Obtain configuration from discovery endpoint
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 20 Aug 2018 07:47:41 +0000 (09:47 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 20 Aug 2018 07:47:41 +0000 (09:47 +0200)
Feature #14078

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

.env
src/common/config.ts
src/services/services.ts
src/store/auth/auth-actions.test.ts
src/store/auth/auth-reducer.test.ts

diff --git a/.env b/.env
index df56fb28a76b3fbd7d61e647a59af98a3b2e7308..ed397c5cc0952badd931be8ccfdd7ec60d95a6d1 100644 (file)
--- a/.env
+++ b/.env
@@ -4,5 +4,4 @@
 
 REACT_APP_ARVADOS_CONFIG_URL=/config.json
 REACT_APP_ARVADOS_API_HOST=qr1hi.arvadosapi.com
 
 REACT_APP_ARVADOS_CONFIG_URL=/config.json
 REACT_APP_ARVADOS_API_HOST=qr1hi.arvadosapi.com
-REACT_APP_ARVADOS_KEEP_WEB_HOST=collections.qr1hi.arvadosapi.com
 HTTPS=true
\ No newline at end of file
 HTTPS=true
\ No newline at end of file
index 759a20158f9f8cafac459cd4ee2213f36c00890d..061f9c00af0b91e5b1a92e5337ecda44492c2754 100644 (file)
@@ -7,8 +7,48 @@ import Axios from "axios";
 export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
 
 export interface Config {
 export const CONFIG_URL = process.env.REACT_APP_ARVADOS_CONFIG_URL || "/config.json";
 
 export interface Config {
-    apiHost: string;
-    keepWebHost: 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;
 }
 
 export const fetchConfig = () => {
 }
 
 export const fetchConfig = () => {
@@ -16,22 +56,62 @@ export const fetchConfig = () => {
         .get<ConfigJSON>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
         .then(response => response.data)
         .catch(() => Promise.resolve(getDefaultConfig()))
         .get<ConfigJSON>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
         .then(response => response.data)
         .catch(() => Promise.resolve(getDefaultConfig()))
-        .then(mapConfig);
+        .then(config => Axios.get<Config>(getDiscoveryURL(config.API_HOST)))
+        .then(response => response.data);
 };
 
 };
 
+export const mockConfig = (config: Partial<Config>): 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: '',
+    ...config
+});
+
 interface ConfigJSON {
     API_HOST: string;
 interface ConfigJSON {
     API_HOST: string;
-    KEEP_WEB_HOST: string;
 }
 
 }
 
-const mapConfig = (config: ConfigJSON): Config => ({
-    apiHost: addProtocol(config.API_HOST),
-    keepWebHost: addProtocol(config.KEEP_WEB_HOST)
-});
-
 const getDefaultConfig = (): ConfigJSON => ({
     API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
 const getDefaultConfig = (): ConfigJSON => ({
     API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || "",
-    KEEP_WEB_HOST: process.env.REACT_APP_ARVADOS_KEEP_WEB_HOST || ""
 });
 
 });
 
-const addProtocol = (url: string) => `${window.location.protocol}//${url}`;
+const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/discovery/v1/apis/arvados/v1/rest`;
index 61dd399206384c159d0ffe6982e704fe054a405a..8ddc3f477403be59e73d981bdcbac9f8a2fab499 100644 (file)
@@ -19,12 +19,12 @@ export type ServiceRepository = ReturnType<typeof createServices>;
 
 export const createServices = (config: Config) => {
     const apiClient = Axios.create();
 
 export const createServices = (config: Config) => {
     const apiClient = Axios.create();
-    apiClient.defaults.baseURL = `${config.apiHost}/arvados/v1`;
+    apiClient.defaults.baseURL = config.baseUrl;
 
     const webdavClient = new WebDAV();
 
     const webdavClient = new WebDAV();
-    webdavClient.defaults.baseURL = config.keepWebHost;
+    webdavClient.defaults.baseURL = config.keepWebServiceUrl;
 
 
-    const authService = new AuthService(apiClient, config.apiHost);
+    const authService = new AuthService(apiClient, config.rootUrl);
     const keepService = new KeepService(apiClient);
     const groupsService = new GroupsService(apiClient);
     const projectService = new ProjectService(apiClient);
     const keepService = new KeepService(apiClient);
     const groupsService = new GroupsService(apiClient);
     const projectService = new ProjectService(apiClient);
index 217a27cc49cfccd5d465a25480670ac327029e3e..4ac48a0be2afa021ab220f553847eccde259871d 100644 (file)
@@ -17,15 +17,16 @@ import 'jest-localstorage-mock';
 import { createServices } from "~/services/services";
 import { configureStore, RootStore } from "../store";
 import createBrowserHistory from "history/createBrowserHistory";
 import { createServices } from "~/services/services";
 import { configureStore, RootStore } from "../store";
 import createBrowserHistory from "history/createBrowserHistory";
+import { mockConfig } from '~/common/config';
 
 describe('auth-actions', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
     let store: RootStore;
 
     beforeEach(() => {
 
 describe('auth-actions', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
     let store: RootStore;
 
     beforeEach(() => {
-        store = configureStore(createBrowserHistory(), createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
+        store = configureStore(createBrowserHistory(), createServices(mockConfig({})));
         localStorage.clear();
         localStorage.clear();
-        reducer = authReducer(createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
+        reducer = authReducer(createServices(mockConfig({})));
     });
 
     it('should initialise state with user and api token from local storage', () => {
     });
 
     it('should initialise state with user and api token from local storage', () => {
@@ -72,3 +73,5 @@ describe('auth-actions', () => {
     });
     */
 });
     });
     */
 });
+
+
index 8eeb7c3c636152c9087b868cd01ca71b1678c9df..2b1920a61db9fc47e32fb543341a2010ccd59d63 100644 (file)
@@ -7,13 +7,14 @@ import { AuthAction, authActions } from "./auth-action";
 
 import 'jest-localstorage-mock';
 import { createServices } from "~/services/services";
 
 import 'jest-localstorage-mock';
 import { createServices } from "~/services/services";
+import { mockConfig } from '~/common/config';
 
 describe('auth-reducer', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
 
     beforeAll(() => {
         localStorage.clear();
 
 describe('auth-reducer', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
 
     beforeAll(() => {
         localStorage.clear();
-        reducer = authReducer(createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
+        reducer = authReducer(createServices(mockConfig({})));
     });
 
     it('should correctly initialise state', () => {
     });
 
     it('should correctly initialise state', () => {