17573: Adds Volumes config support.
[arvados-workbench2.git] / src / common / config.ts
index 146ca90acf62de05f7c4a0214f74701eb6c97f0f..8a85ae007529738fd0f763193a337278101b1ffa 100644 (file)
@@ -83,26 +83,40 @@ export interface ClusterConfigJSON {
     };
     Collections: {
         ForwardSlashNameSubstitution: string;
+        ManagedProperties?: {
+            [key: string]: {
+                Function: string,
+                Value: string,
+                Protected?: boolean,
+            }
+        }
+    };
+    Volumes: {
+        [key: string]: {
+            StorageClasses: {
+                [key: string]: boolean;
+            }
+        }
     };
 }
 
 export class Config {
-    baseUrl: string;
-    keepWebServiceUrl: string;
-    keepWebInlineServiceUrl: string;
-    remoteHosts: {
+    baseUrl!: string;
+    keepWebServiceUrl!: string;
+    keepWebInlineServiceUrl!: string;
+    remoteHosts!: {
         [key: string]: string
     };
-    rootUrl: string;
-    uuidPrefix: string;
-    websocketUrl: string;
-    workbenchUrl: string;
-    workbench2Url: string;
-    vocabularyUrl: string;
-    fileViewersConfigUrl: string;
-    loginCluster: string;
-    clusterConfig: ClusterConfigJSON;
-    apiRevision: number;
+    rootUrl!: string;
+    uuidPrefix!: string;
+    websocketUrl!: string;
+    workbenchUrl!: string;
+    workbench2Url!: string;
+    vocabularyUrl!: string;
+    fileViewersConfigUrl!: string;
+    loginCluster!: string;
+    clusterConfig!: ClusterConfigJSON;
+    apiRevision!: number;
 }
 
 export const buildConfig = (clusterConfig: ClusterConfigJSON): Config => {
@@ -123,6 +137,19 @@ export const buildConfig = (clusterConfig: ClusterConfigJSON): Config => {
     return config;
 };
 
+export const getStorageClasses = (config: Config): string[] => {
+    const classes: Set<string> = new Set();
+    const volumes = config.clusterConfig.Volumes;
+    Object.keys(volumes).forEach(v => {
+        Object.keys(volumes[v].StorageClasses).forEach(sc => {
+            if (volumes[v].StorageClasses[sc]) {
+                classes.add(sc);
+            }
+        });
+    });
+    return Array.from(classes);
+};
+
 const getApiRevision = async (apiUrl: string) => {
     try {
         const dd = (await Axios.get<any>(`${apiUrl}/${DISCOVERY_DOC_PATH}`)).data;
@@ -135,7 +162,7 @@ const getApiRevision = async (apiUrl: string) => {
 
 const removeTrailingSlashes = (config: ClusterConfigJSON): ClusterConfigJSON => {
     const svcs: any = {};
-    Object.keys(config.Services).map((s) => {
+    Object.keys(config.Services).forEach((s) => {
         svcs[s] = config.Services[s];
         if (svcs[s].hasOwnProperty('ExternalURL')) {
             svcs[s].ExternalURL = svcs[s].ExternalURL.replace(/\/+$/, '');
@@ -245,6 +272,7 @@ export const mockClusterConfigJSON = (config: Partial<ClusterConfigJSON>): Clust
     Collections: {
         ForwardSlashNameSubstitution: "",
     },
+    Volumes: {},
     ...config
 });