import { getConfig } from '@/config/configuration' ; import { APP_CLUSTER_NAME , APP_ENV , APP_NAME , APP_REGION , } from '@/config/constants' ; import ClusterAclsNotLoadedError from '@/model/errors/ClusterAclsNotLoadedError' ; import DatastoreNotAvailableError from '@/model/errors/DatastoreNotAvailableError' ; import NoClustersAvailableError from '@/model/errors/NoClustersAvailableErrors' ; import { getStore } from '@/model/store' ; import { DatastoreType } from '@/typings/enums' ; import { IClusterDefinition } from '@/typings/typings' ; import { Application } from 'express' ; const { ENVIRONMENTS , REGIONS } = getConfig ( ) ; param app returns export function getAppName ( app ) { return app . get ( APP_NAME ) ; } param datastoreType returns export function getAvailableClusters ( datastoreType ) { const { discovery } = getStore ( ) ; const { clusters } = discovery ; if ( ! clusters || Object . keys ( clusters ) . length === 0 ) { throw new NoClustersAvailableError ( datastoreType ) ; } const datastoreClusters = clusters [ datastoreType ] ; if ( ! datastoreClusters ) { throw new DatastoreNotAvailableError ( datastoreType ) ; } return datastoreClusters ; } export function getCluster ( app , datastoreType , clusterName ) { const clusters = getAvailableClusters ( datastoreType ) ; const localEnv = getEnv ( app ) ; const localRegion = getRegion ( app ) ; return clusters . find ( ( cluster ) => cluster . name . toLowerCase ( ) === clusterName . toLowerCase ( ) && cluster . env === localEnv && cluster . region === localRegion ) as IClusterDefinition ; } param app returns export function getEnv ( app ) { return app . get ( APP_ENV ) ; } param app returns export function getAppStack ( app ) { return app . get ( APP_CLUSTER_NAME ) ; } param app returns export function getRegion ( app ) { return app . get ( APP_REGION ) ; } returns see getAvailableRegions export function getAllKnownRegions ( ) { return REGIONS ; } /**
 * Fetches all the known environments. These are the well-known environments which is likely
 * a superset of all available environments.
 */ export function getAllKnownEnvironments ( ) { return ENVIRONMENTS ; } export function isClusterShared ( clusterName ) { const { accessControl } = getStore ( ) ; const clusterAclMap = accessControl . clusterAclMap ; if ( ! clusterAclMap ) { throw new ClusterAclsNotLoadedError ( clusterName ) ; } const clusterACLDef = clusterAclMap [ clusterName . toLowerCase ( ) ] ; if ( ! clusterACLDef ) { return false ; } return clusterACLDef . isShared ; } param app param region param env returns export function isRegionAccessible ( app , region , env ) { return region === getRegion ( app ) && env === getEnv ( app ) ; }