From b1aee55cc42af0dfe6983cfb9beed5c9d9ad247c Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Thu, 21 Mar 2024 18:21:18 +0000 Subject: [PATCH 1/2] [MD] Fix typo and remove unused imported package Signed-off-by: Xinrui Bai --- .../authentication_methods_registry.mock.ts | 6 +-- .../authentication_methods_registry.test.ts | 8 +-- .../authentication_methods_registry.ts | 6 +-- .../data_source/server/auth_registry/index.ts | 4 +- .../server/client/configure_client.test.ts | 28 +++++------ .../server/client/configure_client_utils.ts | 9 ++-- .../legacy/configure_legacy_client.test.ts | 32 ++++++------ src/plugins/data_source/server/plugin.ts | 10 ++-- .../routes/fetch_data_source_version.test.ts | 8 +-- .../routes/fetch_data_source_version.ts | 4 +- .../server/routes/test_connection.test.ts | 8 +-- .../server/routes/test_connection.ts | 4 +- ...ource_saved_objects_client_wrapper.test.ts | 4 +- ...ata_source_saved_objects_client_wrapper.ts | 4 +- src/plugins/data_source/server/types.ts | 6 +-- .../authentication_methods_registry.test.ts | 8 +-- .../authentication_methods_registry.ts | 6 +-- .../public/auth_registry/index.ts | 4 +- .../create_data_source_form.test.tsx | 36 ++++++------- .../create_form/create_data_source_form.tsx | 20 ++++---- .../edit_form/edit_data_source_form.test.tsx | 16 +++--- .../edit_form/edit_data_source_form.tsx | 26 +++++----- .../edit_data_source.test.tsx | 6 +-- .../public/components/utils.test.ts | 50 +++++++++---------- .../public/components/utils.ts | 20 ++++---- .../datasource_form_validation.test.ts | 24 ++++----- .../validation/datasource_form_validation.ts | 6 +-- .../mount_management_section.tsx | 6 +-- .../data_source_management/public/mocks.ts | 6 +-- .../public/plugin.test.ts | 2 +- .../data_source_management/public/plugin.ts | 10 ++-- .../data_source_management/public/types.ts | 4 +- 32 files changed, 194 insertions(+), 197 deletions(-) diff --git a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.mock.ts b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.mock.ts index 41e63798556..06d7ce4993d 100644 --- a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.mock.ts +++ b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.mock.ts @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { IAuthenticationMethodRegistery } from './authentication_methods_registry'; +import { IAuthenticationMethodRegistry } from './authentication_methods_registry'; const create = () => (({ getAllAuthenticationMethods: jest.fn(), getAuthenticationMethod: jest.fn(), - } as unknown) as jest.Mocked); + } as unknown) as jest.Mocked); -export const authenticationMethodRegisteryMock = { create }; +export const authenticationMethodRegistryMock = { create }; diff --git a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.test.ts b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.test.ts index 948641870a8..b171a5dab2d 100644 --- a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.test.ts +++ b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.test.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { AuthenticationMethodRegistery } from './authentication_methods_registry'; +import { AuthenticationMethodRegistry } from './authentication_methods_registry'; import { AuthenticationMethod } from '../../server/types'; const createAuthenticationMethod = ( @@ -14,11 +14,11 @@ const createAuthenticationMethod = ( ...authMethod, }); -describe('AuthenticationMethodRegistery', () => { - let registry: AuthenticationMethodRegistery; +describe('AuthenticationMethodRegistry', () => { + let registry: AuthenticationMethodRegistry; beforeEach(() => { - registry = new AuthenticationMethodRegistery(); + registry = new AuthenticationMethodRegistry(); }); it('allows to register authentication method', () => { diff --git a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts index 9fe2eb1e37e..988c5b9f37d 100644 --- a/src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts @@ -7,12 +7,12 @@ import { deepFreeze } from '@osd/std'; import { AuthenticationMethod } from '../../server/types'; import { AuthType } from '../../common/data_sources'; -export type IAuthenticationMethodRegistery = Omit< - AuthenticationMethodRegistery, +export type IAuthenticationMethodRegistry = Omit< + AuthenticationMethodRegistry, 'registerAuthenticationMethod' >; -export class AuthenticationMethodRegistery { +export class AuthenticationMethodRegistry { private readonly authMethods = new Map(); /** * Register a authMethods with function to return credentials inside the registry. diff --git a/src/plugins/data_source/server/auth_registry/index.ts b/src/plugins/data_source/server/auth_registry/index.ts index 9352afd8b66..704f5a26975 100644 --- a/src/plugins/data_source/server/auth_registry/index.ts +++ b/src/plugins/data_source/server/auth_registry/index.ts @@ -4,6 +4,6 @@ */ export { - IAuthenticationMethodRegistery, - AuthenticationMethodRegistery, + IAuthenticationMethodRegistry, + AuthenticationMethodRegistry, } from './authentication_methods_registry'; 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 f01db28080e..3cc89a5ef6e 100644 --- a/src/plugins/data_source/server/client/configure_client.test.ts +++ b/src/plugins/data_source/server/client/configure_client.test.ts @@ -28,8 +28,8 @@ import { cryptographyServiceSetupMock } from '../cryptography_service.mocks'; import { CryptographyServiceSetup } from '../cryptography_service'; import { DataSourceClientParams, AuthenticationMethod, ClientParameters } from '../types'; import { CustomApiSchemaRegistry } from '../schema_registry'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; -import { authenticationMethodRegisteryMock } from '../auth_registry/authentication_methods_registry.mock'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; +import { authenticationMethodRegistryMock } from '../auth_registry/authentication_methods_registry.mock'; const DATA_SOURCE_ID = 'a54b76ec86771ee865a0f74a305dfff8'; @@ -46,7 +46,7 @@ describe('configureClient', () => { let usernamePasswordAuthContent: UsernamePasswordTypedContent; let sigV4AuthContent: SigV4Content; let customApiSchemaRegistry: CustomApiSchemaRegistry; - let authenticationMethodRegistery: jest.Mocked; + let authenticationMethodRegistry: jest.Mocked; let clientParameters: ClientParameters; const customAuthContent = { @@ -70,7 +70,7 @@ describe('configureClient', () => { savedObjectsMock = savedObjectsClientMock.create(); cryptographyMock = cryptographyServiceSetupMock.create(); customApiSchemaRegistry = new CustomApiSchemaRegistry(); - authenticationMethodRegistery = authenticationMethodRegisteryMock.create(); + authenticationMethodRegistry = authenticationMethodRegistryMock.create(); config = { enabled: true, @@ -128,7 +128,7 @@ describe('configureClient', () => { }; ClientMock.mockImplementation(() => dsClient); - authenticationMethodRegistery.getAuthenticationMethod.mockImplementation(() => authMethod); + authenticationMethodRegistry.getAuthenticationMethod.mockImplementation(() => authMethod); authRegistryCredentialProviderMock.mockReturnValue(clientParameters); }); @@ -299,13 +299,13 @@ describe('configureClient', () => { }); const client = await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, clientPoolSetup, config, logger ); expect(authRegistryCredentialProviderMock).toHaveBeenCalled(); - expect(authenticationMethodRegistery.getAuthenticationMethod).toHaveBeenCalledTimes(1); + expect(authenticationMethodRegistry.getAuthenticationMethod).toHaveBeenCalledTimes(1); expect(ClientMock).toHaveBeenCalledTimes(1); expect(savedObjectsMock.get).toHaveBeenCalledTimes(1); expect(client).toBe(dsClient.child.mock.results[0].value); @@ -343,7 +343,7 @@ describe('configureClient', () => { }); const client = await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, clientPoolSetup, config, logger @@ -379,7 +379,7 @@ describe('configureClient', () => { }); const client = await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, clientPoolSetup, config, logger @@ -555,7 +555,7 @@ describe('configureClient', () => { name: 'clientPoolTest', credentialProvider: jest.fn(), }; - authenticationMethodRegistery.getAuthenticationMethod + authenticationMethodRegistry.getAuthenticationMethod .mockReset() .mockImplementation(() => authMethodWithClientPool); const mockDataSourceAttr = { ...dataSourceAttr, name: 'custom_auth' }; @@ -574,14 +574,14 @@ describe('configureClient', () => { }); test('If endpoint is same for multiple requests client pool size should be 1', async () => { await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, opensearchClientPoolSetup, config, logger ); await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, opensearchClientPoolSetup, config, logger @@ -592,7 +592,7 @@ describe('configureClient', () => { test('If endpoint is different for two requests client pool size should be 2', async () => { await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, opensearchClientPoolSetup, config, logger @@ -622,7 +622,7 @@ describe('configureClient', () => { }); await configureClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, opensearchClientPoolSetup, config, logger diff --git a/src/plugins/data_source/server/client/configure_client_utils.ts b/src/plugins/data_source/server/client/configure_client_utils.ts index a7229a0d32f..2748ddfd5ca 100644 --- a/src/plugins/data_source/server/client/configure_client_utils.ts +++ b/src/plugins/data_source/server/client/configure_client_utils.ts @@ -5,10 +5,7 @@ import { Client } from '@opensearch-project/opensearch'; import { Client as LegacyClient } from 'elasticsearch'; -import { - OpenSearchDashboardsRequest, - SavedObjectsClientContract, -} from '../../../../../src/core/server'; +import { SavedObjectsClientContract } from '../../../../../src/core/server'; import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../../common'; import { DataSourceAttributes, @@ -18,7 +15,7 @@ import { } from '../../common/data_sources'; import { CryptographyServiceSetup } from '../cryptography_service'; import { createDataSourceError } from '../lib/error'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; import { AuthenticationMethod, ClientParameters } from '../types'; /** @@ -142,7 +139,7 @@ export const generateCacheKey = (endpoint: string, cacheKeySuffix?: string) => { export const getAuthenticationMethod = ( dataSourceAttr: DataSourceAttributes, - authRegistry?: IAuthenticationMethodRegistery + authRegistry?: IAuthenticationMethodRegistry ): AuthenticationMethod => { const name = dataSourceAttr.name ?? dataSourceAttr.auth.type; return authRegistry?.getAuthenticationMethod(name) as AuthenticationMethod; 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 index 581e545315e..b657df32565 100644 --- a/src/plugins/data_source/server/legacy/configure_legacy_client.test.ts +++ b/src/plugins/data_source/server/legacy/configure_legacy_client.test.ts @@ -27,8 +27,8 @@ import { ClientMock, parseClientOptionsMock } from './configure_legacy_client.te import { authRegistryCredentialProviderMock } from '../client/configure_client.test.mocks'; import { configureLegacyClient } from './configure_legacy_client'; import { CustomApiSchemaRegistry } from '../schema_registry'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; -import { authenticationMethodRegisteryMock } from '../auth_registry/authentication_methods_registry.mock'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; +import { authenticationMethodRegistryMock } from '../auth_registry/authentication_methods_registry.mock'; const DATA_SOURCE_ID = 'a54b76ec86771ee865a0f74a305dfff8'; @@ -41,7 +41,7 @@ describe('configureLegacyClient', () => { let configOptions: ConfigOptions; let dataSourceAttr: DataSourceAttributes; let sigV4AuthContent: SigV4Content; - let authenticationMethodRegistery: jest.Mocked; + let authenticationMethodRegistry: jest.Mocked; let clientParameters: ClientParameters; let mockOpenSearchClientInstance: { @@ -77,7 +77,7 @@ describe('configureLegacyClient', () => { logger = loggingSystemMock.createLogger(); savedObjectsMock = savedObjectsClientMock.create(); cryptographyMock = cryptographyServiceSetupMock.create(); - authenticationMethodRegistery = authenticationMethodRegisteryMock.create(); + authenticationMethodRegistry = authenticationMethodRegistryMock.create(); config = { enabled: true, clientPool: { @@ -144,7 +144,7 @@ describe('configureLegacyClient', () => { }); }); - authenticationMethodRegistery.getAuthenticationMethod.mockImplementation(() => authMethod); + authenticationMethodRegistry.getAuthenticationMethod.mockImplementation(() => authMethod); authRegistryCredentialProviderMock.mockReturnValue(clientParameters); }); @@ -318,14 +318,14 @@ describe('configureLegacyClient', () => { }); await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, clientPoolSetup, config, logger ); expect(authRegistryCredentialProviderMock).toHaveBeenCalled(); - expect(authenticationMethodRegistery.getAuthenticationMethod).toHaveBeenCalledTimes(1); + expect(authenticationMethodRegistry.getAuthenticationMethod).toHaveBeenCalledTimes(1); expect(ClientMock).toHaveBeenCalledTimes(1); expect(savedObjectsMock.get).toHaveBeenCalledTimes(1); expect(mockOpenSearchClientInstance.ping).toHaveBeenCalledTimes(1); @@ -365,14 +365,14 @@ describe('configureLegacyClient', () => { }); await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, clientPoolSetup, config, logger ); expect(authRegistryCredentialProviderMock).toHaveBeenCalled(); - expect(authenticationMethodRegistery.getAuthenticationMethod).toHaveBeenCalledTimes(1); + expect(authenticationMethodRegistry.getAuthenticationMethod).toHaveBeenCalledTimes(1); expect(ClientMock).toHaveBeenCalledTimes(1); expect(savedObjectsMock.get).toHaveBeenCalledTimes(1); expect(mockOpenSearchClientInstance.ping).toHaveBeenCalledTimes(1); @@ -405,14 +405,14 @@ describe('configureLegacyClient', () => { }); await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, clientPoolSetup, config, logger ); expect(authRegistryCredentialProviderMock).toHaveBeenCalled(); - expect(authenticationMethodRegistery.getAuthenticationMethod).toHaveBeenCalledTimes(1); + expect(authenticationMethodRegistry.getAuthenticationMethod).toHaveBeenCalledTimes(1); expect(ClientMock).toHaveBeenCalledTimes(1); expect(savedObjectsMock.get).toHaveBeenCalledTimes(1); expect(mockOpenSearchClientInstance.ping).toHaveBeenCalledTimes(1); @@ -657,7 +657,7 @@ describe('configureLegacyClient', () => { name: 'clientPoolTest', credentialProvider: jest.fn(), }; - authenticationMethodRegistery.getAuthenticationMethod + authenticationMethodRegistry.getAuthenticationMethod .mockReset() .mockImplementation(() => authMethodWithClientPool); const mockDataSourceAttr = { ...dataSourceAttr, name: 'custom_auth' }; @@ -676,7 +676,7 @@ describe('configureLegacyClient', () => { }); test(' If endpoint is same for multiple requests client pool size should be 1', async () => { await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, opensearchClientPoolSetup, config, @@ -684,7 +684,7 @@ describe('configureLegacyClient', () => { ); await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, opensearchClientPoolSetup, config, @@ -696,7 +696,7 @@ describe('configureLegacyClient', () => { test('If endpoint is different for two requests client pool size should be 2', async () => { await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, opensearchClientPoolSetup, config, @@ -727,7 +727,7 @@ describe('configureLegacyClient', () => { }); await configureLegacyClient( - { ...dataSourceClientParams, authRegistry: authenticationMethodRegistery }, + { ...dataSourceClientParams, authRegistry: authenticationMethodRegistry }, callApiParams, opensearchClientPoolSetup, config, diff --git a/src/plugins/data_source/server/plugin.ts b/src/plugins/data_source/server/plugin.ts index c239c816594..6eabe543168 100644 --- a/src/plugins/data_source/server/plugin.ts +++ b/src/plugins/data_source/server/plugin.ts @@ -31,7 +31,7 @@ import { ensureRawRequest } from '../../../../src/core/server/http/router'; import { createDataSourceError } from './lib/error'; import { registerTestConnectionRoute } from './routes/test_connection'; import { registerFetchDataSourceVersionRoute } from './routes/fetch_data_source_version'; -import { AuthenticationMethodRegistery, IAuthenticationMethodRegistery } from './auth_registry'; +import { AuthenticationMethodRegistry, IAuthenticationMethodRegistry } from './auth_registry'; import { CustomApiSchemaRegistry } from './schema_registry'; export class DataSourcePlugin implements Plugin { @@ -40,7 +40,7 @@ export class DataSourcePlugin implements Plugin; private started = false; - private authMethodsRegistry = new AuthenticationMethodRegistery(); + private authMethodsRegistry = new AuthenticationMethodRegistry(); private customApiSchemaRegistry = new CustomApiSchemaRegistry(); constructor(private initializerContext: PluginInitializerContext) { @@ -64,7 +64,7 @@ export class DataSourcePlugin implements Plugin { const dataSourcePluginStart = selfStart as DataSourcePluginStart; - return dataSourcePluginStart.getAuthenticationMethodRegistery(); + return dataSourcePluginStart.getAuthenticationMethodRegistry(); }); const dataSourceSavedObjectsClientWrapper = new DataSourceSavedObjectsClientWrapper( @@ -162,7 +162,7 @@ export class DataSourcePlugin implements Plugin this.authMethodsRegistry, + getAuthenticationMethodRegistry: () => this.authMethodsRegistry, getCustomApiSchemaRegistry: () => this.customApiSchemaRegistry, }; } @@ -176,7 +176,7 @@ export class DataSourcePlugin implements Plugin, - authRegistryPromise: Promise, + authRegistryPromise: Promise, customApiSchemaRegistryPromise: Promise ): IContextProvider, 'dataSource'> => { return async (context, req) => { diff --git a/src/plugins/data_source/server/routes/fetch_data_source_version.test.ts b/src/plugins/data_source/server/routes/fetch_data_source_version.test.ts index d81073f9beb..5514cbdc40f 100644 --- a/src/plugins/data_source/server/routes/fetch_data_source_version.test.ts +++ b/src/plugins/data_source/server/routes/fetch_data_source_version.test.ts @@ -7,8 +7,8 @@ import supertest from 'supertest'; import { UnwrapPromise } from '@osd/utility-types'; import { setupServer } from '../../../../../src/core/server/test_utils'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; -import { authenticationMethodRegisteryMock } from '../auth_registry/authentication_methods_registry.mock'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; +import { authenticationMethodRegistryMock } from '../auth_registry/authentication_methods_registry.mock'; import { CustomApiSchemaRegistry } from '../schema_registry'; import { DataSourceServiceSetup } from '../../server/data_source_service'; import { CryptographyServiceSetup } from '../cryptography_service'; @@ -30,7 +30,7 @@ describe(`Fetch DataSource Version ${URL}`, () => { let customApiSchemaRegistryPromise: Promise; let dataSourceClient: ReturnType; let dataSourceServiceSetupMock: DataSourceServiceSetup; - let authRegistryPromiseMock: Promise; + let authRegistryPromiseMock: Promise; const dataSourceAttr = { endpoint: 'https://test.com', auth: { @@ -155,7 +155,7 @@ describe(`Fetch DataSource Version ${URL}`, () => { beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); customApiSchemaRegistryPromise = Promise.resolve(customApiSchemaRegistry); - authRegistryPromiseMock = Promise.resolve(authenticationMethodRegisteryMock.create()); + authRegistryPromiseMock = Promise.resolve(authenticationMethodRegistryMock.create()); dataSourceClient = opensearchClientMock.createInternalClient(); dataSourceServiceSetupMock = { diff --git a/src/plugins/data_source/server/routes/fetch_data_source_version.ts b/src/plugins/data_source/server/routes/fetch_data_source_version.ts index 5bd53f728e4..b2f03f7fddc 100644 --- a/src/plugins/data_source/server/routes/fetch_data_source_version.ts +++ b/src/plugins/data_source/server/routes/fetch_data_source_version.ts @@ -9,14 +9,14 @@ import { AuthType, DataSourceAttributes, SigV4ServiceName } from '../../common/d import { DataSourceConnectionValidator } from './data_source_connection_validator'; import { DataSourceServiceSetup } from '../data_source_service'; import { CryptographyServiceSetup } from '../cryptography_service'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; import { CustomApiSchemaRegistry } from '../schema_registry/custom_api_schema_registry'; export const registerFetchDataSourceVersionRoute = async ( router: IRouter, dataSourceServiceSetup: DataSourceServiceSetup, cryptography: CryptographyServiceSetup, - authRegistryPromise: Promise, + authRegistryPromise: Promise, customApiSchemaRegistryPromise: Promise ) => { const authRegistry = await authRegistryPromise; diff --git a/src/plugins/data_source/server/routes/test_connection.test.ts b/src/plugins/data_source/server/routes/test_connection.test.ts index 8027354601b..cbe35ef6562 100644 --- a/src/plugins/data_source/server/routes/test_connection.test.ts +++ b/src/plugins/data_source/server/routes/test_connection.test.ts @@ -7,8 +7,8 @@ import supertest from 'supertest'; import { UnwrapPromise } from '@osd/utility-types'; import { setupServer } from '../../../../../src/core/server/test_utils'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; -import { authenticationMethodRegisteryMock } from '../auth_registry/authentication_methods_registry.mock'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; +import { authenticationMethodRegistryMock } from '../auth_registry/authentication_methods_registry.mock'; import { CustomApiSchemaRegistry } from '../schema_registry'; import { DataSourceServiceSetup } from '../../server/data_source_service'; import { CryptographyServiceSetup } from '../cryptography_service'; @@ -30,7 +30,7 @@ describe(`Test connection ${URL}`, () => { let customApiSchemaRegistryPromise: Promise; let dataSourceClient: ReturnType; let dataSourceServiceSetupMock: DataSourceServiceSetup; - let authRegistryPromiseMock: Promise; + let authRegistryPromiseMock: Promise; const dataSourceAttr = { endpoint: 'https://test.com', auth: { @@ -155,7 +155,7 @@ describe(`Test connection ${URL}`, () => { beforeEach(async () => { ({ server, httpSetup, handlerContext } = await setupServer()); customApiSchemaRegistryPromise = Promise.resolve(customApiSchemaRegistry); - authRegistryPromiseMock = Promise.resolve(authenticationMethodRegisteryMock.create()); + authRegistryPromiseMock = Promise.resolve(authenticationMethodRegistryMock.create()); dataSourceClient = opensearchClientMock.createInternalClient(); dataSourceServiceSetupMock = { diff --git a/src/plugins/data_source/server/routes/test_connection.ts b/src/plugins/data_source/server/routes/test_connection.ts index 4edebc12fa8..1aded3a2132 100644 --- a/src/plugins/data_source/server/routes/test_connection.ts +++ b/src/plugins/data_source/server/routes/test_connection.ts @@ -9,14 +9,14 @@ import { AuthType, DataSourceAttributes, SigV4ServiceName } from '../../common/d import { DataSourceConnectionValidator } from './data_source_connection_validator'; import { DataSourceServiceSetup } from '../data_source_service'; import { CryptographyServiceSetup } from '../cryptography_service'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; import { CustomApiSchemaRegistry } from '../schema_registry/custom_api_schema_registry'; export const registerTestConnectionRoute = async ( router: IRouter, dataSourceServiceSetup: DataSourceServiceSetup, cryptography: CryptographyServiceSetup, - authRegistryPromise: Promise, + authRegistryPromise: Promise, customApiSchemaRegistryPromise: Promise ) => { const authRegistry = await authRegistryPromise; diff --git a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.test.ts b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.test.ts index d6d06374a67..4921218a2d4 100644 --- a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.test.ts +++ b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.test.ts @@ -23,10 +23,10 @@ describe('DataSourceSavedObjectsClientWrapper', () => { credentialProvider: jest.fn(), }; jest.mock('../auth_registry'); - const { AuthenticationMethodRegistery: authenticationMethodRegistery } = jest.requireActual( + const { AuthenticationMethodRegistry: authenticationMethodRegistry } = jest.requireActual( '../auth_registry' ); - const authRegistry = new authenticationMethodRegistery(); + const authRegistry = new authenticationMethodRegistry(); authRegistry.registerAuthenticationMethod(customAuthMethod); const requestHandlerContext = coreMock.createRequestHandlerContext(); diff --git a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts index a3531355399..25fdf6d59d7 100644 --- a/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts +++ b/src/plugins/data_source/server/saved_objects/data_source_saved_objects_client_wrapper.ts @@ -25,7 +25,7 @@ import { } from '../../common/data_sources'; import { EncryptionContext, CryptographyServiceSetup } from '../cryptography_service'; import { isValidURL } from '../util/endpoint_validator'; -import { IAuthenticationMethodRegistery } from '../auth_registry'; +import { IAuthenticationMethodRegistry } from '../auth_registry'; /** * Describes the Credential Saved Objects Client Wrapper class, @@ -141,7 +141,7 @@ export class DataSourceSavedObjectsClientWrapper { constructor( private cryptography: CryptographyServiceSetup, private logger: Logger, - private authRegistryPromise: Promise, + private authRegistryPromise: Promise, private endpointBlockedIps?: string[] ) {} diff --git a/src/plugins/data_source/server/types.ts b/src/plugins/data_source/server/types.ts index 847e2f72ff6..1f7d297c8b8 100644 --- a/src/plugins/data_source/server/types.ts +++ b/src/plugins/data_source/server/types.ts @@ -18,7 +18,7 @@ import { import { CryptographyServiceSetup } from './cryptography_service'; import { DataSourceError } from './lib/error'; -import { IAuthenticationMethodRegistery } from './auth_registry'; +import { IAuthenticationMethodRegistry } from './auth_registry'; import { CustomApiSchemaRegistry } from './schema_registry'; export interface LegacyClientCallAPIParams { @@ -40,7 +40,7 @@ export interface DataSourceClientParams { // When client parameters are required to be retrieved from the request header, the caller should provide the request. request?: OpenSearchDashboardsRequest; // To retrieve the credentials provider for the authentication method from the registry in order to return the client. - authRegistry?: IAuthenticationMethodRegistery; + authRegistry?: IAuthenticationMethodRegistry; } export interface DataSourceCredentialsProviderOptions { @@ -95,6 +95,6 @@ export interface DataSourcePluginSetup { } export interface DataSourcePluginStart { - getAuthenticationMethodRegistery: () => IAuthenticationMethodRegistery; + getAuthenticationMethodRegistry: () => IAuthenticationMethodRegistry; getCustomApiSchemaRegistry: () => CustomApiSchemaRegistry; } diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.test.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.test.ts index f2bd07af4dc..599f66018d4 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.test.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.test.ts @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { AuthenticationMethodRegistery } from './authentication_methods_registry'; +import { AuthenticationMethodRegistry } from './authentication_methods_registry'; import React from 'react'; import { createAuthenticationMethod } from '../mocks'; -describe('AuthenticationMethodRegistery', () => { - let registry: AuthenticationMethodRegistery; +describe('AuthenticationMethodRegistry', () => { + let registry: AuthenticationMethodRegistry; beforeEach(() => { - registry = new AuthenticationMethodRegistery(); + registry = new AuthenticationMethodRegistry(); }); it('allows to register authentication method', () => { diff --git a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts index 7d6bf38026a..a9443601af0 100644 --- a/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts +++ b/src/plugins/data_source_management/public/auth_registry/authentication_methods_registry.ts @@ -16,12 +16,12 @@ export interface AuthenticationMethod { credentialFormField?: { [key: string]: string }; } -export type IAuthenticationMethodRegistery = Omit< - AuthenticationMethodRegistery, +export type IAuthenticationMethodRegistry = Omit< + AuthenticationMethodRegistry, 'registerAuthenticationMethod' >; -export class AuthenticationMethodRegistery { +export class AuthenticationMethodRegistry { private readonly authMethods = new Map(); /** * Register a authMethods with function to return credentials inside the registry. diff --git a/src/plugins/data_source_management/public/auth_registry/index.ts b/src/plugins/data_source_management/public/auth_registry/index.ts index 5cbadd12a51..bc832d1c4f1 100644 --- a/src/plugins/data_source_management/public/auth_registry/index.ts +++ b/src/plugins/data_source_management/public/auth_registry/index.ts @@ -4,7 +4,7 @@ */ export { - IAuthenticationMethodRegistery, + IAuthenticationMethodRegistry, AuthenticationMethod, - AuthenticationMethodRegistery, + AuthenticationMethodRegistry, } from './authentication_methods_registry'; diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx index 2c7778868bc..e03d3ef2b73 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.test.tsx @@ -17,7 +17,7 @@ import { sigV4AuthMethod, usernamePasswordAuthMethod, } from '../../../../types'; -import { AuthenticationMethod, AuthenticationMethodRegistery } from '../../../../auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistry } from '../../../../auth_registry'; const titleIdentifier = '[data-test-subj="createDataSourceFormTitleField"]'; const descriptionIdentifier = `[data-test-subj="createDataSourceFormDescriptionField"]`; @@ -30,13 +30,13 @@ const testConnectionButtonIdentifier = '[data-test-subj="createDataSourceTestCon describe('Datasource Management: Create Datasource form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( noAuthCredentialAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( usernamePasswordAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(sigV4AuthMethod); let component: ReactWrapper, React.Component<{}, {}, any>>; const mockSubmitHandler = jest.fn(); @@ -257,10 +257,10 @@ describe('Datasource Management: Create Datasource form with different authType authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -296,10 +296,10 @@ describe('Datasource Management: Create Datasource form with different authType authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -335,10 +335,10 @@ describe('Datasource Management: Create Datasource form with different authType authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -398,10 +398,10 @@ describe('Datasource Management: Create Datasource form with registered Auth Typ authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -451,10 +451,10 @@ describe('Datasource Management: Create Datasource form with registered Auth Typ authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -498,10 +498,10 @@ describe('Datasource Management: Create Datasource form with registered Auth Typ authMethodCombinationsToBeTested.forEach((authMethodCombination) => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); authMethodCombination.forEach((authMethod) => { - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); component = mount( @@ -541,8 +541,8 @@ describe('Datasource Management: Create Datasource form with registered Auth Typ } as AuthenticationMethod; const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); component = mount( wrapWithIntl( diff --git a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx index 180476e8b08..e2f256d23e8 100644 --- a/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/create_data_source_wizard/components/create_form/create_data_source_form.tsx @@ -22,7 +22,7 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; -import { AuthenticationMethodRegistery } from '../../../../auth_registry'; +import { AuthenticationMethodRegistry } from '../../../../auth_registry'; import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/common/data_sources'; import { AuthType, @@ -77,17 +77,17 @@ export class CreateDataSourceForm extends React.Component< authOptions: Array> = []; isNoAuthOptionEnabled: boolean; - authenticationMethodRegistery: AuthenticationMethodRegistery; + authenticationMethodRegistry: AuthenticationMethodRegistry; constructor(props: CreateDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); - this.authenticationMethodRegistery = context.services.authenticationMethodRegistery; - const registeredAuthMethods = this.authenticationMethodRegistery.getAllAuthenticationMethods(); - const initialSelectedAuthMethod = getDefaultAuthMethod(this.authenticationMethodRegistery); + this.authenticationMethodRegistry = context.services.authenticationMethodRegistry; + const registeredAuthMethods = this.authenticationMethodRegistry.getAllAuthenticationMethods(); + const initialSelectedAuthMethod = getDefaultAuthMethod(this.authenticationMethodRegistry); this.isNoAuthOptionEnabled = - this.authenticationMethodRegistery.getAuthenticationMethod(AuthType.NoAuth) !== undefined; + this.authenticationMethodRegistry.getAuthenticationMethod(AuthType.NoAuth) !== undefined; this.authOptions = registeredAuthMethods.map((authMethod) => { return authMethod.credentialSourceOption; @@ -114,7 +114,7 @@ export class CreateDataSourceForm extends React.Component< this.state, this.props.existingDatasourceNamesList, '', - this.authenticationMethodRegistery + this.authenticationMethodRegistry ); }; @@ -158,7 +158,7 @@ export class CreateDataSourceForm extends React.Component< const registeredAuthCredentials = extractRegisteredAuthTypeCredentials( (credentials ?? {}) as { [key: string]: string }, authType, - this.authenticationMethodRegistery + this.authenticationMethodRegistry ); this.setState({ @@ -337,7 +337,7 @@ export class CreateDataSourceForm extends React.Component< credentials = extractRegisteredAuthTypeCredentials( currentCredentials, authType, - this.authenticationMethodRegistery + this.authenticationMethodRegistry ); } @@ -354,7 +354,7 @@ export class CreateDataSourceForm extends React.Component< }; getCredentialFormFromRegistry = (authType: string) => { - const registeredAuthMethod = this.authenticationMethodRegistery.getAuthenticationMethod( + const registeredAuthMethod = this.authenticationMethodRegistry.getAuthenticationMethod( authType ); const authCredentialForm = registeredAuthMethod?.credentialForm; diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx index e5f73c503f6..be5a3a31be7 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.test.tsx @@ -22,7 +22,7 @@ import { sigV4AuthMethod, usernamePasswordAuthMethod, } from '../../../../types'; -import { AuthenticationMethod, AuthenticationMethodRegistery } from '../../../../auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistry } from '../../../../auth_registry'; const titleFieldIdentifier = 'dataSourceTitle'; const titleFormRowIdentifier = '[data-test-subj="editDataSourceTitleFormRow"]'; @@ -36,13 +36,13 @@ const passwordFieldIdentifier = '[data-test-subj="updateDataSourceFormPasswordFi const updatePasswordBtnIdentifier = '[data-test-subj="editDatasourceUpdatePasswordBtn"]'; describe('Datasource Management: Edit Datasource Form', () => { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( noAuthCredentialAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( usernamePasswordAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(sigV4AuthMethod); let component: ReactWrapper, React.Component<{}, {}, any>>; const mockFn = jest.fn(); @@ -385,8 +385,8 @@ describe('With Registered Authentication', () => { } as AuthenticationMethod; const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTest); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTest); component = mount( wrapWithIntl( @@ -426,8 +426,8 @@ describe('With Registered Authentication', () => { } as AuthenticationMethod; const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); - mockedContext.authenticationMethodRegistery = new AuthenticationMethodRegistery(); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTest); + mockedContext.authenticationMethodRegistry = new AuthenticationMethodRegistry(); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTest); component = mount( wrapWithIntl( diff --git a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx index 6714881c4a1..63336cca5d3 100644 --- a/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx +++ b/src/plugins/data_source_management/public/components/edit_data_source/components/edit_form/edit_data_source_form.tsx @@ -25,7 +25,7 @@ import { import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; import deepEqual from 'fast-deep-equal'; -import { AuthenticationMethodRegistery } from '../../../../auth_registry'; +import { AuthenticationMethodRegistry } from '../../../../auth_registry'; import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/common/data_sources'; import { Header } from '../header'; import { @@ -81,19 +81,19 @@ export class EditDataSourceForm extends React.Component> = []; - authenticationMethodRegistery: AuthenticationMethodRegistery; + authenticationMethodRegistry: AuthenticationMethodRegistry; constructor(props: EditDataSourceProps, context: DataSourceManagementContextValue) { super(props, context); - this.authenticationMethodRegistery = context.services.authenticationMethodRegistery; - this.authOptions = this.authenticationMethodRegistery + this.authenticationMethodRegistry = context.services.authenticationMethodRegistry; + this.authOptions = this.authenticationMethodRegistry .getAllAuthenticationMethods() .map((authMethod) => { return authMethod.credentialSourceOption; }); - const initialSelectedAuthMethod = getDefaultAuthMethod(this.authenticationMethodRegistery); + const initialSelectedAuthMethod = getDefaultAuthMethod(this.authenticationMethodRegistry); this.state = { formErrorsByField: { ...defaultValidation }, @@ -129,7 +129,7 @@ export class EditDataSourceForm extends React.Component { - const registeredAuthMethod = this.authenticationMethodRegistery.getAuthenticationMethod( + const registeredAuthMethod = this.authenticationMethodRegistry.getAuthenticationMethod( authType ); const authCredentialForm = registeredAuthMethod?.credentialForm; @@ -1078,13 +1078,13 @@ export class EditDataSourceForm extends React.Component { const mockedContext = mockManagementPlugin.createDataSourceManagementContext(); const uiSettings = mockedContext.uiSettings; - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( noAuthCredentialAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod( + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod( usernamePasswordAuthMethod ); - mockedContext.authenticationMethodRegistery.registerAuthenticationMethod(sigV4AuthMethod); + mockedContext.authenticationMethodRegistry.registerAuthenticationMethod(sigV4AuthMethod); let component: ReactWrapper, React.Component<{}, {}, any>>; const history = (scopedHistoryMock.create() as unknown) as ScopedHistory; diff --git a/src/plugins/data_source_management/public/components/utils.test.ts b/src/plugins/data_source_management/public/components/utils.test.ts index a327c22bf0c..a4069f01907 100644 --- a/src/plugins/data_source_management/public/components/utils.test.ts +++ b/src/plugins/data_source_management/public/components/utils.test.ts @@ -32,7 +32,7 @@ import { usernamePasswordAuthMethod, } from '../types'; import { HttpStart } from 'opensearch-dashboards/public'; -import { AuthenticationMethod, AuthenticationMethodRegistery } from '../auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistry } from '../auth_registry'; import { deepEqual } from 'assert'; const { savedObjects } = coreMock.createStart(); @@ -239,13 +239,13 @@ describe('DataSourceManagement: Utils.ts', () => { ]; authMethodCombinationsToBeTested.forEach((authOptions) => { - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); authOptions.forEach((authMethod) => { - authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); - expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe( + expect(getDefaultAuthMethod(authenticationMethodRegistry)?.name).toBe( AuthType.UsernamePasswordType ); }); @@ -259,19 +259,19 @@ describe('DataSourceManagement: Utils.ts', () => { ]; authMethodCombinationsToBeTested.forEach((authOptions) => { - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); authOptions.forEach((authMethod) => { - authenticationMethodRegistery.registerAuthenticationMethod(authMethod); + authenticationMethodRegistry.registerAuthenticationMethod(authMethod); }); - expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe(authOptions[0].name); + expect(getDefaultAuthMethod(authenticationMethodRegistry)?.name).toBe(authOptions[0].name); }); }); - test('default auth type is NoAuth when no auth options registered in authenticationMethodRegistery, this should not happen in real customer scenario for MD', () => { - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - expect(getDefaultAuthMethod(authenticationMethodRegistery)?.name).toBe(AuthType.NoAuth); + test('default auth type is NoAuth when no auth options registered in authenticationMethodRegistry, this should not happen in real customer scenario for MD', () => { + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + expect(getDefaultAuthMethod(authenticationMethodRegistry)?.name).toBe(AuthType.NoAuth); }); }); @@ -303,13 +303,13 @@ describe('DataSourceManagement: Utils.ts', () => { passWordRegistered: 'some filled in password from registed auth credential form', }; - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const registedAuthTypeCredentials = extractRegisteredAuthTypeCredentials( mockedCredentialState, authTypeToBeTested, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(deepEqual(registedAuthTypeCredentials, expectExtractedAuthCredentials)); @@ -331,13 +331,13 @@ describe('DataSourceManagement: Utils.ts', () => { passWord: 'some password', } as { [key: string]: string }; - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const registedAuthTypeCredentials = extractRegisteredAuthTypeCredentials( mockedCredentialState, authTypeToBeTested, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(deepEqual(registedAuthTypeCredentials, {})); @@ -369,13 +369,13 @@ describe('DataSourceManagement: Utils.ts', () => { passWordRegistered: '', }; - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const registedAuthTypeCredentials = extractRegisteredAuthTypeCredentials( mockedCredentialState, authTypeToBeTested, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(deepEqual(registedAuthTypeCredentials, expectExtractedAuthCredentials)); @@ -401,13 +401,13 @@ describe('DataSourceManagement: Utils.ts', () => { registeredField: 'some value', }; - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const registedAuthTypeCredentials = extractRegisteredAuthTypeCredentials( mockedCredentialState, authTypeToBeTested, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(deepEqual(registedAuthTypeCredentials, expectExtractedAuthCredentials)); @@ -435,13 +435,13 @@ describe('DataSourceManagement: Utils.ts', () => { registeredField: 'some other values', }; - const authenticationMethodRegistery = new AuthenticationMethodRegistery(); - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + const authenticationMethodRegistry = new AuthenticationMethodRegistry(); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const registedAuthTypeCredentials = extractRegisteredAuthTypeCredentials( mockedCredentialState, authTypeToBeTested, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(deepEqual(registedAuthTypeCredentials, expectExtractedAuthCredentials)); diff --git a/src/plugins/data_source_management/public/components/utils.ts b/src/plugins/data_source_management/public/components/utils.ts index 10ce2bb6bf4..d7d6e94265e 100644 --- a/src/plugins/data_source_management/public/components/utils.ts +++ b/src/plugins/data_source_management/public/components/utils.ts @@ -10,7 +10,7 @@ import { defaultAuthType, noAuthCredentialAuthMethod, } from '../types'; -import { AuthenticationMethodRegistery } from '../auth_registry'; +import { AuthenticationMethodRegistry } from '../auth_registry'; export async function getDataSources(savedObjectsClient: SavedObjectsClientContract) { return savedObjectsClient @@ -150,17 +150,17 @@ export const isValidUrl = (endpoint: string) => { }; export const getDefaultAuthMethod = ( - authenticationMethodRegistery: AuthenticationMethodRegistery + authenticationMethodRegistry: AuthenticationMethodRegistry ) => { - const registeredAuthMethods = authenticationMethodRegistery.getAllAuthenticationMethods(); + const registeredAuthMethods = authenticationMethodRegistry.getAllAuthenticationMethods(); const defaultAuthMethod = registeredAuthMethods.length > 0 - ? authenticationMethodRegistery.getAuthenticationMethod(registeredAuthMethods[0].name) + ? authenticationMethodRegistry.getAuthenticationMethod(registeredAuthMethods[0].name) : noAuthCredentialAuthMethod; const initialSelectedAuthMethod = - authenticationMethodRegistery.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; + authenticationMethodRegistry.getAuthenticationMethod(defaultAuthType) ?? defaultAuthMethod; return initialSelectedAuthMethod; }; @@ -168,15 +168,15 @@ export const getDefaultAuthMethod = ( export const extractRegisteredAuthTypeCredentials = ( currentCredentialState: { [key: string]: string }, authType: string, - authenticationMethodRegistery: AuthenticationMethodRegistery + authenticationMethodRegistry: AuthenticationMethodRegistry ) => { const registeredCredentials = {} as { [key: string]: string }; const registeredCredentialField = - authenticationMethodRegistery.getAuthenticationMethod(authType)?.credentialFormField ?? {}; + authenticationMethodRegistry.getAuthenticationMethod(authType)?.credentialFormField ?? {}; - Object.keys(registeredCredentialField).forEach((credentialFiled) => { - registeredCredentials[credentialFiled] = - currentCredentialState[credentialFiled] ?? registeredCredentialField[credentialFiled]; + Object.keys(registeredCredentialField).forEach((credentialField) => { + registeredCredentials[credentialField] = + currentCredentialState[credentialField] ?? registeredCredentialField[credentialField]; }); return registeredCredentials; diff --git a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts index 1eaaea0f567..d0ef842ad4f 100644 --- a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts +++ b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts @@ -8,11 +8,11 @@ import { CreateDataSourceState } from '../create_data_source_wizard/components/c import { EditDataSourceState } from '../edit_data_source/components/edit_form/edit_data_source_form'; import { defaultValidation, performDataSourceFormValidation } from './datasource_form_validation'; import { mockDataSourceAttributesWithAuth } from '../../mocks'; -import { AuthenticationMethod, AuthenticationMethodRegistery } from '../../auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistry } from '../../auth_registry'; describe('DataSourceManagement: Form Validation', () => { describe('validate create/edit datasource', () => { - let authenticationMethodRegistery = new AuthenticationMethodRegistery(); + let authenticationMethodRegistry = new AuthenticationMethodRegistry(); let form: CreateDataSourceState | EditDataSourceState = { formErrorsByField: { ...defaultValidation }, title: '', @@ -27,7 +27,7 @@ describe('DataSourceManagement: Form Validation', () => { }, }; test('should fail validation when title is empty', () => { - const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistery); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); expect(result).toBe(false); }); test('should fail validation on duplicate title', () => { @@ -36,31 +36,31 @@ describe('DataSourceManagement: Form Validation', () => { form, ['oldTitle', 'test'], 'oldTitle', - authenticationMethodRegistery + authenticationMethodRegistry ); expect(result).toBe(false); }); test('should fail validation when endpoint is not valid', () => { form.endpoint = mockDataSourceAttributesWithAuth.endpoint; - const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistery); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); expect(result).toBe(false); }); test('should fail validation when username is empty', () => { form.endpoint = 'test'; - const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistery); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); expect(result).toBe(false); }); test('should fail validation when password is empty', () => { form.auth.credentials.username = 'test'; form.auth.credentials.password = ''; - const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistery); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); expect(result).toBe(false); }); test('should NOT fail validation on empty username/password when No Auth is selected', () => { form.auth.type = AuthType.NoAuth; form.title = 'test'; form.endpoint = mockDataSourceAttributesWithAuth.endpoint; - const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistery); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); expect(result).toBe(true); }); test('should NOT fail validation on all fields', () => { @@ -69,12 +69,12 @@ describe('DataSourceManagement: Form Validation', () => { form, [mockDataSourceAttributesWithAuth.title], mockDataSourceAttributesWithAuth.title, - authenticationMethodRegistery + authenticationMethodRegistry ); expect(result).toBe(true); }); test('should NOT fail validation when registered auth type is selected and related credential field not empty', () => { - authenticationMethodRegistery = new AuthenticationMethodRegistery(); + authenticationMethodRegistry = new AuthenticationMethodRegistry(); const authMethodToBeTested = { name: 'Some Auth Type', credentialSourceOption: { @@ -88,7 +88,7 @@ describe('DataSourceManagement: Form Validation', () => { }, } as AuthenticationMethod; - authenticationMethodRegistery.registerAuthenticationMethod(authMethodToBeTested); + authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested); const formWithRegisteredAuth: CreateDataSourceState | EditDataSourceState = { formErrorsByField: { ...defaultValidation }, @@ -107,7 +107,7 @@ describe('DataSourceManagement: Form Validation', () => { formWithRegisteredAuth, [], '', - authenticationMethodRegistery + authenticationMethodRegistry ); expect(result).toBe(true); }); diff --git a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts index 2ae5585e181..32c87fbee7d 100644 --- a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts +++ b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts @@ -8,7 +8,7 @@ import { extractRegisteredAuthTypeCredentials, isValidUrl } from '../utils'; import { CreateDataSourceState } from '../create_data_source_wizard/components/create_form/create_data_source_form'; import { EditDataSourceState } from '../edit_data_source/components/edit_form/edit_data_source_form'; import { AuthType } from '../../types'; -import { AuthenticationMethodRegistery } from '../../auth_registry'; +import { AuthenticationMethodRegistry } from '../../auth_registry'; export interface CreateEditDataSourceValidation { title: string[]; @@ -70,7 +70,7 @@ export const performDataSourceFormValidation = ( formValues: CreateDataSourceState | EditDataSourceState, existingDatasourceNamesList: string[], existingTitle: string, - authenticationMethodRegistery: AuthenticationMethodRegistery + authenticationMethodRegistry: AuthenticationMethodRegistry ) => { /* Title validation */ const titleValid = isTitleValid(formValues?.title, existingDatasourceNamesList, existingTitle); @@ -122,7 +122,7 @@ export const performDataSourceFormValidation = ( const registeredCredentials = extractRegisteredAuthTypeCredentials( (formValues?.auth?.credentials ?? {}) as { [key: string]: string }, formValues?.auth?.type ?? '', - authenticationMethodRegistery + authenticationMethodRegistry ); for (const credentialValue of Object.values(registeredCredentials)) { diff --git a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx index 6b421a32d2b..6487d60c934 100644 --- a/src/plugins/data_source_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_source_management/public/management_app/mount_management_section.tsx @@ -17,7 +17,7 @@ import { CreateDataSourceWizardWithRouter } from '../components/create_data_sour import { DataSourceTableWithRouter } from '../components/data_source_table'; import { DataSourceManagementContext } from '../types'; import { EditDataSourceWithRouter } from '../components/edit_data_source'; -import { AuthenticationMethodRegistery } from '../auth_registry'; +import { AuthenticationMethodRegistry } from '../auth_registry'; export interface DataSourceManagementStartDependencies { data: DataPublicPluginStart; @@ -26,7 +26,7 @@ export interface DataSourceManagementStartDependencies { export async function mountManagementSection( getStartServices: StartServicesAccessor, params: ManagementAppMountParams, - authMethodsRegistry: AuthenticationMethodRegistery + authMethodsRegistry: AuthenticationMethodRegistry ) { const [ { chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks }, @@ -42,7 +42,7 @@ export async function mountManagementSection( http, docLinks, setBreadcrumbs: params.setBreadcrumbs, - authenticationMethodRegistery: authMethodsRegistry, + authenticationMethodRegistry: authMethodsRegistry, }; ReactDOM.render( diff --git a/src/plugins/data_source_management/public/mocks.ts b/src/plugins/data_source_management/public/mocks.ts index e472860893e..90368762698 100644 --- a/src/plugins/data_source_management/public/mocks.ts +++ b/src/plugins/data_source_management/public/mocks.ts @@ -15,7 +15,7 @@ import { } from './plugin'; import { managementPluginMock } from '../../management/public/mocks'; import { mockManagementPlugin as indexPatternManagementPluginMock } from '../../index_pattern_management/public/mocks'; -import { AuthenticationMethod, AuthenticationMethodRegistery } from './auth_registry'; +import { AuthenticationMethod, AuthenticationMethodRegistry } from './auth_registry'; /* Mock Types */ @@ -30,7 +30,7 @@ export const docLinks = { }, }; -export const authenticationMethodRegistery = new AuthenticationMethodRegistery(); +export const authenticationMethodRegistry = new AuthenticationMethodRegistry(); const createDataSourceManagementContext = () => { const { @@ -53,7 +53,7 @@ const createDataSourceManagementContext = () => { http, docLinks, setBreadcrumbs: () => {}, - authenticationMethodRegistery, + authenticationMethodRegistry, }; }; diff --git a/src/plugins/data_source_management/public/plugin.test.ts b/src/plugins/data_source_management/public/plugin.test.ts index 98615119a0c..ecad5f38922 100644 --- a/src/plugins/data_source_management/public/plugin.test.ts +++ b/src/plugins/data_source_management/public/plugin.test.ts @@ -19,7 +19,7 @@ describe('#dataSourceManagement', () => { const typeA = createAuthenticationMethod({ name: 'typeA' }); setup.registerAuthenticationMethod(createAuthenticationMethod(typeA)); const start = doStart(); - const registry = start.getAuthenticationMethodRegistery(); + const registry = start.getAuthenticationMethodRegistry(); expect(registry.getAuthenticationMethod('typeA')).toEqual(typeA); }); }); diff --git a/src/plugins/data_source_management/public/plugin.ts b/src/plugins/data_source_management/public/plugin.ts index 12cab715b20..cf53bfc2e76 100644 --- a/src/plugins/data_source_management/public/plugin.ts +++ b/src/plugins/data_source_management/public/plugin.ts @@ -14,8 +14,8 @@ import { IndexPatternManagementSetup } from '../../index_pattern_management/publ import { DataSourceColumn } from './components/data_source_column/data_source_column'; import { AuthenticationMethod, - IAuthenticationMethodRegistery, - AuthenticationMethodRegistery, + IAuthenticationMethodRegistry, + AuthenticationMethodRegistry, } from './auth_registry'; import { noAuthCredentialAuthMethod, sigV4AuthMethod, usernamePasswordAuthMethod } from './types'; import { DataSourceSelectorProps } from './components/data_source_selector/data_source_selector'; @@ -37,7 +37,7 @@ export interface DataSourceManagementPluginSetup { } export interface DataSourceManagementPluginStart { - getAuthenticationMethodRegistery: () => IAuthenticationMethodRegistery; + getAuthenticationMethodRegistry: () => IAuthenticationMethodRegistry; } const DSM_APP_ID = 'dataSources'; @@ -50,7 +50,7 @@ export class DataSourceManagementPlugin DataSourceManagementSetupDependencies > { private started = false; - private authMethodsRegistry = new AuthenticationMethodRegistery(); + private authMethodsRegistry = new AuthenticationMethodRegistry(); public setup( core: CoreSetup, @@ -111,7 +111,7 @@ export class DataSourceManagementPlugin public start(core: CoreStart) { this.started = true; return { - getAuthenticationMethodRegistery: () => this.authMethodsRegistry, + getAuthenticationMethodRegistry: () => this.authMethodsRegistry, }; } diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index 32c9a20b7f0..e76b7b4d08a 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -18,7 +18,7 @@ import { SavedObjectAttributes } from 'src/core/types'; import { i18n } from '@osd/i18n'; import { SigV4ServiceName } from '../../data_source/common/data_sources'; import { OpenSearchDashboardsReactContextValue } from '../../opensearch_dashboards_react/public'; -import { AuthenticationMethodRegistery } from './auth_registry'; +import { AuthenticationMethodRegistry } from './auth_registry'; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface DataSourceManagementPluginStart {} @@ -33,7 +33,7 @@ export interface DataSourceManagementContext { http: HttpSetup; docLinks: DocLinksStart; setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs']; - authenticationMethodRegistery: AuthenticationMethodRegistery; + authenticationMethodRegistry: AuthenticationMethodRegistry; } export interface DataSourceTableItem { From 4bfbfce129138a838ebe73a5e15f1f3bc5d36676 Mon Sep 17 00:00:00 2001 From: Xinrui Bai Date: Thu, 21 Mar 2024 18:34:26 +0000 Subject: [PATCH 2/2] Update chagefile.md Signed-off-by: Xinrui Bai --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b2abfe2c19..583e02f324a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Multiple Datasource] Add Vega support to MDS by specifying a data source name in the Vega spec ([#5975](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5975)) - [Multiple Datasource] Test connection schema validation for registered auth types ([#6109](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6109)) - [Multiple DataSource] DataSource creation and edition page improvement to better support registered auth types ([#6122](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6122)) +- [Multiple DataSource] Codebase maintenance involves updating typos and removing unused imported packages ([#6238](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6238)) - [Workspace] Consume workspace id in saved object client ([#6014](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6014)) - [Multiple Datasource] Export DataSourcePluginRequestContext at top level for plugins to use ([#6108](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6108)) - [Multiple Datasource] Expose filterfn in datasource menu component to allow filter data sources before rendering in navigation bar ([#6113](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6113))