Skip to content

Commit

Permalink
Improves connection pooling support for AWSSigV4 clients in data sou…
Browse files Browse the repository at this point in the history
…rces. (#6135)

* Upgrade @opensearch/opensearch@2.6.0 which inherits AWSSigv4 to .child

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Uses client.child for aws sigv4 connection

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Import http-aws-es connector class

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Refactor client caching mechanism

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Fix UT

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Added UT for client pool

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

* Revert client pool changes from authentication method

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>

---------

Signed-off-by: Bandini Bhopi <bandinib@amazon.com>
(cherry picked from commit 09f5563)
  • Loading branch information
bandinib-amzn committed Mar 18, 2024
1 parent 7eac821 commit 5edb124
Show file tree
Hide file tree
Showing 14 changed files with 1,144 additions and 195 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"@hapi/vision": "^6.1.0",
"@hapi/wreck": "^17.1.0",
"@opensearch-project/opensearch": "^1.1.0",
"@opensearch-project/opensearch-next": "npm:@opensearch-project/opensearch@^2.3.1",
"@opensearch-project/opensearch-next": "npm:@opensearch-project/opensearch@^2.6.0",
"@osd/ace": "1.0.0",
"@osd/analytics": "1.0.0",
"@osd/apm-config-loader": "1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

import { AuthenticationMethodRegistery } from './authentication_methods_registry';
import { AuthenticationMethod } from '../../server/types';
import { AuthType } from '../../common/data_sources';

const createAuthenticationMethod = (
authMethod: Partial<AuthenticationMethod>
): AuthenticationMethod => ({
name: 'unknown',
authType: AuthType.NoAuth,
credentialProvider: jest.fn(),
...authMethod,
});
Expand Down Expand Up @@ -61,14 +59,14 @@ describe('AuthenticationMethodRegistery', () => {
registry.registerAuthenticationMethod(
createAuthenticationMethod({
name: 'typeA',
authType: AuthType.NoAuth,
credentialProvider: jest.fn(),
})
);

const typeA = registry.getAuthenticationMethod('typeA')!;

expect(() => {
typeA.authType = AuthType.SigV4;
typeA.credentialProvider = jest.fn();
}).toThrow();
expect(() => {
typeA.name = 'foo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { deepFreeze } from '@osd/std';
import { AuthenticationMethod } from '../../server/types';
import { AuthType } from '../../common/data_sources';

export type IAuthenticationMethodRegistery = Omit<
AuthenticationMethodRegistery,
Expand All @@ -18,6 +19,15 @@ export class AuthenticationMethodRegistery {
* Authentication Method can only be registered once. subsequent calls with the same method name will throw an error.
*/
public registerAuthenticationMethod(method: AuthenticationMethod) {
if (
method.name === AuthType.NoAuth ||
method.name === AuthType.UsernamePasswordType ||
method.name === AuthType.SigV4
) {
throw new Error(

Check warning on line 27 in src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts#L27

Added line #L27 was not covered by tests
`Must not be no_auth or username_password or sigv4 for registered auth types`
);
}
if (this.authMethods.has(method.name)) {
throw new Error(`Authentication method '${method.name}' is already registered`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,3 @@ export const authRegistryCredentialProviderMock = jest.fn();
jest.doMock('../util/credential_provider', () => ({
authRegistryCredentialProvider: authRegistryCredentialProviderMock,
}));

export const CredentialsMock = jest.fn();
jest.doMock('aws-sdk', () => {
const actual = jest.requireActual('aws-sdk');
return {
...actual,
Credentials: CredentialsMock,
};
});
Loading

0 comments on commit 5edb124

Please sign in to comment.