15530: Fedlogin sends unsalted token
[arvados.git] / src / index.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import * as ReactDOM from 'react-dom';
7 import { Provider } from "react-redux";
8 import { MainPanel } from '~/views/main-panel/main-panel';
9 import '~/index.css';
10 import { Route, Switch } from 'react-router';
11 import createBrowserHistory from "history/createBrowserHistory";
12 import { History } from "history";
13 import { configureStore, RootStore } from '~/store/store';
14 import { ConnectedRouter } from "react-router-redux";
15 import { ApiToken } from "~/views-components/api-token/api-token";
16 import { initAuth } from "~/store/auth/auth-action";
17 import { createServices } from "~/services/services";
18 import { MuiThemeProvider } from '@material-ui/core/styles';
19 import { CustomTheme } from '~/common/custom-theme';
20 import { fetchConfig } from '~/common/config';
21 import { addMenuActionSet, ContextMenuKind } from '~/views-components/context-menu/context-menu';
22 import { rootProjectActionSet } from "~/views-components/context-menu/action-sets/root-project-action-set";
23 import { projectActionSet } from "~/views-components/context-menu/action-sets/project-action-set";
24 import { resourceActionSet } from '~/views-components/context-menu/action-sets/resource-action-set';
25 import { favoriteActionSet } from "~/views-components/context-menu/action-sets/favorite-action-set";
26 import { collectionFilesActionSet } from '~/views-components/context-menu/action-sets/collection-files-action-set';
27 import { collectionFilesItemActionSet } from '~/views-components/context-menu/action-sets/collection-files-item-action-set';
28 import { collectionFilesNotSelectedActionSet } from '~/views-components/context-menu/action-sets/collection-files-not-selected-action-set';
29 import { collectionActionSet } from '~/views-components/context-menu/action-sets/collection-action-set';
30 import { collectionResourceActionSet } from '~/views-components/context-menu/action-sets/collection-resource-action-set';
31 import { processActionSet } from '~/views-components/context-menu/action-sets/process-action-set';
32 import { loadWorkbench } from '~/store/workbench/workbench-actions';
33 import { Routes } from '~/routes/routes';
34 import { trashActionSet } from "~/views-components/context-menu/action-sets/trash-action-set";
35 import { ServiceRepository } from '~/services/services';
36 import { initWebSocket } from '~/websocket/websocket';
37 import { Config } from '~/common/config';
38 import { addRouteChangeHandlers } from './routes/route-change-handlers';
39 import { setCurrentTokenDialogApiHost } from '~/store/current-token-dialog/current-token-dialog-actions';
40 import { processResourceActionSet } from '~/views-components/context-menu/action-sets/process-resource-action-set';
41 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
42 import { trashedCollectionActionSet } from '~/views-components/context-menu/action-sets/trashed-collection-action-set';
43 import { setBuildInfo } from '~/store/app-info/app-info-actions';
44 import { getBuildInfo } from '~/common/app-info';
45 import { DragDropContextProvider } from 'react-dnd';
46 import HTML5Backend from 'react-dnd-html5-backend';
47 import { initAdvanceFormProjectsTree } from '~/store/search-bar/search-bar-actions';
48 import { repositoryActionSet } from '~/views-components/context-menu/action-sets/repository-action-set';
49 import { sshKeyActionSet } from '~/views-components/context-menu/action-sets/ssh-key-action-set';
50 import { keepServiceActionSet } from '~/views-components/context-menu/action-sets/keep-service-action-set';
51 import { loadVocabulary } from '~/store/vocabulary/vocabulary-actions';
52 import { virtualMachineActionSet } from '~/views-components/context-menu/action-sets/virtual-machine-action-set';
53 import { userActionSet } from '~/views-components/context-menu/action-sets/user-action-set';
54 import { computeNodeActionSet } from '~/views-components/context-menu/action-sets/compute-node-action-set';
55 import { apiClientAuthorizationActionSet } from '~/views-components/context-menu/action-sets/api-client-authorization-action-set';
56 import { groupActionSet } from '~/views-components/context-menu/action-sets/group-action-set';
57 import { groupMemberActionSet } from '~/views-components/context-menu/action-sets/group-member-action-set';
58 import { linkActionSet } from '~/views-components/context-menu/action-sets/link-action-set';
59 import { loadFileViewersConfig } from '~/store/file-viewers/file-viewers-actions';
60 import { collectionAdminActionSet } from '~/views-components/context-menu/action-sets/collection-admin-action-set';
61 import { processResourceAdminActionSet } from '~/views-components/context-menu/action-sets/process-resource-admin-action-set';
62 import { projectAdminActionSet } from '~/views-components/context-menu/action-sets/project-admin-action-set';
63
64 console.log(`Starting arvados [${getBuildInfo()}]`);
65
66 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
67 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
68 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
69 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
70 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
71 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_NOT_SELECTED, collectionFilesNotSelectedActionSet);
72 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
73 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
74 addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
75 addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
76 addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
77 addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
78 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
79 addMenuActionSet(ContextMenuKind.REPOSITORY, repositoryActionSet);
80 addMenuActionSet(ContextMenuKind.SSH_KEY, sshKeyActionSet);
81 addMenuActionSet(ContextMenuKind.VIRTUAL_MACHINE, virtualMachineActionSet);
82 addMenuActionSet(ContextMenuKind.KEEP_SERVICE, keepServiceActionSet);
83 addMenuActionSet(ContextMenuKind.USER, userActionSet);
84 addMenuActionSet(ContextMenuKind.LINK, linkActionSet);
85 addMenuActionSet(ContextMenuKind.NODE, computeNodeActionSet);
86 addMenuActionSet(ContextMenuKind.API_CLIENT_AUTHORIZATION, apiClientAuthorizationActionSet);
87 addMenuActionSet(ContextMenuKind.GROUPS, groupActionSet);
88 addMenuActionSet(ContextMenuKind.GROUP_MEMBER, groupMemberActionSet);
89 addMenuActionSet(ContextMenuKind.COLLECTION_ADMIN, collectionAdminActionSet);
90 addMenuActionSet(ContextMenuKind.PROCESS_ADMIN, processResourceAdminActionSet);
91 addMenuActionSet(ContextMenuKind.PROJECT_ADMIN, projectAdminActionSet);
92
93 fetchConfig()
94     .then(({ config, apiHost }) => {
95         const history = createBrowserHistory();
96         const services = createServices(config, {
97             progressFn: (id, working) => {
98                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
99             },
100             errorFn: (id, error) => {
101                 // console.error("Backend error:", error);
102                 // store.dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Backend error", kind: SnackbarKind.ERROR }));
103             }
104         });
105         const store = configureStore(history, services);
106
107         store.subscribe(initListener(history, store, services, config));
108         store.dispatch(initAuth(config));
109         store.dispatch(setBuildInfo());
110         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
111         store.dispatch(loadVocabulary);
112         store.dispatch(loadFileViewersConfig);
113
114         const TokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={true} {...props} />;
115         const FedTokenComponent = (props: any) => <ApiToken authService={services.authService} config={config} loadMainApp={false} {...props} />;
116         const MainPanelComponent = (props: any) => <MainPanel {...props} />;
117
118         const App = () =>
119             <MuiThemeProvider theme={CustomTheme}>
120                 <DragDropContextProvider backend={HTML5Backend}>
121                     <Provider store={store}>
122                         <ConnectedRouter history={history}>
123                             <Switch>
124                                 <Route path={Routes.TOKEN} component={TokenComponent} />
125                                 <Route path={Routes.FED_LOGIN} component={FedTokenComponent} />
126                                 <Route path={Routes.ROOT} component={MainPanelComponent} />
127                             </Switch>
128                         </ConnectedRouter>
129                     </Provider>
130                 </DragDropContextProvider>
131             </MuiThemeProvider>;
132
133         ReactDOM.render(
134             <App />,
135             document.getElementById('root') as HTMLElement
136         );
137     });
138
139 const initListener = (history: History, store: RootStore, services: ServiceRepository, config: Config) => {
140     let initialized = false;
141     return async () => {
142         const { router, auth } = store.getState();
143         if (router.location && auth.user && !initialized) {
144             initialized = true;
145             initWebSocket(config, services.authService, store);
146             await store.dispatch(loadWorkbench());
147             addRouteChangeHandlers(history, store);
148             // ToDo: move to searchBar component
149             store.dispatch(initAdvanceFormProjectsTree());
150         }
151     };
152 };
153
154 // force build comment #1