Skip to content

Commit

Permalink
[Multiple DataSource] Codebase maintenance involves updating typos an…
Browse files Browse the repository at this point in the history
…d removing unused imported packages (#6238)

* [MD] Fix typo and remove unused imported package

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>

* Update chagefile.md

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>

---------

Signed-off-by: Xinrui Bai <xinruiba@amazon.com>
(cherry picked from commit 6c25f2d)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Mar 25, 2024
1 parent b174c91 commit a7b399d
Show file tree
Hide file tree
Showing 32 changed files with 194 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAuthenticationMethodRegistery>);
} as unknown) as jest.Mocked<IAuthenticationMethodRegistry>);

export const authenticationMethodRegisteryMock = { create };
export const authenticationMethodRegistryMock = { create };
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AuthenticationMethod>();
/**
* Register a authMethods with function to return credentials inside the registry.
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data_source/server/auth_registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*/

export {
IAuthenticationMethodRegistery,
AuthenticationMethodRegistery,
IAuthenticationMethodRegistry,
AuthenticationMethodRegistry,
} from './authentication_methods_registry';
28 changes: 14 additions & 14 deletions src/plugins/data_source/server/client/configure_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -46,7 +46,7 @@ describe('configureClient', () => {
let usernamePasswordAuthContent: UsernamePasswordTypedContent;
let sigV4AuthContent: SigV4Content;
let customApiSchemaRegistry: CustomApiSchemaRegistry;
let authenticationMethodRegistery: jest.Mocked<IAuthenticationMethodRegistery>;
let authenticationMethodRegistry: jest.Mocked<IAuthenticationMethodRegistry>;
let clientParameters: ClientParameters;

const customAuthContent = {
Expand All @@ -70,7 +70,7 @@ describe('configureClient', () => {
savedObjectsMock = savedObjectsClientMock.create();
cryptographyMock = cryptographyServiceSetupMock.create();
customApiSchemaRegistry = new CustomApiSchemaRegistry();
authenticationMethodRegistery = authenticationMethodRegisteryMock.create();
authenticationMethodRegistry = authenticationMethodRegistryMock.create();

config = {
enabled: true,
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('configureClient', () => {
};

ClientMock.mockImplementation(() => dsClient);
authenticationMethodRegistery.getAuthenticationMethod.mockImplementation(() => authMethod);
authenticationMethodRegistry.getAuthenticationMethod.mockImplementation(() => authMethod);
authRegistryCredentialProviderMock.mockReturnValue(clientParameters);
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('configureClient', () => {
});

const client = await configureClient(
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistery },
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistry },
clientPoolSetup,
config,
logger
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('configureClient', () => {
});

const client = await configureClient(
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistery },
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistry },
clientPoolSetup,
config,
logger
Expand Down Expand Up @@ -555,7 +555,7 @@ describe('configureClient', () => {
name: 'clientPoolTest',
credentialProvider: jest.fn(),
};
authenticationMethodRegistery.getAuthenticationMethod
authenticationMethodRegistry.getAuthenticationMethod
.mockReset()
.mockImplementation(() => authMethodWithClientPool);
const mockDataSourceAttr = { ...dataSourceAttr, name: 'custom_auth' };
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -622,7 +622,7 @@ describe('configureClient', () => {
});

await configureClient(
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistery },
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistry },
opensearchClientPoolSetup,
config,
logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

import { Client } from '@opensearch-project/opensearch-next';
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,
Expand All @@ -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';

/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -41,7 +41,7 @@ describe('configureLegacyClient', () => {
let configOptions: ConfigOptions;
let dataSourceAttr: DataSourceAttributes;
let sigV4AuthContent: SigV4Content;
let authenticationMethodRegistery: jest.Mocked<IAuthenticationMethodRegistery>;
let authenticationMethodRegistry: jest.Mocked<IAuthenticationMethodRegistry>;
let clientParameters: ClientParameters;

let mockOpenSearchClientInstance: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('configureLegacyClient', () => {
});
});

authenticationMethodRegistery.getAuthenticationMethod.mockImplementation(() => authMethod);
authenticationMethodRegistry.getAuthenticationMethod.mockImplementation(() => authMethod);
authRegistryCredentialProviderMock.mockReturnValue(clientParameters);
});

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -657,7 +657,7 @@ describe('configureLegacyClient', () => {
name: 'clientPoolTest',
credentialProvider: jest.fn(),
};
authenticationMethodRegistery.getAuthenticationMethod
authenticationMethodRegistry.getAuthenticationMethod
.mockReset()
.mockImplementation(() => authMethodWithClientPool);
const mockDataSourceAttr = { ...dataSourceAttr, name: 'custom_auth' };
Expand All @@ -676,15 +676,15 @@ 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,
logger
);

await configureLegacyClient(
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistery },
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistry },
callApiParams,
opensearchClientPoolSetup,
config,
Expand All @@ -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,
Expand Down Expand Up @@ -727,7 +727,7 @@ describe('configureLegacyClient', () => {
});

await configureLegacyClient(
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistery },
{ ...dataSourceClientParams, authRegistry: authenticationMethodRegistry },
callApiParams,
opensearchClientPoolSetup,
config,
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSourcePluginSetup, DataSourcePluginStart> {
Expand All @@ -40,7 +40,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
private readonly dataSourceService: DataSourceService;
private readonly config$: Observable<DataSourcePluginConfigType>;
private started = false;
private authMethodsRegistry = new AuthenticationMethodRegistery();
private authMethodsRegistry = new AuthenticationMethodRegistry();
private customApiSchemaRegistry = new CustomApiSchemaRegistry();

constructor(private initializerContext: PluginInitializerContext<DataSourcePluginConfigType>) {
Expand All @@ -64,7 +64,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc

const authRegistryPromise = core.getStartServices().then(([, , selfStart]) => {
const dataSourcePluginStart = selfStart as DataSourcePluginStart;
return dataSourcePluginStart.getAuthenticationMethodRegistery();
return dataSourcePluginStart.getAuthenticationMethodRegistry();
});

const dataSourceSavedObjectsClientWrapper = new DataSourceSavedObjectsClientWrapper(
Expand Down Expand Up @@ -162,7 +162,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
this.logger.debug('dataSource: Started');
this.started = true;
return {
getAuthenticationMethodRegistery: () => this.authMethodsRegistry,
getAuthenticationMethodRegistry: () => this.authMethodsRegistry,
getCustomApiSchemaRegistry: () => this.customApiSchemaRegistry,
};
}
Expand All @@ -176,7 +176,7 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc
cryptography: CryptographyServiceSetup,
logger: Logger,
auditTrailPromise: Promise<AuditorFactory>,
authRegistryPromise: Promise<IAuthenticationMethodRegistery>,
authRegistryPromise: Promise<IAuthenticationMethodRegistry>,
customApiSchemaRegistryPromise: Promise<CustomApiSchemaRegistry>
): IContextProvider<RequestHandler<unknown, unknown, unknown>, 'dataSource'> => {
return async (context, req) => {
Expand Down
Loading

0 comments on commit a7b399d

Please sign in to comment.