import { getConfig } from '@/config/configuration' ; import loggerFactory from '@/config/logger' ; import { getStore } from '@/model/store' ; import ClusterAccessControlService from '@/services/cluster-acls/ClusterAccessControlService' ; import { DiscoveryService } from '@/services/discovery' ; import EntityAccessControlCache from '@/services/entity-acls/EntityAccessControlCache' ; import EntityAccessControlService from '@/services/entity-acls/EntityAccessControlService' ; import ExplorerCache from '@/services/explorer/ExplorerCache' ; import UserGroupCache from '@/services/user/UserGroupCache' ; import { Application } from 'express' ; import { setupClusterAccessControlService } from './cluster-acl' ; import { setupDatastoreSupport } from './datastores' ; import { setupDiscoveryService } from './discovery' ; import { setupEntityAccessControlCache , setupEntityAccessControlService , } from './entity-acls' ; import { setupExplorerCache } from './explorer' ; import { setupUserGroupCache } from './user' ; const logger = loggerFactory ( module ) ; const { SUPPORTED_DATASTORE_TYPES } = getConfig ( ) ; let entityAccessControlCache ; let explorerCache ; let discoveryService ; let clusterAccessControlService ; let userGroupCache ; let entityAccessControlService ; export async function setupServices ( app ) { const store = getStore ( ) ; try { const datastoreServices = await setupDatastoreSupport ( SUPPORTED_DATASTORE_TYPES ) ; entityAccessControlCache = await setupEntityAccessControlCache ( app ) ; explorerCache = await setupExplorerCache ( ) ; userGroupCache = await setupUserGroupCache ( ) ; clusterAccessControlService = await setupClusterAccessControlService ( app , store ) ; discoveryService = await setupDiscoveryService ( explorerCache , datastoreServices , store ) ; entityAccessControlService = await setupEntityAccessControlService ( ) ; await Promise . all ( [ discoveryService . start ( ) , clusterAccessControlService . start ( ) , ] ) ; } catch ( err ) { logger . error ( 'failed to setup services' ) ; throw err ; } } export function getEntityAccessControlService ( ) { return entityAccessControlService ; } export function getEntityAccessControlCache ( ) { return entityAccessControlCache ; } export function getUserGroupCache ( ) { return userGroupCache ; } export function getExplorerCache ( ) { return explorerCache ; } export function getClusterAccessControlService ( ) { return clusterAccessControlService ; }