cr changes
[arvados.git] / src / services / services.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import Axios from "axios";
6 import { AuthService } from "./auth-service/auth-service";
7 import { GroupsService } from "./groups-service/groups-service";
8 import { ProjectService } from "./project-service/project-service";
9 import { LinkService } from "./link-service/link-service";
10 import { FavoriteService } from "./favorite-service/favorite-service";
11 import { CollectionService } from "./collection-service/collection-service";
12 import { TagService } from "./tag-service/tag-service";
13 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
14 import { KeepService } from "./keep-service/keep-service";
15 import { WebDAV } from "~/common/webdav";
16 import { Config } from "~/common/config";
17 import { UserService } from './user-service/user-service';
18 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
19 import { ResourceKind } from "~/models/resource";
20 import { ContainerRequestService } from './container-request-service/container-request-service';
21 import { ContainerService } from './container-service/container-service';
22 import { LogService } from './log-service/log-service';
23 import { ApiActions } from "~/services/api/api-actions";
24 import { WorkflowService } from "~/services/workflow-service/workflow-service";
25 import { SearchService } from '~/services/search-service/search-service';
26 import { PermissionService } from "~/services/permission-service/permission-service";
27 import { VirtualMachinesService } from "~/services/virtual-machines-service/virtual-machines-service";
28 import { RepositoriesService } from '~/services/repositories-service/repositories-service';
29 import { AuthorizedKeysService } from '~/services/authorized-keys-service/authorized-keys-service';
30 import { VocabularyService } from '~/services/vocabulary-service/vocabulary-service';
31
32 export type ServiceRepository = ReturnType<typeof createServices>;
33
34 export const createServices = (config: Config, actions: ApiActions) => {
35     const apiClient = Axios.create();
36     apiClient.defaults.baseURL = config.baseUrl;
37
38     const webdavClient = new WebDAV();
39     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
40
41     const authorizedKeysService = new AuthorizedKeysService(apiClient, actions);
42     const containerRequestService = new ContainerRequestService(apiClient, actions);
43     const containerService = new ContainerService(apiClient, actions);
44     const groupsService = new GroupsService(apiClient, actions);
45     const keepService = new KeepService(apiClient, actions);
46     const linkService = new LinkService(apiClient, actions);
47     const logService = new LogService(apiClient, actions);
48     const permissionService = new PermissionService(apiClient, actions);
49     const projectService = new ProjectService(apiClient, actions);
50     const repositoriesService = new RepositoriesService(apiClient, actions);
51     const userService = new UserService(apiClient, actions);
52     const virtualMachineService = new VirtualMachinesService(apiClient, actions);
53     const workflowService = new WorkflowService(apiClient, actions);
54
55     const ancestorsService = new AncestorService(groupsService, userService);
56     const authService = new AuthService(apiClient, config.rootUrl, actions);
57     const collectionService = new CollectionService(apiClient, webdavClient, authService, actions);
58     const collectionFilesService = new CollectionFilesService(collectionService);
59     const favoriteService = new FavoriteService(linkService, groupsService);
60     const tagService = new TagService(linkService);
61     const searchService = new SearchService();
62     const vocabularyService = new VocabularyService(config.vocabularyUrl);
63
64     return {
65         ancestorsService,
66         apiClient,
67         authService,
68         authorizedKeysService,
69         collectionFilesService,
70         collectionService,
71         containerRequestService,
72         containerService,
73         favoriteService,
74         groupsService,
75         keepService,
76         linkService,
77         logService,
78         permissionService,
79         projectService,
80         repositoriesService,
81         searchService,
82         tagService,
83         userService,
84         virtualMachineService,
85         webdavClient,
86         workflowService,
87         vocabularyService,
88     };
89 };
90
91 export const getResourceService = (kind?: ResourceKind) => (serviceRepository: ServiceRepository) => {
92     switch (kind) {
93         case ResourceKind.USER:
94             return serviceRepository.userService;
95         case ResourceKind.GROUP:
96             return serviceRepository.groupsService;
97         case ResourceKind.COLLECTION:
98             return serviceRepository.collectionService;
99         default:
100             return undefined;
101     }
102 };