Skip to content

Commit bdfa868

Browse files
authored
chore(client-sesv2): enable sigv4a code generation in sesv2 ahead of service availability (#6719)
* chore(client-sesv2): enable sigv4a flag in sesv2 ahead of service availability * chore(client-sesv2): update lockfile
1 parent 331273f commit bdfa868

File tree

7 files changed

+213
-11
lines changed

7 files changed

+213
-11
lines changed

clients/client-sesv2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@aws-sdk/middleware-recursion-detection": "*",
3030
"@aws-sdk/middleware-user-agent": "*",
3131
"@aws-sdk/region-config-resolver": "*",
32+
"@aws-sdk/signature-v4-multi-region": "*",
3233
"@aws-sdk/types": "*",
3334
"@aws-sdk/util-endpoints": "*",
3435
"@aws-sdk/util-user-agent-browser": "*",

clients/client-sesv2/src/SESv2Client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ export class SESv2Client extends __Client<
749749
identityProviderConfigProvider: async (config: SESv2ClientResolvedConfig) =>
750750
new DefaultIdentityProviderConfig({
751751
"aws.auth#sigv4": config.credentials,
752+
"aws.auth#sigv4a": config.credentials,
752753
}),
753754
})
754755
);

clients/client-sesv2/src/auth/httpAuthSchemeProvider.ts

Lines changed: 198 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
// smithy-typescript generated code
22
import {
3+
AwsSdkSigV4AAuthInputConfig,
4+
AwsSdkSigV4AAuthResolvedConfig,
5+
AwsSdkSigV4APreviouslyResolved,
36
AwsSdkSigV4AuthInputConfig,
47
AwsSdkSigV4AuthResolvedConfig,
58
AwsSdkSigV4PreviouslyResolved,
9+
resolveAwsSdkSigV4AConfig,
610
resolveAwsSdkSigV4Config,
711
} from "@aws-sdk/core";
12+
import { signatureV4CrtContainer } from "@aws-sdk/signature-v4-multi-region";
13+
import { EndpointParameterInstructions, resolveParams } from "@smithy/middleware-endpoint";
814
import {
15+
EndpointV2,
916
HandlerExecutionContext,
1017
HttpAuthOption,
1118
HttpAuthScheme,
19+
HttpAuthSchemeId,
1220
HttpAuthSchemeParameters,
1321
HttpAuthSchemeParametersProvider,
1422
HttpAuthSchemeProvider,
23+
Logger,
1524
} from "@smithy/types";
1625
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware";
1726

27+
import { EndpointParameters } from "../endpoint/EndpointParameters";
28+
import { defaultEndpointResolver } from "../endpoint/endpointResolver";
1829
import { SESv2ClientConfig, SESv2ClientResolvedConfig } from "../SESv2Client";
1930

