import { i18n } from '@kbn/i18n' ; import { CoreSetup , Logger , Plugin , PluginInitializerContext } from 'kibana/server' ; import { LicenseStatus , PLUGIN } from '../common' ; import { AppServerPluginDependencies } from './types' ; import * as profileRoute from './routes/profile' ; export class SearchProfilerServerPlugin implements Plugin { licenseStatus : LicenseStatus ; log : Logger ; constructor ( { logger } ) { this . log = logger . get ( ) ; this . licenseStatus = { valid : false } ; } setup ( { http } , { licensing } ) { const router = http . createRouter ( ) ; profileRoute . register ( { router , getLicenseStatus : ( ) => this . licenseStatus , log : this . log , } ) ; licensing . license$ . subscribe ( ( license ) => { const { state , message } = license . check ( PLUGIN . id , PLUGIN . minimumLicenseType ) ; const hasRequiredLicense = state === 'valid' ; if ( hasRequiredLicense ) { this . licenseStatus = { valid : true } ; } else { this . licenseStatus = { valid : false , message : message || i18n . translate ( 'xpack.searchProfiler.licenseCheckErrorMessage' , { defaultMessage : 'License check failed' , } ) , } ; if ( message ) { this . log . info ( message ) ; } } } ) ; } start ( ) { } stop ( ) { } }