Skip to content

Commit f6658b4

Browse files
author
Steven Yuan
authored
feat(experimentalIdentityAndAuth): release phase for STS (#5282)
Release support for `experimentalIdentityAndAuth` for STS.
1 parent 9a97df5 commit f6658b4

16 files changed

+331
-31
lines changed

clients/client-sts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
"@aws-sdk/middleware-host-header": "*",
2828
"@aws-sdk/middleware-logger": "*",
2929
"@aws-sdk/middleware-recursion-detection": "*",
30-
"@aws-sdk/middleware-sdk-sts": "*",
31-
"@aws-sdk/middleware-signing": "*",
3230
"@aws-sdk/middleware-user-agent": "*",
3331
"@aws-sdk/region-config-resolver": "*",
3432
"@aws-sdk/types": "*",
3533
"@aws-sdk/util-endpoints": "*",
3634
"@aws-sdk/util-user-agent-browser": "*",
3735
"@aws-sdk/util-user-agent-node": "*",
3836
"@smithy/config-resolver": "^2.0.21",
37+
"@smithy/core": "^1.1.0",
3938
"@smithy/fetch-http-handler": "^2.3.1",
4039
"@smithy/hash-node": "^2.0.17",
4140
"@smithy/invalid-dependency": "^2.0.15",
@@ -56,6 +55,7 @@
5655
"@smithy/util-defaults-mode-browser": "^2.0.22",
5756
"@smithy/util-defaults-mode-node": "^2.0.29",
5857
"@smithy/util-endpoints": "^1.0.7",
58+
"@smithy/util-middleware": "^2.0.8",
5959
"@smithy/util-retry": "^2.0.8",
6060
"@smithy/util-utf8": "^2.0.2",
6161
"fast-xml-parser": "4.2.5",

clients/client-sts/src/STSClient.ts

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +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 { resolveStsAuthConfig, StsAuthInputConfig, StsAuthResolvedConfig } from "@aws-sdk/middleware-sdk-sts";
1110
import {
1211
getUserAgentPlugin,
1312
resolveUserAgentConfig,
1413
UserAgentInputConfig,
1514
UserAgentResolvedConfig,
1615
} from "@aws-sdk/middleware-user-agent";
17-
import { Credentials as __Credentials } from "@aws-sdk/types";
1816
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
17+
import {
18+
DefaultIdentityProviderConfig,
19+
getHttpAuthSchemeEndpointRuleSetPlugin,
20+
getHttpSigningPlugin,
21+
} from "@smithy/core";
1922
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
2023
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
2124
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
@@ -27,6 +30,7 @@ import {
2730
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
2831
} from "@smithy/smithy-client";
2932
import {
33+
AwsCredentialIdentityProvider,
3034
BodyLengthCalculator as __BodyLengthCalculator,
3135
CheckOptionalClientConfig as __CheckOptionalClientConfig,
3236
ChecksumConstructor as __ChecksumConstructor,
@@ -43,6 +47,12 @@ import {
4347
UserAgent as __UserAgent,
4448
} from "@smithy/types";
4549

50+
import {
51+
defaultSTSHttpAuthSchemeParametersProvider,
52+
HttpAuthSchemeInputConfig,
53+
HttpAuthSchemeResolvedConfig,
54+
resolveHttpAuthSchemeConfig,
55+
} from "./auth/httpAuthSchemeProvider";
4656
import { AssumeRoleCommandInput, AssumeRoleCommandOutput } from "./commands/AssumeRoleCommand";
4757
import { AssumeRoleWithSAMLCommandInput, AssumeRoleWithSAMLCommandOutput } from "./commands/AssumeRoleWithSAMLCommand";
4858
import {
@@ -181,21 +191,22 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
181191
useFipsEndpoint?: boolean | __Provider<boolean>;
182192

183193
/**
184-
* The AWS region to which this client will send requests
194+
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
195+
* @internal
185196
*/
186-
region?: string | __Provider<string>;
197+
defaultUserAgentProvider?: Provider<__UserAgent>;
187198

188199
/**
189-
* Default credentials provider; Not available in browser runtime.
190-
* @internal
200+
* The AWS region to which this client will send requests
191201
*/
192-
credentialDefaultProvider?: (input: any) => __Provider<__Credentials>;
202+
region?: string | __Provider<string>;
193203

194204
/**
195-
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
205+
* Default credentials provider; Not available in browser runtime.
206+
* @deprecated
196207
* @internal
197208
*/
198-
defaultUserAgentProvider?: Provider<__UserAgent>;
209+
credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider;
199210

200211
/**
201212
* Value for how many times a request will be made at most in case of retry.
@@ -234,8 +245,8 @@ export type STSClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOpt
234245
EndpointInputConfig<EndpointParameters> &
235246
RetryInputConfig &
236247
HostHeaderInputConfig &
237-
StsAuthInputConfig &
238248
UserAgentInputConfig &
249+
HttpAuthSchemeInputConfig &
239250
ClientInputEndpointParameters;
240251
/**
241252
* @public
@@ -254,8 +265,8 @@ export type STSClientResolvedConfigType = __SmithyResolvedConfiguration<__HttpHa
254265
EndpointResolvedConfig<EndpointParameters> &
255266
RetryResolvedConfig &
256267
HostHeaderResolvedConfig &
257-
StsAuthResolvedConfig &
258268
UserAgentResolvedConfig &
269+
HttpAuthSchemeResolvedConfig &
259270
ClientResolvedEndpointParameters;
260271
/**
261272
* @public
@@ -282,15 +293,26 @@ export class STSClient extends __Client<
282293
*/
283294
readonly config: STSClientResolvedConfig;
284295

296+
private getDefaultHttpAuthSchemeParametersProvider() {
297+
return defaultSTSHttpAuthSchemeParametersProvider;
298+
}
299+
300+
private getIdentityProviderConfigProvider() {
301+
return async (config: STSClientResolvedConfig) =>
302+
new DefaultIdentityProviderConfig({
303+
"aws.auth#sigv4": config.credentials,
304+
});
305+
}
306+
285307
constructor(...[configuration]: __CheckOptionalClientConfig<STSClientConfig>) {
286308
const _config_0 = __getRuntimeConfig(configuration || {});
287309
const _config_1 = resolveClientEndpointParameters(_config_0);
288310
const _config_2 = resolveRegionConfig(_config_1);
289311
const _config_3 = resolveEndpointConfig(_config_2);
290312
const _config_4 = resolveRetryConfig(_config_3);
291313
const _config_5 = resolveHostHeaderConfig(_config_4);
292-
const _config_6 = resolveStsAuthConfig(_config_5, { stsClientCtor: STSClient });
293-
const _config_7 = resolveUserAgentConfig(_config_6);
314+
const _config_6 = resolveUserAgentConfig(_config_5);
315+
const _config_7 = resolveHttpAuthSchemeConfig(_config_6);
294316
const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
295317
super(_config_8);
296318
this.config = _config_8;
@@ -300,6 +322,13 @@ export class STSClient extends __Client<
300322
this.middlewareStack.use(getLoggerPlugin(this.config));
301323
this.middlewareStack.use(getRecursionDetectionPlugin(this.config));
302324
this.middlewareStack.use(getUserAgentPlugin(this.config));
325+
this.middlewareStack.use(
326+
getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
327+
httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(),
328+
identityProviderConfigProvider: this.getIdentityProviderConfigProvider(),
329+
})
330+
);
331+
this.middlewareStack.use(getHttpSigningPlugin(this.config));
303332
}
304333

305334
/**
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 { STSHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
5+
6+
/**
7+
* @internal
8+
*/
9+
export interface HttpAuthExtensionConfiguration {
10+
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void;
11+
httpAuthSchemes(): HttpAuthScheme[];
12+
setHttpAuthSchemeProvider(httpAuthSchemeProvider: STSHttpAuthSchemeProvider): void;
13+
httpAuthSchemeProvider(): STSHttpAuthSchemeProvider;
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: STSHttpAuthSchemeProvider;
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: STSHttpAuthSchemeProvider): void {
49+
_httpAuthSchemeProvider = httpAuthSchemeProvider;
50+
},
51+
httpAuthSchemeProvider(): STSHttpAuthSchemeProvider {
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+
};

0 commit comments

Comments
 (0)