From ef9bc478cba32eb8722c17d7911cb201941f2adc Mon Sep 17 00:00:00 2001 From: Matt Apperson Date: Wed, 27 Nov 2019 18:43:58 -0500 Subject: [PATCH] [Ingest] Adds support for a working default output (#51841) * aadding config * add working settings to the default output * remove default username and password * update libs --- x-pack/legacy/plugins/ingest/index.ts | 1 + .../libs/adapters/policy/adapter_types.ts | 2 ++ .../ingest/server/libs/compose/kibana.ts | 12 ++++++------ .../ingest/server/libs/compose/memorized.ts | 18 +++++++++--------- .../plugins/ingest/server/libs/framework.ts | 10 ++++++---- .../plugins/ingest/server/libs/outputs.ts | 14 ++++++++++++-- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/x-pack/legacy/plugins/ingest/index.ts b/x-pack/legacy/plugins/ingest/index.ts index a36c86f958280..d120c1ec03a3c 100644 --- a/x-pack/legacy/plugins/ingest/index.ts +++ b/x-pack/legacy/plugins/ingest/index.ts @@ -14,6 +14,7 @@ import { mappings } from './server/mappings'; export const config = Joi.object({ enabled: Joi.boolean().default(true), + defaultOutputHost: Joi.string().default('http://localhost:9200'), }).default(); export function ingest(kibana: any) { diff --git a/x-pack/legacy/plugins/ingest/server/libs/adapters/policy/adapter_types.ts b/x-pack/legacy/plugins/ingest/server/libs/adapters/policy/adapter_types.ts index cdb69e2a015e0..ee12f6a79db42 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/adapters/policy/adapter_types.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/adapters/policy/adapter_types.ts @@ -132,6 +132,8 @@ export enum InputType { */ export interface Output { api_token?: string; + username?: string; + password?: string; /** * contains everything not otherwise specified (e.g. TLS, etc) */ diff --git a/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts b/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts index d5fc9e715e1a5..b430d6594a7df 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/compose/kibana.ts @@ -9,15 +9,15 @@ import { PLUGIN } from '../../../common/constants'; import { CONFIG_PREFIX } from '../../../common/constants/plugin'; import { DatabaseKbnESPlugin } from '../adapters/es_database/adapter_types'; import { ESDatabaseAdapter } from '../adapters/es_database/default'; +import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; import { BackendFrameworkAdapter } from '../adapters/framework/default'; -import { ServerLibs } from '../types'; -import { BackendFrameworkLib } from './../framework'; -import { PolicyLib } from '../policy'; import { PolicyAdapter } from '../adapters/policy/default'; import { SODatabaseAdapter } from '../adapters/so_database/default'; -import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; -import { OutputsLib } from '../outputs'; import { DatasourcesLib } from '../datasources'; +import { OutputsLib } from '../outputs'; +import { PolicyLib } from '../policy'; +import { ServerLibs } from '../types'; +import { BackendFrameworkLib } from './../framework'; export function compose(server: KibanaLegacyServer): ServerLibs { const framework = new BackendFrameworkLib( @@ -26,7 +26,7 @@ export function compose(server: KibanaLegacyServer): ServerLibs { const database = new ESDatabaseAdapter(server.plugins.elasticsearch as DatabaseKbnESPlugin); const soDatabase = new SODatabaseAdapter(server.savedObjects, server.plugins.elasticsearch); - const outputs = new OutputsLib(); + const outputs = new OutputsLib({ framework }); const datasources = new DatasourcesLib(); diff --git a/x-pack/legacy/plugins/ingest/server/libs/compose/memorized.ts b/x-pack/legacy/plugins/ingest/server/libs/compose/memorized.ts index 3a003ccecf4bb..042f4dab323e0 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/compose/memorized.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/compose/memorized.ts @@ -4,22 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ -import { camelCase } from 'lodash'; import { callWhenOnline } from '@mattapperson/slapshot/lib/call_when_online'; +import { camelCase } from 'lodash'; import { PLUGIN } from '../../../common/constants'; import { CONFIG_PREFIX } from '../../../common/constants/plugin'; import { ESDatabaseAdapter } from '../adapters/es_database/default'; +import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; import { BackendFrameworkAdapter } from '../adapters/framework/default'; -import { ServerLibs } from '../types'; -import { BackendFrameworkLib } from './../framework'; -import { PolicyLib } from '../policy'; +import { MemorizedBackendFrameworkAdapter } from '../adapters/framework/memorized'; import { PolicyAdapter } from '../adapters/policy/default'; -import { SODatabaseAdapter } from '../adapters/so_database/default'; -import { KibanaLegacyServer } from '../adapters/framework/adapter_types'; import { MemorizedPolicyAdapter } from '../adapters/policy/memorized'; -import { MemorizedBackendFrameworkAdapter } from '../adapters/framework/memorized'; -import { OutputsLib } from '../outputs'; +import { SODatabaseAdapter } from '../adapters/so_database/default'; import { DatasourcesLib } from '../datasources'; +import { OutputsLib } from '../outputs'; +import { PolicyLib } from '../policy'; +import { ServerLibs } from '../types'; +import { BackendFrameworkLib } from './../framework'; export function compose(servers?: { shutdown: () => Promise; @@ -52,7 +52,7 @@ export function compose(servers?: { ) as BackendFrameworkAdapter; const framework = new BackendFrameworkLib(memorizedFrameworkAdapter); - const outputs = new OutputsLib(); + const outputs = new OutputsLib({ framework }); const datasources = new DatasourcesLib(); diff --git a/x-pack/legacy/plugins/ingest/server/libs/framework.ts b/x-pack/legacy/plugins/ingest/server/libs/framework.ts index 15bd491ad5f81..8445b21bab8df 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/framework.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/framework.ts @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Request } from 'src/legacy/server/kbn_server'; import { get } from 'lodash'; -import { BackendFrameworkAdapter } from './adapters/framework/default'; +import { Request } from 'src/legacy/server/kbn_server'; import { LicenseType } from '../../common/types/security'; +import { BackendFrameworkAdapter } from './adapters/framework/default'; export class BackendFrameworkLib { /** @@ -37,9 +37,11 @@ export class BackendFrameworkLib { public getCurrentUser(request: Request) { return this.adapter.getUser(request); } + + public getSetting(setting: 'defaultOutputHost'): string; public getSetting(setting: 'defaultUserRoles'): string[]; - public getSetting(setting: 'defaultUserRoles') { - return this.adapter.getSetting(`xpack.ingest-do-not-disable.${setting}`); + public getSetting(setting: string): string | string[] { + return this.adapter.getSetting(`xpack.ingest.${setting}`) as any; } public expose(name: string, thing: any) { return this.adapter.expose(name, thing); diff --git a/x-pack/legacy/plugins/ingest/server/libs/outputs.ts b/x-pack/legacy/plugins/ingest/server/libs/outputs.ts index e67402dc4bf55..60cf81c622ac4 100644 --- a/x-pack/legacy/plugins/ingest/server/libs/outputs.ts +++ b/x-pack/legacy/plugins/ingest/server/libs/outputs.ts @@ -5,15 +5,25 @@ */ import { FrameworkUser } from './adapters/framework/adapter_types'; import { Output, OutputType } from './adapters/policy/adapter_types'; +import { BackendFrameworkLib } from './framework'; export class OutputsLib { - public async getByIDs(_user: FrameworkUser, _ids: string[]): Promise { + constructor( + private readonly libs: { + framework: BackendFrameworkLib; + } + ) {} + public async getByIDs(_user: FrameworkUser, ids: string[]): Promise { + if (ids.length > 0 || ids[0] !== 'default') { + throw new Error('Currently, only a default output is supported'); + } + return [ { id: 'default', name: 'default', type: OutputType.Elasticsearch, - url: '', + url: this.libs.framework.getSetting('defaultOutputHost'), ingest_pipeline: 'default', }, ];