import crypto from 'crypto' ; import ipaddr from 'ipaddr.js' ; import { sum } from 'lodash' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { CoreSetup } from 'src/core/server' ; import { LevelLogger } from '../lib' ; import { ReportingConfigType } from './schema' ; export function createConfig$ ( core , config$ , parentLogger ) { const logger = parentLogger . clone ( [ 'config' ] ) ; return config$ . pipe ( map ( ( config ) => { let encryptionKey = config . encryptionKey ; if ( encryptionKey === undefined ) { logger . warn ( 'Generating a random key for xpack.reporting.encryptionKey. To prevent sessions from being invalidated on ' + 'restart, please set xpack.reporting.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.' ) ; encryptionKey = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ; } const { kibanaServer : reportingServer } = config ; const serverInfo = core . http . getServerInfo ( ) ; let kibanaServerHostname = reportingServer . hostname ? reportingServer . hostname : serverInfo . hostname ; if ( ipaddr . isValid ( kibanaServerHostname ) && ! sum ( ipaddr . parse ( kibanaServerHostname ) . toByteArray ( ) ) ) { logger . warn ( `Found 'server.host: "0.0.0.0"' in Kibana configuration. Reporting is not able to use this as the Kibana server hostname.` + ` To enable PNG/PDF Reporting to work, 'xpack.reporting.kibanaServer.hostname: localhost' is automatically set in the configuration.` + ` You can prevent this message by adding 'xpack.reporting.kibanaServer.hostname: localhost' in kibana.yml.` ) ; kibanaServerHostname = 'localhost' ; } const kibanaServerPort = reportingServer . port ? reportingServer . port : serverInfo . port ; const kibanaServerProtocol = reportingServer . protocol ? reportingServer . protocol : serverInfo . protocol ; return { ... config , encryptionKey , kibanaServer : { hostname : kibanaServerHostname , port : kibanaServerPort , protocol : kibanaServerProtocol , } , } ; } ) ) ; }