Skip to content

Commit 1ba36c4

Browse files
author
Steven Yuan
authored
feat(experimentalIdentityAndAuth): release phase for services with signing customizations (#5286)
Services: - RDS - EC2 - Polly
1 parent 2b028a5 commit 1ba36c4

22 files changed

+813
-63
lines changed

clients/client-ec2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"@aws-sdk/middleware-logger": "*",
2828
"@aws-sdk/middleware-recursion-detection": "*",
2929
"@aws-sdk/middleware-sdk-ec2": "*",
30-
"@aws-sdk/middleware-signing": "*",
3130
"@aws-sdk/middleware-user-agent": "*",
3231
"@aws-sdk/region-config-resolver": "*",
3332
"@aws-sdk/types": "*",
@@ -56,6 +55,7 @@
5655
"@smithy/util-defaults-mode-browser": "^2.0.24",
5756
"@smithy/util-defaults-mode-node": "^2.0.32",
5857
"@smithy/util-endpoints": "^1.0.8",
58+
"@smithy/util-middleware": "^2.0.9",
5959
"@smithy/util-retry": "^2.0.9",
6060
"@smithy/util-utf8": "^2.0.2",
6161
"@smithy/util-waiter": "^2.0.16",

clients/client-ec2/src/EC2Client.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import {
77
} from "@aws-sdk/middleware-host-header";
88
import { getLoggerPlugin } from "@aws-sdk/middleware-logger";
99
import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection";
10-
import {
11-
AwsAuthInputConfig,
12-
AwsAuthResolvedConfig,
13-
getAwsAuthPlugin,
14-
resolveAwsAuthConfig,
15-
} from "@aws-sdk/middleware-signing";
1610
import {
1711
getUserAgentPlugin,
1812
resolveUserAgentConfig,
1913
UserAgentInputConfig,
2014
UserAgentResolvedConfig,
2115
} from "@aws-sdk/middleware-user-agent";
22-
import { Credentials as __Credentials } from "@aws-sdk/types";
2316
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
17+
import {
18+
DefaultIdentityProviderConfig,
19+
getHttpAuthSchemeEndpointRuleSetPlugin,
20+
getHttpSigningPlugin,
21+
} from "@smithy/core";
2422
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
2523
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
2624
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
@@ -32,6 +30,7 @@ import {
3230
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
3331
} from "@smithy/smithy-client";
3432
import {
33+
AwsCredentialIdentityProvider,
3534
BodyLengthCalculator as __BodyLengthCalculator,
3635
CheckOptionalClientConfig as __CheckOptionalClientConfig,
3736
ChecksumConstructor as __ChecksumConstructor,
@@ -48,6 +47,12 @@ import {
4847
UserAgent as __UserAgent,
4948
} from "@smithy/types";
5049

50+
import {
51+
defaultEC2HttpAuthSchemeParametersProvider,
52+
HttpAuthSchemeInputConfig,
53+
HttpAuthSchemeResolvedConfig,
54+
resolveHttpAuthSchemeConfig,
55+
} from "./auth/httpAuthSchemeProvider";
5156
import {
5257
AcceptAddressTransferCommandInput,
5358
AcceptAddressTransferCommandOutput,
@@ -3465,21 +3470,22 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
34653470
useFipsEndpoint?: boolean | __Provider<boolean>;
34663471

34673472
/**
3468-
* The AWS region to which this client will send requests
3473+
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
3474+
* @internal
34693475
*/
3470-
region?: string | __Provider<string>;
3476+
defaultUserAgentProvider?: Provider<__UserAgent>;
34713477

34723478
/**
3473-
* Default credentials provider; Not available in browser runtime.
3474-
* @internal
3479+
* The AWS region to which this client will send requests
34753480
*/
3476-
credentialDefaultProvider?: (input: any) => __Provider<__Credentials>;
3481+
region?: string | __Provider<string>;
34773482

34783483
/**
3479-
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
3484+
* Default credentials provider; Not available in browser runtime.
3485+
* @deprecated
34803486
* @internal
34813487
*/
3482-
defaultUserAgentProvider?: Provider<__UserAgent>;
3488+
credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider;
34833489

34843490
/**
34853491
* Value for how many times a request will be made at most in case of retry.
@@ -3518,8 +3524,8 @@ export type EC2ClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOpt
35183524
EndpointInputConfig<EndpointParameters> &
35193525
RetryInputConfig &
35203526
HostHeaderInputConfig &
3521-
AwsAuthInputConfig &
35223527
UserAgentInputConfig &
3528+
HttpAuthSchemeInputConfig &
35233529
ClientInputEndpointParameters;
35243530
/**
35253531
* @public
@@ -3538,8 +3544,8 @@ export type EC2ClientResolvedConfigType = __SmithyResolvedConfiguration<__HttpHa
35383544
EndpointResolvedConfig<EndpointParameters> &
35393545
RetryResolvedConfig &
35403546
HostHeaderResolvedConfig &
3541-
AwsAuthResolvedConfig &
35423547
UserAgentResolvedConfig &
3548+
HttpAuthSchemeResolvedConfig &
35433549
ClientResolvedEndpointParameters;
35443550
/**
35453551
* @public
@@ -3588,15 +3594,26 @@ export class EC2Client extends __Client<
35883594
*/
35893595
readonly config: EC2ClientResolvedConfig;
35903596

3597+
private getDefaultHttpAuthSchemeParametersProvider() {
3598+
return defaultEC2HttpAuthSchemeParametersProvider;
3599+
}
3600+
3601+
private getIdentityProviderConfigProvider() {
3602+
return async (config: EC2ClientResolvedConfig) =>
3603+
new DefaultIdentityProviderConfig({
3604+
"aws.auth#sigv4": config.credentials,
3605+
});
3606+
}
3607+
35913608
constructor(...[configuration]: __CheckOptionalClientConfig<EC2ClientConfig>) {
35923609
const _config_0 = __getRuntimeConfig(configuration || {});
35933610
const _config_1 = resolveClientEndpointParameters(_config_0);
35943611
const _config_2 = resolveRegionConfig(_config_1);
35953612
const _config_3 = resolveEndpointConfig(_config_2);
35963613
const _config_4 = resolveRetryConfig(_config_3);
35973614
const _config_5 = resolveHostHeaderConfig(_config_4);
3598-
const _config_6 = resolveAwsAuthConfig(_config_5);
3599-
const _config_7 = resolveUserAgentConfig(_config_6);
3615+
const _config_6 = resolveUserAgentConfig(_config_5);
3616+
const _config_7 = resolveHttpAuthSchemeConfig(_config_6);
36003617
const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
36013618
super(_config_8);
36023619
this.config = _config_8;
@@ -3605,8 +3622,14 @@ export class EC2Client extends __Client<
36053622
this.middlewareStack.use(getHostHeaderPlugin(this.config));
36063623
this.middlewareStack.use(getLoggerPlugin(this.config));
36073624
this.middlewareStack.use(getRecursionDetectionPlugin(this.config));
3608-
this.middlewareStack.use(getAwsAuthPlugin(this.config));
36093625
this.middlewareStack.use(getUserAgentPlugin(this.config));
3626+
this.middlewareStack.use(
3627+
getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
3628+
httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(),
3629+
identityProviderConfigProvider: this.getIdentityProviderConfigProvider(),
3630+
})
3631+
);
3632+
this.middlewareStack.use(getHttpSigningPlugin(this.config));
36103633
}
36113634

36123635
/**
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 { EC2HttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
5+
6+
/**
7+
* @internal
8+
*/
9+
export interface HttpAuthExtensionConfiguration {
10+
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void;
11+
httpAuthSchemes(): HttpAuthScheme[];
12+
setHttpAuthSchemeProvider(httpAuthSchemeProvider: EC2HttpAuthSchemeProvider): void;
13+
httpAuthSchemeProvider(): EC2HttpAuthSchemeProvider;
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: EC2HttpAuthSchemeProvider;
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: EC2HttpAuthSchemeProvider): void {
49+
_httpAuthSchemeProvider = httpAuthSchemeProvider;
50+
},
51+
httpAuthSchemeProvider(): EC2HttpAuthSchemeProvider {
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 { EC2ClientConfig, EC2ClientResolvedConfig } from "../EC2Client";
19+
20+
/**
21+
* @internal
22+
*/
23+
export interface EC2HttpAuthSchemeParameters extends HttpAuthSchemeParameters {
24+
region?: string;
25+
}
26+
27+
/**
28+
* @internal
29+
*/
30+
export interface EC2HttpAuthSchemeParametersProvider
31+
extends HttpAuthSchemeParametersProvider<
32+
EC2ClientResolvedConfig,
33+
HandlerExecutionContext,
34+
EC2HttpAuthSchemeParameters,
35+
object
36+
> {}
37+
38+
/**
39+
* @internal
40+
*/
41+
export const defaultEC2HttpAuthSchemeParametersProvider = async (
42+
config: EC2ClientResolvedConfig,
43+
context: HandlerExecutionContext,
44+
input: object
45+
): Promise<EC2HttpAuthSchemeParameters> => {
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: EC2HttpAuthSchemeParameters): HttpAuthOption {
57+
return {
58+
schemeId: "aws.auth#sigv4",
59+
signingProperties: {
60+
name: "ec2",
61+
region: authParameters.region,
62+
},
63+
propertiesExtractor: (config: EC2ClientConfig, context) => ({
64+
/**
65+
* @internal
66+
*/
67+
signingProperties: {
68+
config,
69+
context,
70+
},
71+
}),
72+
};
73+
}
74+
75+
/**
76+
* @internal
77+
*/
78+
export interface EC2HttpAuthSchemeProvider extends HttpAuthSchemeProvider<EC2HttpAuthSchemeParameters> {}
79+
80+
/**
81+
* @internal
82+
*/
83+
export const defaultEC2HttpAuthSchemeProvider: EC2HttpAuthSchemeProvider = (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?: EC2HttpAuthSchemeProvider;
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: EC2HttpAuthSchemeProvider;
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+
};

clients/client-ec2/src/extensionConfiguration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { AwsRegionExtensionConfiguration } from "@aws-sdk/types";
33
import { HttpHandlerExtensionConfiguration } from "@smithy/protocol-http";
44
import { DefaultExtensionConfiguration } from "@smithy/types";
55

6+
import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration";
7+
68
/**
79
* @internal
810
*/
911
export interface EC2ExtensionConfiguration
1012
extends HttpHandlerExtensionConfiguration,
1113
DefaultExtensionConfiguration,
12-
AwsRegionExtensionConfiguration {}
14+
AwsRegionExtensionConfiguration,
15+
HttpAuthExtensionConfiguration {}

0 commit comments

Comments
 (0)