Skip to content

Commit b3d1497

Browse files
author
Steven Yuan
authored
feat(experimentalIdentityAndAuth): release phase for SQS and DynamoDB (#5284)
* feat(experimentalIdentityAndAuth): enable `experimentalIdentityAndAuth` for SQS * feat(experimentalIdentityAndAuth): enable `experimentalIdentityAndAuth` for DynamoDB
1 parent 3ed7c81 commit b3d1497

15 files changed

+553
-51
lines changed

clients/client-dynamodb/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"@aws-sdk/middleware-host-header": "*",
2828
"@aws-sdk/middleware-logger": "*",
2929
"@aws-sdk/middleware-recursion-detection": "*",
30-
"@aws-sdk/middleware-signing": "*",
3130
"@aws-sdk/middleware-user-agent": "*",
3231
"@aws-sdk/region-config-resolver": "*",
3332
"@aws-sdk/types": "*",
3433
"@aws-sdk/util-endpoints": "*",
3534
"@aws-sdk/util-user-agent-browser": "*",
3635
"@aws-sdk/util-user-agent-node": "*",
3736
"@smithy/config-resolver": "^2.0.21",
37+
"@smithy/core": "^1.2.0",
3838
"@smithy/fetch-http-handler": "^2.3.1",
3939
"@smithy/hash-node": "^2.0.17",
4040
"@smithy/invalid-dependency": "^2.0.15",
@@ -55,6 +55,7 @@
5555
"@smithy/util-defaults-mode-browser": "^2.0.22",
5656
"@smithy/util-defaults-mode-node": "^2.0.29",
5757
"@smithy/util-endpoints": "^1.0.7",
58+
"@smithy/util-middleware": "^2.0.8",
5859
"@smithy/util-retry": "^2.0.8",
5960
"@smithy/util-utf8": "^2.0.2",
6061
"@smithy/util-waiter": "^2.0.15",

clients/client-dynamodb/src/DynamoDBClient.ts

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ import {
1212
} from "@aws-sdk/middleware-host-header";
1313
import { getLoggerPlugin } from "@aws-sdk/middleware-logger";
1414
import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection";
15-
import {
16-
AwsAuthInputConfig,
17-
AwsAuthResolvedConfig,
18-
getAwsAuthPlugin,
19-
resolveAwsAuthConfig,
20-
} from "@aws-sdk/middleware-signing";
2115
import {
2216
getUserAgentPlugin,
2317
resolveUserAgentConfig,
2418
UserAgentInputConfig,
2519
UserAgentResolvedConfig,
2620
} from "@aws-sdk/middleware-user-agent";
27-
import { Credentials as __Credentials } from "@aws-sdk/types";
2821
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
22+
import {
23+
DefaultIdentityProviderConfig,
24+
getHttpAuthSchemeEndpointRuleSetPlugin,
25+
getHttpSigningPlugin,
26+
} from "@smithy/core";
2927
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
3028
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
3129
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
@@ -37,6 +35,7 @@ import {
3735
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
3836
} from "@smithy/smithy-client";
3937
import {
38+
AwsCredentialIdentityProvider,
4039
BodyLengthCalculator as __BodyLengthCalculator,
4140
CheckOptionalClientConfig as __CheckOptionalClientConfig,
4241
ChecksumConstructor as __ChecksumConstructor,
@@ -53,6 +52,12 @@ import {
5352
UserAgent as __UserAgent,
5453
} from "@smithy/types";
5554

55+
import {
56+
defaultDynamoDBHttpAuthSchemeParametersProvider,
57+
HttpAuthSchemeInputConfig,
58+
HttpAuthSchemeResolvedConfig,
59+
resolveHttpAuthSchemeConfig,
60+
} from "./auth/httpAuthSchemeProvider";
5661
import {
5762
BatchExecuteStatementCommandInput,
5863
BatchExecuteStatementCommandOutput,
@@ -375,28 +380,22 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
375380
useFipsEndpoint?: boolean | __Provider<boolean>;
376381

377382
/**
378-
* The AWS region to which this client will send requests
379-
*/
380-
region?: string | __Provider<string>;
381-
382-
/**
383-
* Default credentials provider; Not available in browser runtime.
383+
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
384384
* @internal
385385
*/
386-
credentialDefaultProvider?: (input: any) => __Provider<__Credentials>;
386+
defaultUserAgentProvider?: Provider<__UserAgent>;
387387

388388
/**
389-
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
390-
* @internal
389+
* The AWS region to which this client will send requests
391390
*/
392-
defaultUserAgentProvider?: Provider<__UserAgent>;
391+
region?: string | __Provider<string>;
393392

394393
/**
395-
* The provider which populates default for endpointDiscoveryEnabled configuration, if it's
396-
* not passed during client creation.
394+
* Default credentials provider; Not available in browser runtime.
395+
* @deprecated
397396
* @internal
398397
*/
399-
endpointDiscoveryEnabledProvider?: __Provider<boolean | undefined>;
398+
credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider;
400399

401400
/**
402401
* Value for how many times a request will be made at most in case of retry.
@@ -424,6 +423,13 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
424423
* The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
425424
*/
426425
defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>;
426+
427+
/**
428+
* The provider which populates default for endpointDiscoveryEnabled configuration, if it's
429+
* not passed during client creation.
430+
* @internal
431+
*/
432+
endpointDiscoveryEnabledProvider?: __Provider<boolean | undefined>;
427433
}
428434

429435
/**
@@ -435,8 +441,8 @@ export type DynamoDBClientConfigType = Partial<__SmithyConfiguration<__HttpHandl
435441
EndpointInputConfig<EndpointParameters> &
436442
RetryInputConfig &
437443
HostHeaderInputConfig &
438-
AwsAuthInputConfig &
439444
UserAgentInputConfig &
445+
HttpAuthSchemeInputConfig &
440446
EndpointDiscoveryInputConfig &
441447
ClientInputEndpointParameters;
442448
/**
@@ -456,8 +462,8 @@ export type DynamoDBClientResolvedConfigType = __SmithyResolvedConfiguration<__H
456462
EndpointResolvedConfig<EndpointParameters> &
457463
RetryResolvedConfig &
458464
HostHeaderResolvedConfig &
459-
AwsAuthResolvedConfig &
460465
UserAgentResolvedConfig &
466+
HttpAuthSchemeResolvedConfig &
461467
EndpointDiscoveryResolvedConfig &
462468
ClientResolvedEndpointParameters;
463469
/**
@@ -498,15 +504,26 @@ export class DynamoDBClient extends __Client<
498504
*/
499505
readonly config: DynamoDBClientResolvedConfig;
500506

507+
private getDefaultHttpAuthSchemeParametersProvider() {
508+
return defaultDynamoDBHttpAuthSchemeParametersProvider;
509+
}
510+
511+
private getIdentityProviderConfigProvider() {
512+
return async (config: DynamoDBClientResolvedConfig) =>
513+
new DefaultIdentityProviderConfig({
514+
"aws.auth#sigv4": config.credentials,
515+
});
516+
}
517+
501518
constructor(...[configuration]: __CheckOptionalClientConfig<DynamoDBClientConfig>) {
502519
const _config_0 = __getRuntimeConfig(configuration || {});
503520
const _config_1 = resolveClientEndpointParameters(_config_0);
504521
const _config_2 = resolveRegionConfig(_config_1);
505522
const _config_3 = resolveEndpointConfig(_config_2);
506523
const _config_4 = resolveRetryConfig(_config_3);
507524
const _config_5 = resolveHostHeaderConfig(_config_4);
508-
const _config_6 = resolveAwsAuthConfig(_config_5);
509-
const _config_7 = resolveUserAgentConfig(_config_6);
525+
const _config_6 = resolveUserAgentConfig(_config_5);
526+
const _config_7 = resolveHttpAuthSchemeConfig(_config_6);
510527
const _config_8 = resolveEndpointDiscoveryConfig(_config_7, {
511528
endpointDiscoveryCommandCtor: DescribeEndpointsCommand,
512529
});
@@ -518,8 +535,14 @@ export class DynamoDBClient extends __Client<
518535
this.middlewareStack.use(getHostHeaderPlugin(this.config));
519536
this.middlewareStack.use(getLoggerPlugin(this.config));
520537
this.middlewareStack.use(getRecursionDetectionPlugin(this.config));
521-
this.middlewareStack.use(getAwsAuthPlugin(this.config));
522538
this.middlewareStack.use(getUserAgentPlugin(this.config));
539+
this.middlewareStack.use(
540+
getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
541+
httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(),
542+
identityProviderConfigProvider: this.getIdentityProviderConfigProvider(),
543+
})
544+
);
545+
this.middlewareStack.use(getHttpSigningPlugin(this.config));
523546
}
524547

