X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f7cf9da472181411b7faaebd02008f012b247a94..85c93508dc959ca5491998283565a8e125a56a86:/src/common/config.ts diff --git a/src/common/config.ts b/src/common/config.ts index 775b1145..c74277e4 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -2,29 +2,125 @@ // // SPDX-License-Identifier: AGPL-3.0 -import Axios from "../../node_modules/axios"; +import Axios from "axios"; export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json"; export interface Config { - API_HOST: string; + auth: {}; + basePath: string; + baseUrl: string; + batchPath: string; + blobSignatureTtl: number; + crunchLimitLogBytesPerJob: number; + crunchLogBytesPerEvent: number; + crunchLogPartialLineThrottlePeriod: number; + crunchLogSecondsBetweenEvents: number; + crunchLogThrottleBytes: number; + crunchLogThrottleLines: number; + crunchLogThrottlePeriod: number; + defaultCollectionReplication: number; + defaultTrashLifetime: number; + description: string; + discoveryVersion: string; + dockerImageFormats: string[]; + documentationLink: string; + generatedAt: string; + gitUrl: string; + id: string; + keepWebServiceUrl: string; + kind: string; + maxRequestSize: number; + name: string; + packageVersion: string; + parameters: {}; + protocol: string; + remoteHosts: string; + remoteHostsViaDNS: boolean; + resources: {}; + revision: string; + rootUrl: string; + schemas: {}; + servicePath: string; + sourceVersion: string; + source_version: string; + title: string; + uuidPrefix: string; + version: string; + websocketUrl: string; + workbenchUrl: string; + vocabularyUrl: string; } export const fetchConfig = () => { return Axios - .get(CONFIG_URL + "?nocache=" + (new Date()).getTime()) + .get(CONFIG_URL + "?nocache=" + (new Date()).getTime()) .then(response => response.data) .catch(() => Promise.resolve(getDefaultConfig())) - .then(mapConfig); + .then(config => Axios + .get(getDiscoveryURL(config.API_HOST)) + .then(response => ({ + config: {...response.data, vocabularyUrl: config.VOCABULARY_URL }, + apiHost: config.API_HOST, + }))); + }; -const mapConfig = (config: Config): Config => ({ - ...config, - API_HOST: addProtocol(config.API_HOST) +export const mockConfig = (config: Partial): Config => ({ + auth: {}, + basePath: '', + baseUrl: '', + batchPath: '', + blobSignatureTtl: 0, + crunchLimitLogBytesPerJob: 0, + crunchLogBytesPerEvent: 0, + crunchLogPartialLineThrottlePeriod: 0, + crunchLogSecondsBetweenEvents: 0, + crunchLogThrottleBytes: 0, + crunchLogThrottleLines: 0, + crunchLogThrottlePeriod: 0, + defaultCollectionReplication: 0, + defaultTrashLifetime: 0, + description: '', + discoveryVersion: '', + dockerImageFormats: [], + documentationLink: '', + generatedAt: '', + gitUrl: '', + id: '', + keepWebServiceUrl: '', + kind: '', + maxRequestSize: 0, + name: '', + packageVersion: '', + parameters: {}, + protocol: '', + remoteHosts: '', + remoteHostsViaDNS: false, + resources: {}, + revision: '', + rootUrl: '', + schemas: {}, + servicePath: '', + sourceVersion: '', + source_version: '', + title: '', + uuidPrefix: '', + version: '', + websocketUrl: '', + workbenchUrl: '', + vocabularyUrl: '', + ...config }); -const getDefaultConfig = (): Config => ({ - API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "" +interface ConfigJSON { + API_HOST: string; + VOCABULARY_URL: string; +} + +const getDefaultConfig = (): ConfigJSON => ({ + API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "", + VOCABULARY_URL: "", }); -const addProtocol = (url: string) => `${window.location.protocol}//${url}`; +const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/discovery/v1/apis/arvados/v1/rest`;