Merge branch '17585-Redesign-navigation-of-files-in-collections' into main
[arvados-workbench2.git] / src / common / config.ts
index 5d9435953fa819f166dcac4c3f015ff07d42c97a..56f7c4884b19542ee057b937b5ff420809477a9e 100644 (file)
@@ -89,27 +89,35 @@ export interface ClusterConfigJSON {
                 Value: string,
                 Protected?: boolean,
             }
+        },
+        TrustAllContent: 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 => {
@@ -130,6 +138,19 @@ export const buildConfig = (clusterConfig: ClusterConfigJSON): Config => {
     return config;
 };
 
+export const getStorageClasses = (config: Config): string[] => {
+    const classes: Set<string> = new Set(['default']);
+    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;
@@ -142,7 +163,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(/\/+$/, '');
@@ -251,7 +272,9 @@ export const mockClusterConfigJSON = (config: Partial<ClusterConfigJSON>): Clust
     },
     Collections: {
         ForwardSlashNameSubstitution: "",
+        TrustAllContent: false,
     },
+    Volumes: {},
     ...config
 });