1
1
// smithy-typescript generated code
2
2
import {
3
+ AwsSdkSigV4AAuthInputConfig ,
4
+ AwsSdkSigV4AAuthResolvedConfig ,
5
+ AwsSdkSigV4APreviouslyResolved ,
3
6
AwsSdkSigV4AuthInputConfig ,
4
7
AwsSdkSigV4AuthResolvedConfig ,
5
8
AwsSdkSigV4PreviouslyResolved ,
9
+ resolveAwsSdkSigV4AConfig ,
6
10
resolveAwsSdkSigV4Config ,
7
11
} from "@aws-sdk/core" ;
12
+ import { signatureV4CrtContainer } from "@aws-sdk/signature-v4-multi-region" ;
13
+ import { EndpointParameterInstructions , resolveParams } from "@smithy/middleware-endpoint" ;
8
14
import {
15
+ EndpointV2 ,
9
16
HandlerExecutionContext ,
10
17
HttpAuthOption ,
11
18
HttpAuthScheme ,
19
+ HttpAuthSchemeId ,
12
20
HttpAuthSchemeParameters ,
13
21
HttpAuthSchemeParametersProvider ,
14
22
HttpAuthSchemeProvider ,
23
+ Logger ,
15
24
} from "@smithy/types" ;
16
25
import { getSmithyContext , normalizeProvider } from "@smithy/util-middleware" ;
17
26
27
+ import { EndpointParameters } from "../endpoint/EndpointParameters" ;
28
+ import { defaultEndpointResolver } from "../endpoint/endpointResolver" ;
18
29
import { SESv2ClientConfig , SESv2ClientResolvedConfig } from "../SESv2Client" ;
19
30
20
31
/**
21
32
* @internal
22
33
*/
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 {
24
42
region ?: string ;
25
43
}
26
44
@@ -38,11 +56,71 @@ export interface SESv2HttpAuthSchemeParametersProvider
38
56
/**
39
57
* @internal
40
58
*/
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 (
42
120
config : SESv2ClientResolvedConfig ,
43
121
context : HandlerExecutionContext ,
44
122
input : object
45
- ) : Promise < SESv2HttpAuthSchemeParameters > => {
123
+ ) : Promise < _SESv2HttpAuthSchemeParameters > => {
46
124
return {
47
125
operation : getSmithyContext ( context ) . operation as string ,
48
126
region :
@@ -52,6 +130,11 @@ export const defaultSESv2HttpAuthSchemeParametersProvider = async (
52
130
} ) ( ) ,
53
131
} ;
54
132
} ;
133
+ /**
134
+ * @internal
135
+ */
136
+ export const defaultSESv2HttpAuthSchemeParametersProvider : SESv2HttpAuthSchemeParametersProvider =
137
+ createEndpointRuleSetHttpAuthSchemeParametersProvider ( _defaultSESv2HttpAuthSchemeParametersProvider ) ;
55
138
56
139
function createAwsAuthSigv4HttpAuthOption ( authParameters : SESv2HttpAuthSchemeParameters ) : HttpAuthOption {
57
140
return {
@@ -72,6 +155,30 @@ function createAwsAuthSigv4HttpAuthOption(authParameters: SESv2HttpAuthSchemePar
72
155
} ;
73
156
}
74
157
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
+
75
182
/**
76
183
* @internal
77
184
*/
@@ -80,20 +187,102 @@ export interface SESv2HttpAuthSchemeProvider extends HttpAuthSchemeProvider<SESv
80
187
/**
81
188
* @internal
82
189
*/
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 ) => {
84
264
const options : HttpAuthOption [ ] = [ ] ;
85
265
switch ( authParameters . operation ) {
86
266
default : {
87
267
options . push ( createAwsAuthSigv4HttpAuthOption ( authParameters ) ) ;
268
+ options . push ( createAwsAuthSigv4aHttpAuthOption ( authParameters ) ) ;
88
269
}
89
270
}
90
271
return options ;
91
272
} ;
273
+ /**
274
+ * @internal
275
+ */
276
+ export const defaultSESv2HttpAuthSchemeProvider : SESv2HttpAuthSchemeProvider =
277
+ createEndpointRuleSetHttpAuthSchemeProvider ( defaultEndpointResolver , _defaultSESv2HttpAuthSchemeProvider , {
278
+ "aws.auth#sigv4" : createAwsAuthSigv4HttpAuthOption ,
279
+ "aws.auth#sigv4a" : createAwsAuthSigv4aHttpAuthOption ,
280
+ } ) ;
92
281
93
282
/**
94
283
* @internal
95
284
*/
96
- export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig {
285
+ export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig , AwsSdkSigV4AAuthInputConfig {
97
286
/**
98
287
* Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
99
288
* @internal
@@ -110,7 +299,7 @@ export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig {
110
299
/**
111
300
* @internal
112
301
*/
113
- export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig {
302
+ export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig , AwsSdkSigV4AAuthResolvedConfig {
114
303
/**
115
304
* Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
116
305
* @internal
@@ -128,10 +317,11 @@ export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedCon
128
317
* @internal
129
318
*/
130
319
export const resolveHttpAuthSchemeConfig = < T > (
131
- config : T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved
320
+ config : T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved & AwsSdkSigV4APreviouslyResolved
132
321
) : T & HttpAuthSchemeResolvedConfig => {
133
322
const config_0 = resolveAwsSdkSigV4Config ( config ) ;
323
+ const config_1 = resolveAwsSdkSigV4AConfig ( config_0 ) ;
134
324
return {
135
- ...config_0 ,
325
+ ...config_1 ,
136
326
} as T & HttpAuthSchemeResolvedConfig ;
137
327
} ;
0 commit comments