import { get } from 'lodash' ; import { first } from 'rxjs/operators' ; import { CoreSetup , PluginInitializerContext } from 'src/core/server' ; import { LevelLogger } from '../lib' ; import { createConfig$ } from './create_config' ; import { ReportingConfigType } from './schema' ; interface Config < BaseType > { get < Key1 extends keyof BaseType > ( key1 ) : BaseType [ Key1 ] ; get < Key1 extends keyof BaseType , Key2 extends keyof BaseType [ Key1 ] > ( key1 , key2 ) : BaseType [ Key1 ] [ Key2 ] ; get < Key1 extends keyof BaseType , Key2 extends keyof BaseType [ Key1 ] , Key3 extends keyof BaseType [ Key1 ] [ Key2 ] > ( key1 , key2 , key3 ) : BaseType [ Key1 ] [ Key2 ] [ Key3 ] ; get < Key1 extends keyof BaseType , Key2 extends keyof BaseType [ Key1 ] , Key3 extends keyof BaseType [ Key1 ] [ Key2 ] , Key4 extends keyof BaseType [ Key1 ] [ Key2 ] [ Key3 ] > ( key1 , key2 , key3 , key4 ) : BaseType [ Key1 ] [ Key2 ] [ Key3 ] [ Key4 ] ; } interface KbnServerConfigType { server : { basePath : string ; host : string ; name : string ; port : number ; protocol : string ; uuid : string ; } ; } internal export interface ReportingConfig extends Config < ReportingConfigType > { kbnConfig : Config < KbnServerConfigType > ; } internal param { PluginInitializerContext < ReportingConfigType > } initContext param { CoreSetup } core param { LevelLogger } logger returns { Promise < ReportingConfig > } export const buildConfig = async ( initContext , core , logger ) : Promise < ReportingConfig > => { const config$ = initContext . config . create < ReportingConfigType > ( ) ; const { http } = core ; const serverInfo = http . getServerInfo ( ) ; const kbnConfig = { server : { basePath : core . http . basePath . serverBasePath , host : serverInfo . hostname , name : serverInfo . name , port : serverInfo . port , uuid : initContext . env . instanceUuid , protocol : serverInfo . protocol , } , } ; const reportingConfig$ = createConfig$ ( core , config$ , logger ) ; const reportingConfig = await reportingConfig$ . pipe ( first ( ) ) . toPromise ( ) ; return { get : ( ... keys ) => get ( reportingConfig , keys . join ( '.' ) , null ) , kbnConfig : { get : ( ... keys ) => get ( kbnConfig , keys . join ( '.' ) , null ) , } , } ; } ;