import { take } from 'rxjs/operators' ; import { DeprecationsFactory } from './deprecations_factory' ; import { DomainDeprecationDetails , RegisterDeprecationsConfig } from './types' ; import { registerRoutes } from './routes' ; import { config as deprecationConfig , DeprecationConfigType } from './deprecation_config' ; import { CoreContext } from '../core_context' ; import { IConfigService } from '../config' ; import { CoreService } from '../../types' ; import { InternalHttpServiceSetup } from '../http' ; import { Logger } from '../logging' ; import { IScopedClusterClient } from '../elasticsearch/client' ; import { SavedObjectsClientContract } from '../saved_objects/types' ; example public export interface DeprecationsServiceSetup { registerDeprecations : ( deprecationContext : RegisterDeprecationsConfig ) => void ; } public export interface DeprecationsClient { getAllDeprecations : ( ) => Promise < DomainDeprecationDetails [ ] > ; } export interface InternalDeprecationsServiceStart { /**
     * Creates a  DeprecationsClient with provided SO client and ES client.
     *
      asScopedToClient ( esClient , savedObjectsClient ) : DeprecationsClient ; } internal export interface InternalDeprecationsServiceSetup { getRegistry : ( domainId : string ) => DeprecationsServiceSetup ; } internal export interface DeprecationsSetupDeps { http : InternalHttpServiceSetup ; } internal export class DeprecationsService implements CoreService < InternalDeprecationsServiceSetup , InternalDeprecationsServiceStart > { private readonly logger : Logger ; private readonly configService : IConfigService ; private deprecationsFactory ? : DeprecationsFactory ; constructor ( coreContext ) { this . logger = coreContext . logger . get ( 'deprecations-service' ) ; this . configService = coreContext . configService ; } public async setup ( { http } ) { this . logger . debug ( 'Setting up Deprecations service' ) ; const config = await this . configService . atPath < DeprecationConfigType > ( deprecationConfig . path ) . pipe ( take ( 1 ) ) . toPromise ( ) ; this . deprecationsFactory = new DeprecationsFactory ( { logger : this . logger , config : { ignoredConfigDeprecations : config . skip_deprecated_settings , } , } ) ; registerRoutes ( { http } ) ; this . registerConfigDeprecationsInfo ( this . deprecationsFactory ) ; const deprecationsFactory = this . deprecationsFactory ; return { getRegistry : ( domainId ) : DeprecationsServiceSetup => { const registry = deprecationsFactory . getRegistry ( domainId ) ; return { registerDeprecations : registry . registerDeprecations , } ; } , } ; } public start ( ) { if ( ! this . deprecationsFactory ) { throw new Error ( '`setup` must be called before `start`' ) ; } return { asScopedToClient : this . createScopedDeprecations ( ) , } ; } public stop ( ) { } private createScopedDeprecations ( ) { return ( esClient , savedObjectsClient ) => { return { getAllDeprecations : this . deprecationsFactory ! . getAllDeprecations . bind ( null , { savedObjectsClient , esClient , } ) , } ; } ; } private registerConfigDeprecationsInfo ( deprecationsFactory ) { const handledDeprecatedConfigs = this . configService . getHandledDeprecatedConfigs ( ) ; for ( const [ domainId , deprecationsContexts ] of handledDeprecatedConfigs ) { const deprecationsRegistry = deprecationsFactory . getRegistry ( domainId ) ; deprecationsRegistry . registerDeprecations ( { getDeprecations : ( ) => { return deprecationsContexts . map ( ( { configPath , title = `${ domainId } has a deprecated setting` , level = 'critical' , message , correctiveActions , documentationUrl , } ) => ( { configPath , title , level , message , correctiveActions , documentationUrl , deprecationType : 'config' , requireRestart : true , } ) ) ; } , } ) ; } } }