525548
/**
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// smithy-typescript generated code
2+
import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types";
3+
4+
import { DynamoDBHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
5+
6+
/**
7+
* @internal
8+
*/
9+
export interface HttpAuthExtensionConfiguration {
10+
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void;
11+
httpAuthSchemes(): HttpAuthScheme[];
12+
setHttpAuthSchemeProvider(httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider): void;
13+
httpAuthSchemeProvider(): DynamoDBHttpAuthSchemeProvider;
14+
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void;
15+
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined;
16+
}
17+
18+
/**
19+
* @internal
20+
*/
21+
export type HttpAuthRuntimeConfig = Partial<{
22+
httpAuthSchemes: HttpAuthScheme[];
23+
httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider;
24+
credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
25+
}>;
26+
27+
/**
28+
* @internal
29+
*/
30+
export const getHttpAuthExtensionConfiguration = (
31+
runtimeConfig: HttpAuthRuntimeConfig
32+
): HttpAuthExtensionConfiguration => {
33+
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
34+
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!;
35+
let _credentials = runtimeConfig.credentials;
36+
return {
37+
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void {
38+
const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId);
39+
if (index === -1) {
40+
_httpAuthSchemes.push(httpAuthScheme);
41+
} else {
42+
_httpAuthSchemes.splice(index, 1, httpAuthScheme);
43+
}
44+
},
45+
httpAuthSchemes(): HttpAuthScheme[] {
46+
return _httpAuthSchemes;
47+
},
48+
setHttpAuthSchemeProvider(httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider): void {
49+
_httpAuthSchemeProvider = httpAuthSchemeProvider;
50+
},
51+
httpAuthSchemeProvider(): DynamoDBHttpAuthSchemeProvider {
52+
return _httpAuthSchemeProvider;
53+
},
54+
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void {
55+
_credentials = credentials;
56+
},
57+
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined {
58+
return _credentials;
59+
},
60+
};
61+
};
62+
63+
/**
64+
* @internal
65+
*/
66+
export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => {
67+
return {
68+
httpAuthSchemes: config.httpAuthSchemes(),
69+
httpAuthSchemeProvider: config.httpAuthSchemeProvider(),
70+
credentials: config.credentials(),
71+
};
72+
};
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// smithy-typescript generated code
2+
import {
3+
AWSSDKSigV4AuthInputConfig,
4+
AWSSDKSigV4AuthResolvedConfig,
5+
AWSSDKSigV4PreviouslyResolved,
6+
resolveAWSSDKSigV4Config,
7+
} from "@aws-sdk/core";
8+
import {
9+
HandlerExecutionContext,
10+
HttpAuthOption,
11+
HttpAuthScheme,
12+
HttpAuthSchemeParameters,
13+
HttpAuthSchemeParametersProvider,
14+
HttpAuthSchemeProvider,
15+
} from "@smithy/types";
16+
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware";
17+
18+
import { DynamoDBClientConfig, DynamoDBClientResolvedConfig } from "../DynamoDBClient";
19+
20+
/**
21+
* @internal
22+
*/
23+
export interface DynamoDBHttpAuthSchemeParameters extends HttpAuthSchemeParameters {
24+
region?: string;
25+
}
26+
27+
/**
28+
* @internal
29+
*/
30+
export interface DynamoDBHttpAuthSchemeParametersProvider
31+
extends HttpAuthSchemeParametersProvider<
32+
DynamoDBClientResolvedConfig,
33+
HandlerExecutionContext,
34+
DynamoDBHttpAuthSchemeParameters,
35+
object
36+
> {}
37+
38+
/**
39+
* @internal
40+
*/
41+
export const defaultDynamoDBHttpAuthSchemeParametersProvider = async (
42+
config: DynamoDBClientResolvedConfig,
43+
context: HandlerExecutionContext,
44+
input: object
45+
): Promise<DynamoDBHttpAuthSchemeParameters> => {
46+
return {
47+
operation: getSmithyContext(context).operation as string,
48+
region:
49+
(await normalizeProvider(config.region)()) ||
50+
(() => {
51+
throw new Error("expected `region` to be configured for `aws.auth#sigv4`");
52+
})(),
53+
};
54+
};
55+
56+
function createAwsAuthSigv4HttpAuthOption(authParameters: DynamoDBHttpAuthSchemeParameters): HttpAuthOption {
57+
return {
58+
schemeId: "aws.auth#sigv4",
59+
signingProperties: {
60+
name: "dynamodb",
61+
region: authParameters.region,
62+
},
63+
propertiesExtractor: (config: DynamoDBClientConfig, context) => ({
64+
/**
65+
* @internal
66+
*/
67+
signingProperties: {
68+
config,
69+
context,
70+
},
71+
}),
72+
};
73+
}
74+
75+
/**
76+
* @internal
77+
*/
78+
export interface DynamoDBHttpAuthSchemeProvider extends HttpAuthSchemeProvider<DynamoDBHttpAuthSchemeParameters> {}
79+
80+
/**
81+
* @internal
82+
*/
83+
export const defaultDynamoDBHttpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider = (authParameters) => {
84+
const options: HttpAuthOption[] = [];
85+
switch (authParameters.operation) {
86+
default: {
87+
options.push(createAwsAuthSigv4HttpAuthOption(authParameters));
88+
}
89+
}
90+
return options;
91+
};
92+
93+
/**
94+
* @internal
95+
*/
96+
export interface HttpAuthSchemeInputConfig extends AWSSDKSigV4AuthInputConfig {
97+
/**
98+
* experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
99+
* @internal
100+
*/
101+
httpAuthSchemes?: HttpAuthScheme[];
102+
103+
/**
104+
* experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use.
105+
* @internal
106+
*/
107+
httpAuthSchemeProvider?: DynamoDBHttpAuthSchemeProvider;
108+
}
109+
110+
/**
111+
* @internal
112+
*/
113+
export interface HttpAuthSchemeResolvedConfig extends AWSSDKSigV4AuthResolvedConfig {
114+
/**
115+
* experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme.
116+
* @internal
117+
*/
118+
readonly httpAuthSchemes: HttpAuthScheme[];
119+
120+
/**
121+
* experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use.
122+
* @internal
123+
*/
124+
readonly httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider;
125+
}
126+
127+
/**
128+
* @internal
129+
*/
130+
export const resolveHttpAuthSchemeConfig = <T>(
131+
config: T & HttpAuthSchemeInputConfig & AWSSDKSigV4PreviouslyResolved
132+
): T & HttpAuthSchemeResolvedConfig => {
133+
const config_0 = resolveAWSSDKSigV4Config(config);
134+
return {
135+
...config_0,
136+
} as T & HttpAuthSchemeResolvedConfig;
137+
};

0 commit comments

Comments
 (0)