1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import Axios from "axios";
7 export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
9 export interface Config {
14 blobSignatureTtl: number;
15 crunchLimitLogBytesPerJob: number;
16 crunchLogBytesPerEvent: number;
17 crunchLogPartialLineThrottlePeriod: number;
18 crunchLogSecondsBetweenEvents: number;
19 crunchLogThrottleBytes: number;
20 crunchLogThrottleLines: number;
21 crunchLogThrottlePeriod: number;
22 defaultCollectionReplication: number;
23 defaultTrashLifetime: number;
25 discoveryVersion: string;
26 dockerImageFormats: string[];
27 documentationLink: string;
31 keepWebServiceUrl: string;
33 maxRequestSize: number;
35 packageVersion: string;
41 remoteHostsViaDNS: boolean;
47 sourceVersion: string;
48 source_version: string;
54 workbench2Url?: string;
55 vocabularyUrl: string;
56 fileViewersConfigUrl: string;
59 export const fetchConfig = () => {
61 .get<ConfigJSON>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
62 .then(response => response.data)
63 .catch(() => Promise.resolve(getDefaultConfig()))
65 .get<Config>(getDiscoveryURL(config.API_HOST))
67 // TODO: After tests delete `|| '/vocabulary-example.json'`
68 // TODO: After tests delete `|| '/file-viewers-example.json'`
71 vocabularyUrl: config.VOCABULARY_URL || '/vocabulary-example.json',
72 fileViewersConfigUrl: config.FILE_VIEWERS_CONFIG_URL || '/file-viewers-example.json'
74 apiHost: config.API_HOST,
79 export const mockConfig = (config: Partial<Config>): Config => ({
85 crunchLimitLogBytesPerJob: 0,
86 crunchLogBytesPerEvent: 0,
87 crunchLogPartialLineThrottlePeriod: 0,
88 crunchLogSecondsBetweenEvents: 0,
89 crunchLogThrottleBytes: 0,
90 crunchLogThrottleLines: 0,
91 crunchLogThrottlePeriod: 0,
92 defaultCollectionReplication: 0,
93 defaultTrashLifetime: 0,
96 dockerImageFormats: [],
97 documentationLink: '',
101 keepWebServiceUrl: '',
109 remoteHostsViaDNS: false,
123 fileViewersConfigUrl: '',
127 interface ConfigJSON {
129 VOCABULARY_URL: string;
130 FILE_VIEWERS_CONFIG_URL: string;
133 const getDefaultConfig = (): ConfigJSON => ({
134 API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
136 FILE_VIEWERS_CONFIG_URL: "",
139 export const DISCOVERY_URL = 'discovery/v1/apis/arvados/v1/rest';
140 export const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${DISCOVERY_URL}?nocache=${(new Date()).getTime()}`;