2031
/**
2132
* @internal
2233
*/
23-
export interface SESv2HttpAuthSchemeParameters extends HttpAuthSchemeParameters {
34+
interface _SESv2HttpAuthSchemeParameters extends HttpAuthSchemeParameters {
35+
region?: string;
36+
}
37+
38+
/**
39+
* @internal
40+
*/
41+
export interface SESv2HttpAuthSchemeParameters extends _SESv2HttpAuthSchemeParameters, EndpointParameters {
2442
region?: string;
2543
}
2644

@@ -38,11 +56,71 @@ export interface SESv2HttpAuthSchemeParametersProvider
3856
/**
3957
* @internal
4058
*/
41-
export const defaultSESv2HttpAuthSchemeParametersProvider = async (
59+
interface EndpointRuleSetSmithyContext {
60+
commandInstance?: {
61+
constructor?: {
62+
getEndpointParameterInstructions(): EndpointParameterInstructions;
63+
};
64+
};
65+
}
66+
/**
67+
* @internal
68+
*/
69+
interface EndpointRuleSetHttpAuthSchemeParametersProvider<
70+
TConfig extends object,
71+
TContext extends HandlerExecutionContext,
72+
TParameters extends HttpAuthSchemeParameters & EndpointParameters,
73+
TInput extends object
74+
> extends HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput> {}
75+
/**
76+
* @internal
77+
*/
78+
const createEndpointRuleSetHttpAuthSchemeParametersProvider =
79+
<
80+
TConfig extends object,
81+
TContext extends HandlerExecutionContext,
82+
THttpAuthSchemeParameters extends HttpAuthSchemeParameters,
83+
TEndpointParameters extends EndpointParameters,
84+
TParameters extends THttpAuthSchemeParameters & TEndpointParameters,
85+
TInput extends object
86+
>(
87+
defaultHttpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<
88+
TConfig,
89+
TContext,
90+
THttpAuthSchemeParameters,
91+
TInput
92+
>
93+
): EndpointRuleSetHttpAuthSchemeParametersProvider<
94+
TConfig,
95+
TContext,
96+
THttpAuthSchemeParameters & TEndpointParameters,
97+
TInput
98+
> =>
99+
async (config: TConfig, context: TContext, input: TInput): Promise<TParameters> => {
100+
if (!input) {
101+
throw new Error(`Could not find \`input\` for \`defaultEndpointRuleSetHttpAuthSchemeParametersProvider\``);
102+
}
103+
const defaultParameters = await defaultHttpAuthSchemeParametersProvider(config, context, input);
104+
const instructionsFn = (getSmithyContext(context) as EndpointRuleSetSmithyContext)?.commandInstance?.constructor
105+
?.getEndpointParameterInstructions;
106+
if (!instructionsFn) {
107+
throw new Error(`getEndpointParameterInstructions() is not defined on \`${context.commandName!}\``);
108+
}
109+
const endpointParameters = await resolveParams(
110+
input as Record<string, unknown>,
111+
{ getEndpointParameterInstructions: instructionsFn! },
112+
config as Record<string, unknown>
113+
);
114+
return Object.assign(defaultParameters, endpointParameters) as TParameters;
115+
};
116+
/**
117+
* @internal
118+
*/
119+
const _defaultSESv2HttpAuthSchemeParametersProvider = async (
42120
config: SESv2ClientResolvedConfig,
43121
context: HandlerExecutionContext,
44122
input: object
45-
): Promise<SESv2HttpAuthSchemeParameters> => {
123+
): Promise<_SESv2HttpAuthSchemeParameters> => {
46124
return {
47125
operation: getSmithyContext(context).operation as string,
48126
region:
@@ -52,6 +130,11 @@ export const defaultSESv2HttpAuthSchemeParametersProvider = async (
52130
})(),
53131
};
54132
};
133+
/**
134+
* @internal
135+
*/
136+
export const defaultSESv2HttpAuthSchemeParametersProvider: SESv2HttpAuthSchemeParametersProvider =
137+
createEndpointRuleSetHttpAuthSchemeParametersProvider(_defaultSESv2HttpAuthSchemeParametersProvider);
55138

56139
function createAwsAuthSigv4HttpAuthOption(authParameters: SESv2HttpAuthSchemeParameters): HttpAuthOption {
57140
return {
@@ -72,6 +155,30 @@ function createAwsAuthSigv4HttpAuthOption(authParameters: SESv2HttpAuthSchemePar
72155
};
73156
}
74157

158+
function createAwsAuthSigv4aHttpAuthOption(authParameters: SESv2HttpAuthSchemeParameters): HttpAuthOption {
159+
return {
160+
schemeId: "aws.auth#sigv4a",
161+
signingProperties: {
162+
name: "ses",
163+
region: authParameters.region,
164+
},
165+
propertiesExtractor: (config: Partial<SESv2ClientConfig>, context) => ({
166+
/**
167+
* @internal
168+
*/
169+
signingProperties: {
170+
config,
171+
context,
172+
},
173+
}),
174+
};
175+
}
176+
177+
/**
178+
* @internal
179+
*/
180+
interface _SESv2HttpAuthSchemeProvider extends HttpAuthSchemeProvider<SESv2HttpAuthSchemeParameters> {}
181+
75182
/**
76183
* @internal
77184
*/
@@ -80,20 +187,102 @@ export interface SESv2HttpAuthSchemeProvider extends HttpAuthSchemeProvider<SESv
80187
/**
81188
* @internal
82189
*/
83-
export const defaultSESv2HttpAuthSchemeProvider: SESv2HttpAuthSchemeProvider = (authParameters) => {
190+
interface EndpointRuleSetHttpAuthSchemeProvider<
191+
EndpointParametersT extends EndpointParameters,
192+
HttpAuthSchemeParametersT extends HttpAuthSchemeParameters
193+
> extends HttpAuthSchemeProvider<EndpointParametersT & HttpAuthSchemeParametersT> {}
194+
/**
195+
* @internal
196+
*/
197+
interface DefaultEndpointResolver<EndpointParametersT extends EndpointParameters> {
198+
(params: EndpointParametersT, context?: { logger?: Logger }): EndpointV2;
199+
}
200+
/**
201+
* @internal
202+
*/
203+
const createEndpointRuleSetHttpAuthSchemeProvider = <
204+
EndpointParametersT extends EndpointParameters,
205+
HttpAuthSchemeParametersT extends HttpAuthSchemeParameters
206+
>(
207+
defaultEndpointResolver: DefaultEndpointResolver<EndpointParametersT>,
208+
defaultHttpAuthSchemeResolver: HttpAuthSchemeProvider<HttpAuthSchemeParametersT>,
209+
createHttpAuthOptionFunctions: Record<
210+
HttpAuthSchemeId,
211+
(authParameters: EndpointParametersT & HttpAuthSchemeParametersT) => HttpAuthOption
212+
>
213+
): EndpointRuleSetHttpAuthSchemeProvider<EndpointParametersT, HttpAuthSchemeParametersT> => {
214+
const endpointRuleSetHttpAuthSchemeProvider: EndpointRuleSetHttpAuthSchemeProvider<
215+
EndpointParametersT,
216+
HttpAuthSchemeParametersT
217+
> = (authParameters) => {
218+
const endpoint: EndpointV2 = defaultEndpointResolver(authParameters);
219+
const authSchemes = endpoint.properties?.authSchemes;
220+
if (!authSchemes) {
221+
return defaultHttpAuthSchemeResolver(authParameters);
222+
}
223+
const options: HttpAuthOption[] = [];
224+
for (const scheme of authSchemes) {
225+
const { name: resolvedName, properties = {}, ...rest } = scheme;
226+
const name = resolvedName.toLowerCase();
227+
if (resolvedName !== name) {
228+
console.warn(`HttpAuthScheme has been normalized with lowercasing: \`${resolvedName}\` to \`${name}\``);
229+
}
230+
let schemeId;
231+
if (name === "sigv4a") {
232+
schemeId = "aws.auth#sigv4a";
233+
const sigv4Present = authSchemes.find((s) => {
234+
const name = s.name.toLowerCase();
235+
return name !== "sigv4a" && name.startsWith("sigv4");
236+
});
237+
if (!signatureV4CrtContainer.CrtSignerV4 && sigv4Present) {
238+
// sigv4a -> sigv4 fallback.
239+
continue;
240+
}
241+
} else if (name.startsWith("sigv4")) {
242+
schemeId = "aws.auth#sigv4";
243+
} else {
244+
throw new Error(`Unknown HttpAuthScheme found in \`@smithy.rules#endpointRuleSet\`: \`${name}\``);
245+
}
246+
const createOption = createHttpAuthOptionFunctions[schemeId];
247+
if (!createOption) {
248+
throw new Error(`Could not find HttpAuthOption create function for \`${schemeId}\``);
249+
}
250+
const option = createOption(authParameters);
251+
option.schemeId = schemeId;
252+
option.signingProperties = { ...(option.signingProperties || {}), ...rest, ...properties };
253+
options.push(option);
254+
}
255+
return options;
256+
};
257+
258+
return endpointRuleSetHttpAuthSchemeProvider;
259+
};
260+
/**
261+
* @internal
262+
*/
263+
const _defaultSESv2HttpAuthSchemeProvider: _SESv2HttpAuthSchemeProvider = (authParameters) => {
84264
const options: HttpAuthOption[] = [];
85265
switch (authParameters.operation) {
86266
default: {
87267
options.push(createAwsAuthSigv4HttpAuthOption(authParameters));
268+
options.push(createAwsAuthSigv4aHttpAuthOption(authParameters));
88269
}
89270
}
90271
return options;
91272
};
273+
/**
274+
* @internal
275+
*/
276+
export const defaultSESv2HttpAuthSchemeProvider: SESv2HttpAuthSchemeProvider =
277+
createEndpointRuleSetHttpAuthSchemeProvider(defaultEndpointResolver, _defaultSESv2HttpAuthSchemeProvider, {
278+
"aws.auth#sigv4": createAwsAuthSigv4HttpAuthOption,
279+
"aws.auth#sigv4a": createAwsAuthSigv4aHttpAuthOption,
280+
});
92281

93282
/**
94283
* @internal
95284
*/
96-
export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig {
285+
export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig, AwsSdkSigV4AAuthInputConfig {
97286
/**
98287
* Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
99288
* @internal
@@ -110,7 +299,7 @@ export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig {
110299
/**
111300
* @internal
112301
*/
113-
export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig {
302+
export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig, AwsSdkSigV4AAuthResolvedConfig {
114303
/**
115304
* Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
116305
* @internal
@@ -128,10 +317,11 @@ export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedCon
128317
* @internal
129318
*/
130319
export const resolveHttpAuthSchemeConfig = <T>(
131-
config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved
320+
config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved & AwsSdkSigV4APreviouslyResolved
132321
): T & HttpAuthSchemeResolvedConfig => {
133322
const config_0 = resolveAwsSdkSigV4Config(config);
323+
const config_1 = resolveAwsSdkSigV4AConfig(config_0);
134324
return {
135-
...config_0,
325+
...config_1,
136326
} as T & HttpAuthSchemeResolvedConfig;
137327
};

clients/client-sesv2/src/runtimeConfig.shared.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// smithy-typescript generated code
2-
import { AwsSdkSigV4Signer } from "@aws-sdk/core";
2+
import { AwsSdkSigV4ASigner, AwsSdkSigV4Signer } from "@aws-sdk/core";
3+
import { SignatureV4MultiRegion } from "@aws-sdk/signature-v4-multi-region";
34
import { NoOpLogger } from "@smithy/smithy-client";
45
import { IdentityProviderConfig } from "@smithy/types";
56
import { parseUrl } from "@smithy/url-parser";
@@ -28,9 +29,15 @@ export const getRuntimeConfig = (config: SESv2ClientConfig) => {
2829
identityProvider: (ipc: IdentityProviderConfig) => ipc.getIdentityProvider("aws.auth#sigv4"),
2930
signer: new AwsSdkSigV4Signer(),
3031
},
32+
{
33+
schemeId: "aws.auth#sigv4a",
34+
identityProvider: (ipc: IdentityProviderConfig) => ipc.getIdentityProvider("aws.auth#sigv4a"),
35+
signer: new AwsSdkSigV4ASigner(),
36+
},
3137
],
3238
logger: config?.logger ?? new NoOpLogger(),
3339
serviceId: config?.serviceId ?? "SESv2",
40+
signerConstructor: config?.signerConstructor ?? SignatureV4MultiRegion,
3441
urlParser: config?.urlParser ?? parseUrl,
3542
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
3643
utf8Encoder: config?.utf8Encoder ?? toUtf8,

clients/client-sesv2/src/runtimeConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @ts-ignore: package.json will be imported from dist folders
33
import packageInfo from "../package.json"; // eslint-disable-line
44

5-
import { emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
5+
import { NODE_SIGV4A_CONFIG_OPTIONS, emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
66
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
77
import { NODE_APP_ID_CONFIG_OPTIONS, createDefaultUserAgentProvider } from "@aws-sdk/util-user-agent-node";
88
import {
@@ -52,6 +52,7 @@ export const getRuntimeConfig = (config: SESv2ClientConfig) => {
5252
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
5353
}),
5454
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
55+
sigv4aSigningRegionSet: config?.sigv4aSigningRegionSet ?? loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS),
5556
streamCollector: config?.streamCollector ?? streamCollector,
5657
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
5758
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS),

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsTraitsUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public final class AwsTraitsUtils {
3838
private static final Set<ShapeId> ENDPOINT_RULESET_HTTP_AUTH_SCHEME_SERVICES = Set.of(
3939
ShapeId.from("com.amazonaws.s3#AmazonS3"),
4040
ShapeId.from("com.amazonaws.eventbridge#AWSEvents"),
41-
ShapeId.from("com.amazonaws.cloudfrontkeyvaluestore#CloudFrontKeyValueStore")
41+
ShapeId.from("com.amazonaws.cloudfrontkeyvaluestore#CloudFrontKeyValueStore"),
42+
ShapeId.from("com.amazonaws.sesv2#SimpleEmailService_v2")
4243
);
4344

4445
private AwsTraitsUtils() {}

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20360,6 +20360,7 @@ __metadata:
2036020360
"@aws-sdk/middleware-recursion-detection": "npm:*"
2036120361
"@aws-sdk/middleware-user-agent": "npm:*"
2036220362
"@aws-sdk/region-config-resolver": "npm:*"
20363+
"@aws-sdk/signature-v4-multi-region": "npm:*"
2036320364
"@aws-sdk/types": "npm:*"
2036420365
"@aws-sdk/util-endpoints": "npm:*"
2036520366
"@aws-sdk/util-user-agent-browser": "npm:*"

0 commit comments

Comments
 (0)