import { get } from 'lodash' ; import { RequestHandler } from 'src/core/server' ; import { deserializeCluster } from '../../../common/lib' ; import { API_BASE_PATH } from '../../../common/constants' ; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory' ; import { RouteDependencies } from '../../types' ; export const register = ( deps ) : void => { const { router , lib : { handleEsError } , } = deps ; const allHandler = async ( ctx , request , response ) => { try { const { client : clusterClient } = ctx . core . elasticsearch ; const { body : clusterSettings } = await clusterClient . asCurrentUser . cluster . getSettings ( ) ; const transientClusterNames = Object . keys ( get ( clusterSettings , 'transient.cluster.remote' ) || { } ) ; const persistentClusterNames = Object . keys ( get ( clusterSettings , 'persistent.cluster.remote' ) || { } ) ; const { body : clustersByName } = await clusterClient . asCurrentUser . cluster . remoteInfo ( ) ; const clusterNames = ( clustersByName && Object . keys ( clustersByName ) ) || [ ] ; const body = clusterNames . map ( ( clusterName ) : any => { const cluster = clustersByName [ clusterName ] ; const isTransient = transientClusterNames . includes ( clusterName ) ; const isPersistent = persistentClusterNames . includes ( clusterName ) ; const { config } = deps ; const isConfiguredByNode = ! isTransient && ! isPersistent ; const deprecatedProxyAddress = isPersistent ? get ( clusterSettings , `persistent.cluster.remote[${ clusterName }].proxy` , undefined ) : undefined ; return { ... deserializeCluster ( clusterName , cluster , deprecatedProxyAddress , config . isCloudEnabled ) , isConfiguredByNode , } ; } ) ; return response . ok ( { body } ) ; } catch ( error ) { return handleEsError ( { error , response } ) ; } } ; router . get ( { path : API_BASE_PATH , validate : false , } , licensePreRoutingFactory ( deps , allHandler ) ) ; } ;