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. (opensearch-project#6135) (opensearch-project#6176)

* Upgrade @opensearch/[email protected] which inherits AWSSigv4 to .child

Signed-off-by: Bandini Bhopi <[email protected]>

* Uses client.child for aws sigv4 connection

Signed-off-by: Bandini Bhopi <[email protected]>

* Import http-aws-es connector class

Signed-off-by: Bandini Bhopi <[email protected]>

* Refactor client caching mechanism

Signed-off-by: Bandini Bhopi <[email protected]>

* Fix UT

Signed-off-by: Bandini Bhopi <[email protected]>

* Added UT for client pool

Signed-off-by: Bandini Bhopi <[email protected]>

* Revert client pool changes from authentication method

Signed-off-by: Bandini Bhopi <[email protected]>

---------

Signed-off-by: Bandini Bhopi <[email protected]>
(cherry picked from commit 09f5563)
  • Loading branch information
bandinib-amzn authored Mar 19, 2024
1 parent 7eac821 commit ad5370e
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(
`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 ad5370e

Please sign in to comment.