11// smithy-typescript generated code
22import {
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" ;
814import {
15+ EndpointV2 ,
916 HandlerExecutionContext ,
1017 HttpAuthOption ,
1118 HttpAuthScheme ,
19+ HttpAuthSchemeId ,
1220 HttpAuthSchemeParameters ,
1321 HttpAuthSchemeParametersProvider ,
1422 HttpAuthSchemeProvider ,
23+ Logger ,
1524} from "@smithy/types" ;
1625import { getSmithyContext , normalizeProvider } from "@smithy/util-middleware" ;
1726
27+ import { EndpointParameters } from "../endpoint/EndpointParameters" ;
28+ import { defaultEndpointResolver } from "../endpoint/endpointResolver" ;
1829import { 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
56139function 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 */
130319export 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} ;
0 commit comments