15064: Fetch discovery documents for all remotes
[arvados-workbench2.git] / src / store / auth / auth-action.ts
index baf80595f300ad9fb7d181aa8ba5441303e71aab..09d922e05282ba0809272bca22a238d77e39c29f 100644 (file)
@@ -10,8 +10,9 @@ import { ServiceRepository } from "~/services/services";
 import { SshKeyResource } from '~/models/ssh-key';
 import { User } from "~/models/user";
 import { Session } from "~/models/session";
-import { Config } from '~/common/config';
+import { getDiscoveryURL, Config } from '~/common/config';
 import { initSessions } from "~/store/auth/auth-action-session";
+import Axios from "axios";
 
 export const authActions = unionize({
     SAVE_API_TOKEN: ofType<string>(),
@@ -28,7 +29,8 @@ export const authActions = unionize({
     SET_SESSIONS: ofType<Session[]>(),
     ADD_SESSION: ofType<Session>(),
     REMOVE_SESSION: ofType<string>(),
-    UPDATE_SESSION: ofType<Session>()
+    UPDATE_SESSION: ofType<Session>(),
+    REMOTE_CLUSTER_CONFIG: ofType<{ config: Config }>(),
 });
 
 function setAuthorizationHeader(services: ServiceRepository, token: string) {
@@ -57,6 +59,10 @@ export const initAuth = (config: Config) => (dispatch: Dispatch, getState: () =>
         dispatch<any>(getUserDetails()).then((user: User) => {
             dispatch(authActions.INIT({ user, token }));
         });
+        Object.keys(config.remoteHosts).map((k) => {
+            Axios.get<Config>(getDiscoveryURL(config.remoteHosts[k]))
+                .then(response => dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config: response.data })));
+        });
     }
 };