From 145ec29ec099ad320d5b31a67793f6814acd795c Mon Sep 17 00:00:00 2001 From: Su Date: Fri, 26 Aug 2022 15:43:22 -0700 Subject: [PATCH] add UT Signed-off-by: Su --- .../data/server/index_patterns/routes.ts | 8 +- .../data_source/server/client/client_pool.ts | 4 +- .../server/client/configure_client.test.ts | 38 ++-- .../server/client/configure_client.ts | 50 +---- .../data_source/server/client/index.ts | 4 +- .../server/data_source_service.test.ts | 1 + .../data_source/server/data_source_service.ts | 47 ++--- .../server/legacy/client_config.test.ts | 28 +++ .../configure_legacy_client.test.mocks.ts | 18 ++ .../legacy/configure_legacy_client.test.ts | 183 ++++++++++++++++++ .../server/legacy/configure_legacy_client.ts | 28 +-- src/plugins/data_source/server/plugin.ts | 3 +- src/plugins/data_source/server/types.ts | 14 +- .../server/routes/resolve_index.ts | 3 +- 14 files changed, 299 insertions(+), 130 deletions(-) create mode 100644 src/plugins/data_source/server/legacy/client_config.test.ts create mode 100644 src/plugins/data_source/server/legacy/configure_legacy_client.test.mocks.ts create mode 100644 src/plugins/data_source/server/legacy/configure_legacy_client.test.ts diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 36715b5e681a..3adc1970dd81 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -155,10 +155,12 @@ export function registerRoutes(http: HttpServiceSetup) { ); } -const decideClient = async (context: RequestHandlerContext, request: any) => { +const decideClient = async ( + context: RequestHandlerContext, + request: any +): Promise => { const dataSourceId = request.query.data_source; return dataSourceId - ? ((await context.dataSource.opensearch.legacy.getClient(dataSourceId) - .callAPI) as LegacyAPICaller) + ? (context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI as LegacyAPICaller) : context.core.opensearch.legacy.client.callAsCurrentUser; }; diff --git a/src/plugins/data_source/server/client/client_pool.ts b/src/plugins/data_source/server/client/client_pool.ts index 612e9ff93708..56ca0ff7f7d0 100644 --- a/src/plugins/data_source/server/client/client_pool.ts +++ b/src/plugins/data_source/server/client/client_pool.ts @@ -15,14 +15,14 @@ export interface OpenSearchClientPoolSetup { } /** - * OpenSearch client pool. + * OpenSearch client pool for data source. * * This client pool uses an LRU cache to manage OpenSearch Js client objects. * It reuse TPC connections for each OpenSearch endpoint. */ export class OpenSearchClientPool { // LRU cache - // key: data source endpoint, prefixed with identifier for legacy + // key: data source endpoint // value: OpenSearch client object | Legacy client object private cache?: LRUCache; private isClosed = false; diff --git a/src/plugins/data_source/server/client/configure_client.test.ts b/src/plugins/data_source/server/client/configure_client.test.ts index 11523f649685..3393d3dc9c06 100644 --- a/src/plugins/data_source/server/client/configure_client.test.ts +++ b/src/plugins/data_source/server/client/configure_client.test.ts @@ -19,10 +19,11 @@ import { ClientOptions } from '@opensearch-project/opensearch'; // eslint-disable-next-line @osd/eslint/no-restricted-paths import { opensearchClientMock } from '../../../../core/server/opensearch/client/mocks'; import { CryptographyClient } from '../cryptography'; +import { DataSourceClientParams } from '../types'; const DATA_SOURCE_ID = 'a54b76ec86771ee865a0f74a305dfff8'; const CREDENETIAL_ID = 'a54dsaadasfasfwe22d23d23d2453df3'; -const cryptoClient = new CryptographyClient('test', 'test', new Array(32).fill(0)); +const cryptographyClient = new CryptographyClient('test', 'test', new Array(32).fill(0)); // TODO: improve UT describe('configureClient', () => { @@ -33,6 +34,7 @@ describe('configureClient', () => { let clientOptions: ClientOptions; let dataSourceAttr: DataSourceAttributes; let dsClient: ReturnType; + let dataSourceClientParams: DataSourceClientParams; beforeEach(() => { dsClient = opensearchClientMock.createInternalClient(); @@ -87,9 +89,13 @@ describe('configureClient', () => { references: [], }); - ClientMock.mockImplementation(() => { - return dsClient; - }); + dataSourceClientParams = { + dataSourceId: DATA_SOURCE_ID, + savedObjects: savedObjectsMock, + cryptographyClient, + }; + + ClientMock.mockImplementation(() => dsClient); }); afterEach(() => { @@ -106,14 +112,7 @@ describe('configureClient', () => { parseClientOptionsMock.mockReturnValue(clientOptions); - const client = await configureClient( - DATA_SOURCE_ID, - savedObjectsMock, - cryptoClient, - clientPoolSetup, - config, - logger - ); + const client = await configureClient(dataSourceClientParams, clientPoolSetup, config, logger); expect(parseClientOptionsMock).toHaveBeenCalled(); expect(ClientMock).toHaveBeenCalledTimes(1); @@ -123,20 +122,15 @@ describe('configureClient', () => { }); test('configure client with noAuth == false, will first call decrypt()', async () => { - const spy = jest.spyOn(cryptoClient, 'decodeAndDecrypt').mockResolvedValue('password'); + const decodeAndDecryptSpy = jest + .spyOn(cryptographyClient, 'decodeAndDecrypt') + .mockResolvedValue('password'); - const client = await configureClient( - DATA_SOURCE_ID, - savedObjectsMock, - cryptoClient, - clientPoolSetup, - config, - logger - ); + const client = await configureClient(dataSourceClientParams, clientPoolSetup, config, logger); expect(ClientMock).toHaveBeenCalledTimes(1); expect(savedObjectsMock.get).toHaveBeenCalledTimes(2); - expect(spy).toHaveBeenCalledTimes(1); + expect(decodeAndDecryptSpy).toHaveBeenCalledTimes(1); expect(client).toBe(dsClient.child.mock.results[0].value); }); }); diff --git a/src/plugins/data_source/server/client/configure_client.ts b/src/plugins/data_source/server/client/configure_client.ts index ea861deb2fed..4aaf7316d2d2 100644 --- a/src/plugins/data_source/server/client/configure_client.ts +++ b/src/plugins/data_source/server/client/configure_client.ts @@ -5,7 +5,7 @@ import { Client } from '@opensearch-project/opensearch'; import { - LegacyAPICaller, + Logger, SavedObject, SavedObjectsClientContract, SavedObjectsErrorHelpers, @@ -22,14 +22,12 @@ import { DataSourceClientParams } from '../types'; import { parseClientOptions } from './client_config'; import { OpenSearchClientPoolSetup } from './client_pool'; -export const configureClient = async ({ - dataSourceId, - savedObjects, - config, - logger, - cryptographyClient, - openSearchClientPoolSetup, -}: DataSourceClientParams): Promise => { +export const configureClient = async ( + { dataSourceId, savedObjects, cryptographyClient }: DataSourceClientParams, + openSearchClientPoolSetup: OpenSearchClientPoolSetup, + config: DataSourcePluginConfigType, + logger: Logger +): Promise => { const dataSource = await getDataSource(dataSourceId, savedObjects); const rootClient = getRootClient(dataSource.attributes, config, openSearchClientPoolSetup); @@ -66,6 +64,7 @@ export const getCredential = async ( username, password, } = credentialSavedObject.attributes.credentialMaterials.credentialMaterialsContent; + const decodedPassword = await cryptographyClient.decodeAndDecrypt(password); const credential = { username, @@ -148,36 +147,3 @@ const getBasicAuthClient = ( headers: { authorization: null }, }); }; - -// const getLegacyClient = (client: Client, isLegacy: boolean, logger: Logger): Client => { -// if (isLegacy) { -// logger.warn( -// 'Legacy OpenSearch client is used. Please migrate your code to use the new OpenSearch client.' -// ); -// return new LegacyScopedClusterClient(callAsCurrentUser, callAsCurrentUser); -// } else { -// return client; -// } -// }; - -/** - * Calls specified endpoint with provided clientParams on behalf of the - * user initiated request to the OpenSearch Dashboards server (via HTTP request headers). - * See {@link LegacyAPICaller}. - * - * @param endpoint - String descriptor of the endpoint e.g. `cluster.getSettings` or `ping`. - * @param clientParams - A dictionary of parameters that will be passed directly to the OpenSearch JS client. - * @param options - Options that affect the way we call the API and process the result. - */ -// const callAsCurrentUser: LegacyAPICaller = async ( -// client: Client, -// endpoint: string, -// clientParams: Record = {}, -// options?: LegacyCallAPIOptions -// ) => { -// return await (callAPI.bind(null, client as EsClient) as LegacyAPICaller)( -// endpoint, -// clientParams, -// options -// ); -// }; diff --git a/src/plugins/data_source/server/client/index.ts b/src/plugins/data_source/server/client/index.ts index 8adc96115b91..f27848965077 100644 --- a/src/plugins/data_source/server/client/index.ts +++ b/src/plugins/data_source/server/client/index.ts @@ -3,5 +3,5 @@ * SPDX-License-Identifier: Apache-2.0 */ -export { OpenSearchClientPool } from './client_pool'; -export { configureClient } from './configure_client'; +export { OpenSearchClientPool, OpenSearchClientPoolSetup } from './client_pool'; +export { configureClient, getDataSource, getCredential } from './configure_client'; diff --git a/src/plugins/data_source/server/data_source_service.test.ts b/src/plugins/data_source/server/data_source_service.test.ts index 53dfb6f273eb..690188562360 100644 --- a/src/plugins/data_source/server/data_source_service.test.ts +++ b/src/plugins/data_source/server/data_source_service.test.ts @@ -33,6 +33,7 @@ describe('Data Source Service', () => { test('exposes proper contract', async () => { const setup = await service.setup(config); expect(setup).toHaveProperty('getDataSourceClient'); + expect(setup).toHaveProperty('getDataSourceLegacyClient'); }); }); }); diff --git a/src/plugins/data_source/server/data_source_service.ts b/src/plugins/data_source/server/data_source_service.ts index 01ba4558018e..0ae7a8076d36 100644 --- a/src/plugins/data_source/server/data_source_service.ts +++ b/src/plugins/data_source/server/data_source_service.ts @@ -4,28 +4,15 @@ */ import { + LegacyAPICaller, LegacyCallAPIOptions, Logger, OpenSearchClient, - SavedObjectsClientContract, } from '../../../../src/core/server'; import { DataSourcePluginConfigType } from '../config'; import { OpenSearchClientPool, configureClient } from './client'; -import { CryptographyClient } from './cryptography'; import { configureLegacyClient } from './legacy'; - -export interface LegacyClientCallAPIParams { - endpoint: string; - clientParams?: Record; - options?: LegacyCallAPIOptions; -} - -export interface DataSourceClientParams { - dataSourceId: string; - // this saved objects client is used to fetch data source on behalf of users, caller should pass scoped saved objects client - savedObjects: SavedObjectsClientContract; - cryptographyClient: CryptographyClient; -} +import { DataSourceClientParams } from './types'; export interface DataSourceServiceSetup { getDataSourceClient: (params: DataSourceClientParams) => Promise; @@ -42,28 +29,26 @@ export interface DataSourceServiceSetup { } export class DataSourceService { private readonly openSearchClientPool: OpenSearchClientPool; + private readonly legacyClientPool: OpenSearchClientPool; + private readonly legacyLogger: Logger; constructor(private logger: Logger) { + this.legacyLogger = logger.get('legacy'); this.openSearchClientPool = new OpenSearchClientPool(logger); + this.legacyClientPool = new OpenSearchClientPool(this.legacyLogger); } async setup(config: DataSourcePluginConfigType): Promise { - const basicParams = { - openSearchClientPoolSetup: await this.openSearchClientPool.setup(config), - config, - logger: this.logger, - }; + const opensearchClientPoolSetup = await this.openSearchClientPool.setup(config); + const legacyClientPoolSetup = await this.legacyClientPool.setup(config); const getDataSourceClient = async ( - dataSourceClientParams: DataSourceClientParams + params: DataSourceClientParams ): Promise => { - return configureClient({ - ...basicParams, - ...dataSourceClientParams, - }); + return configureClient(params, opensearchClientPoolSetup, config, this.logger); }; - const getDataSourceLegacyClient = (dataSourceClientParams: DataSourceClientParams) => { + const getDataSourceLegacyClient = (params: DataSourceClientParams) => { return { callAPI: ( endpoint: string, @@ -71,11 +56,11 @@ export class DataSourceService { options?: LegacyCallAPIOptions ) => configureLegacyClient( - { - ...basicParams, - ...dataSourceClientParams, - }, - { endpoint, clientParams, options } + params, + { endpoint, clientParams, options }, + legacyClientPoolSetup, + config, + this.legacyLogger ), }; }; diff --git a/src/plugins/data_source/server/legacy/client_config.test.ts b/src/plugins/data_source/server/legacy/client_config.test.ts new file mode 100644 index 000000000000..1b21eede35bc --- /dev/null +++ b/src/plugins/data_source/server/legacy/client_config.test.ts @@ -0,0 +1,28 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +import { DataSourcePluginConfigType } from '../../config'; +import { parseClientOptions } from './client_config'; + +const TEST_DATA_SOURCE_ENDPOINT = 'http://datasource.com'; + +const config = { + enabled: true, + clientPool: { + size: 5, + }, +} as DataSourcePluginConfigType; + +describe('parseClientOptions', () => { + test('include the ssl client configs as defaults', () => { + expect(parseClientOptions(config, TEST_DATA_SOURCE_ENDPOINT)).toEqual( + expect.objectContaining({ + host: TEST_DATA_SOURCE_ENDPOINT, + ssl: { + rejectUnauthorized: true, + }, + }) + ); + }); +}); diff --git a/src/plugins/data_source/server/legacy/configure_legacy_client.test.mocks.ts b/src/plugins/data_source/server/legacy/configure_legacy_client.test.mocks.ts new file mode 100644 index 000000000000..e6c1b3363896 --- /dev/null +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.test.mocks.ts @@ -0,0 +1,18 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const ClientMock = jest.fn(); +jest.doMock('elasticsearch', () => { + const actual = jest.requireActual('elasticsearch'); + return { + ...actual, + Client: ClientMock, + }; +}); + +export const parseClientOptionsMock = jest.fn(); +jest.doMock('./client_config', () => ({ + parseClientOptions: parseClientOptionsMock, +})); diff --git a/src/plugins/data_source/server/legacy/configure_legacy_client.test.ts b/src/plugins/data_source/server/legacy/configure_legacy_client.test.ts new file mode 100644 index 000000000000..c338021f725b --- /dev/null +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.test.ts @@ -0,0 +1,183 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { LegacyAPICaller, SavedObjectsClientContract } from '../../../../core/server'; +import { loggingSystemMock, savedObjectsClientMock } from '../../../../core/server/mocks'; +import { DATA_SOURCE_SAVED_OBJECT_TYPE, CREDENTIAL_SAVED_OBJECT_TYPE } from '../../common'; +import { + CredentialMaterialsType, + CredentialSavedObjectAttributes, +} from '../../common/credentials/types'; +import { DataSourceAttributes } from '../../common/data_sources'; +import { DataSourcePluginConfigType } from '../../config'; +import { CryptographyClient } from '../cryptography'; +import { DataSourceClientParams, LegacyClientCallAPIParams } from '../types'; +import { OpenSearchClientPoolSetup } from '../client'; +import { ConfigOptions } from 'elasticsearch'; +import { ClientMock, parseClientOptionsMock } from './configure_legacy_client.test.mocks'; +import { configureLegacyClient } from './configure_legacy_client'; + +const DATA_SOURCE_ID = 'a54b76ec86771ee865a0f74a305dfff8'; +const CREDENETIAL_ID = 'a54dsaadasfasfwe22d23d23d2453df3'; +const cryptographyClient = new CryptographyClient('test', 'test', new Array(32).fill(0)); + +// TODO: improve UT +describe('configureLegacyClient', () => { + let logger: ReturnType; + let config: DataSourcePluginConfigType; + let savedObjectsMock: jest.Mocked; + let clientPoolSetup: OpenSearchClientPoolSetup; + let configOptions: ConfigOptions; + let dataSourceAttr: DataSourceAttributes; + + let mockOpenSearchClientInstance: { + close: jest.Mock; + ping: jest.Mock; + }; + let dataSourceClientParams: DataSourceClientParams; + let callApiParams: LegacyClientCallAPIParams; + + const mockResponse = { data: 'ping' }; + const decodeAndDecryptSpy = jest + .spyOn(cryptographyClient, 'decodeAndDecrypt') + .mockResolvedValue('password'); + + beforeEach(() => { + mockOpenSearchClientInstance = { + close: jest.fn(), + ping: jest.fn(), + }; + logger = loggingSystemMock.createLogger(); + savedObjectsMock = savedObjectsClientMock.create(); + config = { + enabled: true, + clientPool: { + size: 5, + }, + } as DataSourcePluginConfigType; + + configOptions = { + host: 'http://localhost', + ssl: { + rejectUnauthorized: true, + }, + } as ConfigOptions; + + dataSourceAttr = { + title: 'title', + endpoint: 'http://localhost', + noAuth: false, + } as DataSourceAttributes; + + clientPoolSetup = { + getClientFromPool: jest.fn(), + addClientToPool: jest.fn(), + }; + + callApiParams = { + endpoint: 'ping', + }; + + const crendentialAttr = { + title: 'cred', + credentialMaterials: { + credentialMaterialsType: CredentialMaterialsType.UsernamePasswordType, + credentialMaterialsContent: { + username: 'username', + password: 'password', + }, + }, + } as CredentialSavedObjectAttributes; + + savedObjectsMock.get + .mockResolvedValueOnce({ + id: DATA_SOURCE_ID, + type: DATA_SOURCE_SAVED_OBJECT_TYPE, + attributes: dataSourceAttr, + references: [{ name: 'user', type: CREDENTIAL_SAVED_OBJECT_TYPE, id: CREDENETIAL_ID }], + }) + .mockResolvedValueOnce({ + id: CREDENETIAL_ID, + type: CREDENTIAL_SAVED_OBJECT_TYPE, + attributes: crendentialAttr, + references: [], + }); + + dataSourceClientParams = { + dataSourceId: DATA_SOURCE_ID, + savedObjects: savedObjectsMock, + cryptographyClient, + }; + + ClientMock.mockImplementation(() => mockOpenSearchClientInstance); + + mockOpenSearchClientInstance.ping.mockImplementation(function mockCall(this: any) { + return Promise.resolve({ + context: this, + response: mockResponse, + }); + }); + }); + + afterEach(() => { + ClientMock.mockReset(); + savedObjectsMock.get.mockReset(); + }); + + test('configure client with noAuth == true, will call new Client() to create client', async () => { + savedObjectsMock.get.mockReset().mockResolvedValueOnce({ + id: DATA_SOURCE_ID, + type: DATA_SOURCE_SAVED_OBJECT_TYPE, + attributes: { ...dataSourceAttr, noAuth: true }, + references: [], + }); + + parseClientOptionsMock.mockReturnValue(configOptions); + + await configureLegacyClient( + dataSourceClientParams, + callApiParams, + clientPoolSetup, + config, + logger + ); + + expect(parseClientOptionsMock).toHaveBeenCalled(); + expect(ClientMock).toHaveBeenCalledTimes(1); + expect(ClientMock).toHaveBeenCalledWith(configOptions); + expect(savedObjectsMock.get).toHaveBeenCalledTimes(1); + }); + + test('configure client with noAuth == false, will first call decrypt()', async () => { + const mockResult = await configureLegacyClient( + dataSourceClientParams, + callApiParams, + clientPoolSetup, + config, + logger + ); + + expect(ClientMock).toHaveBeenCalledTimes(1); + expect(savedObjectsMock.get).toHaveBeenCalledTimes(2); + expect(decodeAndDecryptSpy).toHaveBeenCalledTimes(1); + expect(mockResult).toBeDefined(); + }); + + test('correctly called with endpoint and params', async () => { + const mockParams = { param: 'ping' }; + const mockResult = await configureLegacyClient( + dataSourceClientParams, + { ...callApiParams, clientParams: mockParams }, + clientPoolSetup, + config, + logger + ); + + expect(mockResult.response).toBe(mockResponse); + expect(mockResult.context).toBe(mockOpenSearchClientInstance); + expect(mockOpenSearchClientInstance.ping).toHaveBeenCalledTimes(1); + expect(mockOpenSearchClientInstance.ping).toHaveBeenLastCalledWith(mockParams); + }); +}); diff --git a/src/plugins/data_source/server/legacy/configure_legacy_client.ts b/src/plugins/data_source/server/legacy/configure_legacy_client.ts index 79ce3baf8bfd..e43b984690c0 100644 --- a/src/plugins/data_source/server/legacy/configure_legacy_client.ts +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.ts @@ -9,6 +9,7 @@ import { callAPI } from '../../../../../src/core/server/opensearch/legacy/cluste import { Headers, LegacyAPICaller, + Logger, SavedObject, SavedObjectsClientContract, } from '../../../../../src/core/server'; @@ -16,24 +17,16 @@ import { UsernamePasswordTypedContent } from '../../common/credentials/types'; import { DataSourceAttributes } from '../../common/data_sources'; import { DataSourcePluginConfigType } from '../../config'; import { CryptographyClient } from '../cryptography'; -import { DataSourceClientParams } from '../types'; -import { OpenSearchClientPoolSetup } from '../client/client_pool'; -import { getCredential, getDataSource } from '../client/configure_client'; -import { LegacyClientCallAPIParams } from '../data_source_service'; +import { DataSourceClientParams, LegacyClientCallAPIParams } from '../types'; +import { OpenSearchClientPoolSetup, getCredential, getDataSource } from '../client'; import { parseClientOptions } from './client_config'; -const LEGACY_CLIENT_PREFIX = 'legacy'; - export const configureLegacyClient = async ( - { - dataSourceId, - savedObjects, - config, - logger, - cryptographyClient, - openSearchClientPoolSetup, - }: DataSourceClientParams, - callApiParams: LegacyClientCallAPIParams + { dataSourceId, savedObjects, cryptographyClient }: DataSourceClientParams, + callApiParams: LegacyClientCallAPIParams, + openSearchClientPoolSetup: OpenSearchClientPoolSetup, + config: DataSourcePluginConfigType, + logger: Logger ) => { const dataSource = await getDataSource(dataSourceId, savedObjects); const rootClient = getRootClient(dataSource.attributes, config, openSearchClientPoolSetup); @@ -88,14 +81,13 @@ const getRootClient = ( { getClientFromPool, addClientToPool }: OpenSearchClientPoolSetup ): Client => { const endpoint = dataSourceAttr.endpoint; - const identifier = LEGACY_CLIENT_PREFIX + endpoint; - const cachedClient = getClientFromPool(identifier); + const cachedClient = getClientFromPool(endpoint); if (cachedClient) { return cachedClient as Client; } else { const configOptions = parseClientOptions(config, endpoint); const client = new Client(configOptions); - addClientToPool(identifier, client); + addClientToPool(endpoint, client); return client; } diff --git a/src/plugins/data_source/server/plugin.ts b/src/plugins/data_source/server/plugin.ts index 674af932c5b7..002a241e2ae1 100644 --- a/src/plugins/data_source/server/plugin.ts +++ b/src/plugins/data_source/server/plugin.ts @@ -15,7 +15,6 @@ import { Logger, IContextProvider, RequestHandler, - LegacyAPICaller, } from '../../../../src/core/server'; import { DataSourceService, DataSourceServiceSetup } from './data_source_service'; import { DataSourcePluginSetup, DataSourcePluginStart } from './types'; @@ -114,7 +113,7 @@ export class DataSourcePlugin implements Plugin; + options?: LegacyCallAPIOptions; +} + export interface DataSourceClientParams { dataSourceId: string; + // this saved objects client is used to fetch data source on behalf of users, caller should pass scoped saved objects client savedObjects: SavedObjectsClientContract; cryptographyClient: CryptographyClient; - openSearchClientPoolSetup: OpenSearchClientPoolSetup; - config: DataSourcePluginConfigType; - logger: Logger; } + export interface DataSourcePluginRequestContext { opensearch: { getClient: (dataSourceId: string) => Promise; diff --git a/src/plugins/index_pattern_management/server/routes/resolve_index.ts b/src/plugins/index_pattern_management/server/routes/resolve_index.ts index 6b5285f70692..baf19ca5b7d0 100644 --- a/src/plugins/index_pattern_management/server/routes/resolve_index.ts +++ b/src/plugins/index_pattern_management/server/routes/resolve_index.ts @@ -60,8 +60,7 @@ export function registerResolveIndexRoute(router: IRouter): void { const dataSourceId = req.query.data_source; const caller = dataSourceId - ? ((await context.dataSource.opensearch.legacy.getClient(dataSourceId) - .callAPI) as LegacyAPICaller) + ? context.dataSource.opensearch.legacy.getClient(dataSourceId).callAPI : context.core.opensearch.legacy.client.callAsCurrentUser; const result = await caller('transport.request', {