Skip to content

chore(clients): convert second argument of resolve to options #2523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clients/client-dynamodb/DynamoDBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ export class DynamoDBClient extends __Client<
let _config_4 = resolveHostHeaderConfig(_config_3);
let _config_5 = resolveAwsAuthConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, DescribeEndpointsCommand);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, {
endpointDiscoveryCommandCtor: DescribeEndpointsCommand,
});
super(_config_7);
this.config = _config_7;
this.middlewareStack.use(getRetryPlugin(this.config));
Expand Down
2 changes: 1 addition & 1 deletion clients/client-sts/STSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class STSClient extends __Client<
let _config_2 = resolveEndpointsConfig(_config_1);
let _config_3 = resolveRetryConfig(_config_2);
let _config_4 = resolveHostHeaderConfig(_config_3);
let _config_5 = resolveStsAuthConfig(_config_4, STSClient);
let _config_5 = resolveStsAuthConfig(_config_4, { stsClientCtor: STSClient });
let _config_6 = resolveUserAgentConfig(_config_5);
super(_config_6);
this.config = _config_6;
Expand Down
4 changes: 3 additions & 1 deletion clients/client-timestream-query/TimestreamQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ export class TimestreamQueryClient extends __Client<
let _config_4 = resolveHostHeaderConfig(_config_3);
let _config_5 = resolveAwsAuthConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, DescribeEndpointsCommand);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, {
endpointDiscoveryCommandCtor: DescribeEndpointsCommand,
});
super(_config_7);
this.config = _config_7;
this.middlewareStack.use(getRetryPlugin(this.config));
Expand Down
4 changes: 3 additions & 1 deletion clients/client-timestream-write/TimestreamWriteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ export class TimestreamWriteClient extends __Client<
let _config_4 = resolveHostHeaderConfig(_config_3);
let _config_5 = resolveAwsAuthConfig(_config_4);
let _config_6 = resolveUserAgentConfig(_config_5);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, DescribeEndpointsCommand);
let _config_7 = resolveEndpointDiscoveryConfig(_config_6, {
endpointDiscoveryCommandCtor: DescribeEndpointsCommand,
});
super(_config_7);
this.config = _config_7;
this.middlewareStack.use(getRetryPlugin(this.config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ && isAwsService(s)
.withConventions(AwsDependency.STS_MIDDLEWARE.dependency,
"StsAuth", HAS_CONFIG)
.additionalResolveFunctionParamsSupplier((m, s, o) -> new HashMap<String, Object>() {{
put("STSClient", Symbol.builder().name("STSClient").build());
put("stsClientCtor", Symbol.builder().name("STSClient").build());
}})
.servicePredicate((m, s) -> testServiceId(s, "STS"))
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public List<RuntimeClientPlugin> getClientPlugins() {
"EndpointDiscovery", RuntimeClientPlugin.Convention.HAS_CONFIG)
// ToDo: The Endpoint Discovery Command Name needs to be read from ClientEndpointDiscoveryTrait.
.additionalResolveFunctionParamsSupplier((m, s, o) -> new HashMap<String, Object>() {{
put("DescribeEndpointsCommand", Symbol.builder().name("DescribeEndpointsCommand").build());
put("endpointDiscoveryCommandCtor",
Symbol.builder().name("DescribeEndpointsCommand").build());
}})
.servicePredicate((m, s) -> hasClientEndpointDiscovery(s))
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
});

it("assigns endpointDiscoveryCommandCtor in resolvedConfig", () => {
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, endpointDiscoveryCommandCtor);
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
expect(resolvedConfig.endpointDiscoveryCommandCtor).toStrictEqual(endpointDiscoveryCommandCtor);
});

Expand All @@ -29,13 +29,13 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
...mockInput,
endpointCacheSize,
},
endpointDiscoveryCommandCtor
{ endpointDiscoveryCommandCtor }
);
expect(EndpointCache).toBeCalledWith(endpointCacheSize);
});

it("creates cache of size 1000 if endpointCacheSize not passed", () => {
resolveEndpointDiscoveryConfig(mockInput, endpointDiscoveryCommandCtor);
resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
expect(EndpointCache).toBeCalledWith(1000);
});
});
Expand All @@ -47,15 +47,15 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
...mockInput,
endpointDiscoveryEnabled,
},
endpointDiscoveryCommandCtor
{ endpointDiscoveryCommandCtor }
);
expect(resolvedConfig.endpointDiscoveryEnabled()).resolves.toBe(endpointDiscoveryEnabled);
expect(mockInput.endpointDiscoveryEnabledProvider).not.toHaveBeenCalled();
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(true);
});

it(`sets to endpointDiscoveryEnabledProvider if value is not passed`, () => {
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, endpointDiscoveryCommandCtor);
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
expect(resolvedConfig.endpointDiscoveryEnabled).toBe(mockInput.endpointDiscoveryEnabledProvider);
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ export interface EndpointDiscoveryResolvedConfig {
isClientEndpointDiscoveryEnabled: boolean;
}

export interface EndpointDiscoveryConfigOptions {
/**
* The constructor of the Command used for discovering endpoints.
*/
endpointDiscoveryCommandCtor: new (comandConfig: any) => any;
}

export const resolveEndpointDiscoveryConfig = <T>(
input: T & PreviouslyResolved & EndpointDiscoveryInputConfig,
endpointDiscoveryCommandCtor: new (comandConfig: any) => any
{ endpointDiscoveryCommandCtor }: EndpointDiscoveryConfigOptions
): T & EndpointDiscoveryResolvedConfig => ({
...input,
endpointDiscoveryCommandCtor,
Expand Down
14 changes: 10 additions & 4 deletions packages/middleware-sdk-sts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ export interface StsAuthResolvedConfig extends AwsAuthResolvedConfig {
stsClientCtor: new (clientConfig: any) => Client<any, any, any>;
}

export interface StsAuthConfigOptions {
/**
* Reference to STSClient class constructor.
*/
stsClientCtor: new (clientConfig: any) => Client<any, any, any>;
}

/**
* Set STS client constructor to `stsClientCtor` config parameter. It is used
* for role assumers for STS client internally. See `clients/client-sts/defaultStsRoleAssumers.ts`
* and `clients/client-sts/STSClient.ts`.
*/
export const resolveStsAuthConfig = <T>(
input: T & PreviouslyResolved & StsAuthInputConfig,
stsClientCtor: new (clientConfig: any) => Client<any, any, any>
): T & StsAuthResolvedConfig => {
return resolveAwsAuthConfig({
{ stsClientCtor }: StsAuthConfigOptions
): T & StsAuthResolvedConfig =>
resolveAwsAuthConfig({
...input,
stsClientCtor,
});
};