1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import Axios from "axios";
7 export const WORKBENCH_CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
9 interface WorkbenchConfig {
11 VOCABULARY_URL: string;
12 FILE_VIEWERS_CONFIG_URL: string;
15 export interface ClusterConfigJSON {
19 ActivateUsers: boolean
44 ArvadosDocsite: string;
45 VocabularyURL: string;
46 FileViewersConfigURL: string;
52 keepWebServiceUrl: string;
60 workbench2Url: string;
61 vocabularyUrl: string;
62 fileViewersConfigUrl: string;
65 export const fetchConfig = () => {
67 .get<WorkbenchConfig>(WORKBENCH_CONFIG_URL + "?nocache=" + (new Date()).getTime())
68 .then(response => response.data)
69 .catch(() => Promise.resolve(getDefaultConfig()))
70 .then(workbenchConfig => Axios
71 .get<ClusterConfigJSON>(getClusterConfigURL(workbenchConfig.API_HOST))
74 const config = new Config();
75 const clusterConfigJSON = response.data;
76 const docsite = clusterConfigJSON.Workbench.ArvadosDocsite;
77 const warnDeprecation = (varName: string) => console.warn(
78 `A value for ${varName} was found in ${WORKBENCH_CONFIG_URL}. This configuration is deprecated. \
79 Please use the centralized configuration instead. See more at ${docsite}admin/config-migration.html`);
81 // Check if the workbench config has an entry for vocabulary and file viewer URLs
82 // If so, use these values (even if it is an empty string), but print a console warning.
83 // Otherwise, use the cluster config or default values.
84 let fileViewerConfigUrl;
85 if (workbenchConfig.FILE_VIEWERS_CONFIG_URL !== undefined) {
86 warnDeprecation("FILE_VIEWERS_CONFIG_URL");
87 fileViewerConfigUrl = workbenchConfig.FILE_VIEWERS_CONFIG_URL;
90 fileViewerConfigUrl = clusterConfigJSON.Workbench.FileViewersConfigURL || "/file-viewers-example.json";
92 config.fileViewersConfigUrl = fileViewerConfigUrl;
95 if (workbenchConfig.VOCABULARY_URL !== undefined) {
96 warnDeprecation("VOCABULARY_URL");
97 vocabularyUrl = workbenchConfig.VOCABULARY_URL;
100 vocabularyUrl = clusterConfigJSON.Workbench.VocabularyURL || "/vocabulary-example.json";
102 config.vocabularyUrl = vocabularyUrl;
104 config.rootUrl = clusterConfigJSON.Services.Controller.ExternalURL;
105 config.baseUrl = `${config.rootUrl}/${ARVADOS_API_PATH}`;
106 config.uuidPrefix = clusterConfigJSON.ClusterID;
107 config.websocketUrl = clusterConfigJSON.Services.Websocket.ExternalURL;
108 config.workbench2Url = clusterConfigJSON.Services.Workbench2.ExternalURL;
109 config.workbenchUrl = clusterConfigJSON.Services.Workbench1.ExternalURL;
110 config.keepWebServiceUrl = clusterConfigJSON.Services.WebDAV.ExternalURL;
111 mapRemoteHosts(clusterConfigJSON, config);
115 return { config, apiHost: workbenchConfig.API_HOST };
120 // Maps remote cluster hosts and removes the default RemoteCluster entry
121 export const mapRemoteHosts = (clusterConfigJSON: ClusterConfigJSON, config: Config) => {
122 config.remoteHosts = {};
123 Object.keys(clusterConfigJSON.RemoteClusters).forEach (k => { config.remoteHosts[k] = clusterConfigJSON.RemoteClusters[k].Host; });
124 delete config.remoteHosts["*"];
127 export const mockConfig = (config: Partial<Config>): Config => ({
129 keepWebServiceUrl: "",
137 fileViewersConfigUrl: ""
140 const getDefaultConfig = (): WorkbenchConfig => ({
141 API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
143 FILE_VIEWERS_CONFIG_URL: "",
146 export const ARVADOS_API_PATH = "arvados/v1";
147 export const CLUSTER_CONFIG_URL = "arvados/v1/config";
148 export const getClusterConfigURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${CLUSTER_CONFIG_URL}?nocache=${(new Date()).getTime()}`;