import ClusterAccessControlService from '@/services/cluster-acls/ClusterAccessControlService' ; import ClusterAccessControlProvider from '@/services/cluster-acls/providers/ClusterAccessControlProvider' ; import { State } from '@/typings/enums' ; import { IStore } from '@/typings/store' ; import { IClusterAClMap } from '@/typings/typings' ; import { getAllKnownEnvironments , getAllKnownRegions , getEnv , getRegion , } from '@/utils/app-utils' ; import { loadClass } from '@/utils/class-loader-utils' ; import { Application } from 'express' ; import { getConfig } from '../configuration' ; import loggerFactory from '../logger' ; const { CLUSTER_ACCESS_CONTROL_SERVICE_PROVIDER } = getConfig ( ) ; const logger = loggerFactory ( module ) ; async function getClusterAccessControlProvider ( app ) { if ( ! CLUSTER_ACCESS_CONTROL_SERVICE_PROVIDER ) { throw new Error ( 'CLUSTER_ACCESS_CONTROL_SERVICE_PROVIDER not specified in configuration.' ) ; } const EntityAccessControlLoaderClass = await loadClass < new ( environments , regions , currentEnvironment , currentRegion ) => ClusterAccessControlProvider > ( `@/services/cluster-acls/providers/${ CLUSTER_ACCESS_CONTROL_SERVICE_PROVIDER }` ) ; return new EntityAccessControlLoaderClass ( getAllKnownEnvironments ( ) , getAllKnownRegions ( ) , getEnv ( app ) , getRegion ( app ) ) ; } param app export async function setupClusterAccessControlService ( app , store ) { const dataAccessControlService = new ClusterAccessControlService ( ) ; dataAccessControlService . use ( await getClusterAccessControlProvider ( app ) ) ; const { accessControl } = store ; accessControl . status = State . LOADING ; dataAccessControlService . on ( 'loaded' , ( clusterAclMap ) => { accessControl . clusterAclMap = clusterAclMap ; accessControl . status = State . SUCCESS ; } ) ; dataAccessControlService . on ( 'error' , ( err ) => { logger . error ( 'failed fetch cluster access control information' , err . message ) ; accessControl . status = State . ERROR ; } ) ; return dataAccessControlService ; }