From 0eb2f2c5a695173535d135b5667ff7f4a34ca215 Mon Sep 17 00:00:00 2001 From: restrry Date: Wed, 10 Jul 2019 11:01:01 +0200 Subject: [PATCH] expose ES createClient to plugins --- .../kibana-plugin-server.coresetup.elasticsearch.md | 1 + .../core/server/kibana-plugin-server.coresetup.md | 2 +- .../server/elasticsearch/elasticsearch_service.mock.ts | 2 +- src/core/server/index.ts | 10 +++++++++- src/core/server/plugins/plugin_context.ts | 1 + src/core/server/server.api.md | 1 + 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.elasticsearch.md b/docs/development/core/server/kibana-plugin-server.coresetup.elasticsearch.md index d837b614e58a0..cd99eabe1e1e5 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.elasticsearch.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.elasticsearch.md @@ -10,5 +10,6 @@ elasticsearch: { adminClient$: Observable; dataClient$: Observable; + createClient: (type: string, clientConfig?: Partial) => ClusterClient; }; ``` diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.md b/docs/development/core/server/kibana-plugin-server.coresetup.md index c85fcfac6f8ef..bc13bad563acb 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.md @@ -16,6 +16,6 @@ export interface CoreSetup | Property | Type | Description | | --- | --- | --- | -| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | {
adminClient$: Observable<ClusterClient>;
dataClient$: Observable<ClusterClient>;
} | | +| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | {
adminClient$: Observable<ClusterClient>;
dataClient$: Observable<ClusterClient>;
createClient: (type: string, clientConfig?: Partial<ElasticsearchClientConfig>) => ClusterClient;
} | | | [http](./kibana-plugin-server.coresetup.http.md) | {
registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
createNewServer: HttpServiceSetup['createNewServer'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
} | | diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/src/core/server/elasticsearch/elasticsearch_service.mock.ts index 672331199ffa0..6c26c96ebca27 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.mock.ts @@ -23,7 +23,7 @@ import { ElasticsearchConfig } from './elasticsearch_config'; import { ElasticsearchService, ElasticsearchServiceSetup } from './elasticsearch_service'; const createSetupContractMock = () => { - const setupContract: ElasticsearchServiceSetup = { + const setupContract: jest.Mocked = { legacy: { config$: new BehaviorSubject({} as ElasticsearchConfig), }, diff --git a/src/core/server/index.ts b/src/core/server/index.ts index bcd101e9912e0..787478d5b3c3f 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -36,7 +36,11 @@ */ import { Observable } from 'rxjs'; -import { ClusterClient, ElasticsearchServiceSetup } from './elasticsearch'; +import { + ClusterClient, + ElasticsearchClientConfig, + ElasticsearchServiceSetup, +} from './elasticsearch'; import { HttpServiceSetup, HttpServiceStart } from './http'; import { PluginsServiceSetup, PluginsServiceStart } from './plugins'; @@ -115,6 +119,10 @@ export interface CoreSetup { elasticsearch: { adminClient$: Observable; dataClient$: Observable; + createClient: ( + type: string, + clientConfig?: Partial + ) => ClusterClient; }; http: { registerOnPreAuth: HttpServiceSetup['registerOnPreAuth']; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 139c142dcb1db..88039238af09f 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -115,6 +115,7 @@ export function createPluginSetupContext( elasticsearch: { adminClient$: deps.elasticsearch.adminClient$, dataClient$: deps.elasticsearch.dataClient$, + createClient: deps.elasticsearch.createClient, }, http: { registerOnPreAuth: deps.http.registerOnPreAuth, diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index c0464107210e6..e4345d1310ecf 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -89,6 +89,7 @@ export interface CoreSetup { elasticsearch: { adminClient$: Observable; dataClient$: Observable; + createClient: (type: string, clientConfig?: Partial) => ClusterClient; }; // (undocumented) http: {