Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimentalIdentityAndAuth): release phase for STS #5282

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/client-sts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
"@aws-sdk/middleware-sdk-sts": "*",
"@aws-sdk/middleware-signing": "*",
"@aws-sdk/middleware-user-agent": "*",
"@aws-sdk/region-config-resolver": "*",
"@aws-sdk/types": "*",
"@aws-sdk/util-endpoints": "*",
"@aws-sdk/util-user-agent-browser": "*",
"@aws-sdk/util-user-agent-node": "*",
"@smithy/config-resolver": "^2.0.21",
"@smithy/core": "^1.1.0",
"@smithy/fetch-http-handler": "^2.3.1",
"@smithy/hash-node": "^2.0.17",
"@smithy/invalid-dependency": "^2.0.15",
Expand All @@ -56,6 +55,7 @@
"@smithy/util-defaults-mode-browser": "^2.0.22",
"@smithy/util-defaults-mode-node": "^2.0.29",
"@smithy/util-endpoints": "^1.0.7",
"@smithy/util-middleware": "^2.0.8",
"@smithy/util-retry": "^2.0.8",
"@smithy/util-utf8": "^2.0.2",
"fast-xml-parser": "4.2.5",
Expand Down
55 changes: 42 additions & 13 deletions clients/client-sts/src/STSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
} from "@aws-sdk/middleware-host-header";
import { getLoggerPlugin } from "@aws-sdk/middleware-logger";
import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection";
import { resolveStsAuthConfig, StsAuthInputConfig, StsAuthResolvedConfig } from "@aws-sdk/middleware-sdk-sts";
import {
getUserAgentPlugin,
resolveUserAgentConfig,
UserAgentInputConfig,
UserAgentResolvedConfig,
} from "@aws-sdk/middleware-user-agent";
import { Credentials as __Credentials } from "@aws-sdk/types";
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
import {
DefaultIdentityProviderConfig,
getHttpAuthSchemeEndpointRuleSetPlugin,
getHttpSigningPlugin,
} from "@smithy/core";
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
Expand All @@ -27,6 +30,7 @@ import {
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
} from "@smithy/smithy-client";
import {
AwsCredentialIdentityProvider,
BodyLengthCalculator as __BodyLengthCalculator,
CheckOptionalClientConfig as __CheckOptionalClientConfig,
ChecksumConstructor as __ChecksumConstructor,
Expand All @@ -43,6 +47,12 @@ import {
UserAgent as __UserAgent,
} from "@smithy/types";

import {
defaultSTSHttpAuthSchemeParametersProvider,
HttpAuthSchemeInputConfig,
HttpAuthSchemeResolvedConfig,
resolveHttpAuthSchemeConfig,
} from "./auth/httpAuthSchemeProvider";
import { AssumeRoleCommandInput, AssumeRoleCommandOutput } from "./commands/AssumeRoleCommand";
import { AssumeRoleWithSAMLCommandInput, AssumeRoleWithSAMLCommandOutput } from "./commands/AssumeRoleWithSAMLCommand";
import {
Expand Down Expand Up @@ -181,21 +191,22 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
useFipsEndpoint?: boolean | __Provider<boolean>;

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

/**
* Default credentials provider; Not available in browser runtime.
* @internal
* The AWS region to which this client will send requests
*/
credentialDefaultProvider?: (input: any) => __Provider<__Credentials>;
region?: string | __Provider<string>;

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

/**
* Value for how many times a request will be made at most in case of retry.
Expand Down Expand Up @@ -234,8 +245,8 @@ export type STSClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOpt
EndpointInputConfig<EndpointParameters> &
RetryInputConfig &
HostHeaderInputConfig &
StsAuthInputConfig &
UserAgentInputConfig &
HttpAuthSchemeInputConfig &
ClientInputEndpointParameters;
/**
* @public
Expand All @@ -254,8 +265,8 @@ export type STSClientResolvedConfigType = __SmithyResolvedConfiguration<__HttpHa
EndpointResolvedConfig<EndpointParameters> &
RetryResolvedConfig &
HostHeaderResolvedConfig &
StsAuthResolvedConfig &
UserAgentResolvedConfig &
HttpAuthSchemeResolvedConfig &
ClientResolvedEndpointParameters;
/**
* @public
Expand All @@ -282,15 +293,26 @@ export class STSClient extends __Client<
*/
readonly config: STSClientResolvedConfig;

private getDefaultHttpAuthSchemeParametersProvider() {
return defaultSTSHttpAuthSchemeParametersProvider;
}

private getIdentityProviderConfigProvider() {
return async (config: STSClientResolvedConfig) =>
new DefaultIdentityProviderConfig({
"aws.auth#sigv4": config.credentials,
});
}

constructor(...[configuration]: __CheckOptionalClientConfig<STSClientConfig>) {
const _config_0 = __getRuntimeConfig(configuration || {});
const _config_1 = resolveClientEndpointParameters(_config_0);
const _config_2 = resolveRegionConfig(_config_1);
const _config_3 = resolveEndpointConfig(_config_2);
const _config_4 = resolveRetryConfig(_config_3);
const _config_5 = resolveHostHeaderConfig(_config_4);
const _config_6 = resolveStsAuthConfig(_config_5, { stsClientCtor: STSClient });
const _config_7 = resolveUserAgentConfig(_config_6);
const _config_6 = resolveUserAgentConfig(_config_5);
const _config_7 = resolveHttpAuthSchemeConfig(_config_6);
const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
super(_config_8);
this.config = _config_8;
Expand All @@ -300,6 +322,13 @@ export class STSClient extends __Client<
this.middlewareStack.use(getLoggerPlugin(this.config));
this.middlewareStack.use(getRecursionDetectionPlugin(this.config));
this.middlewareStack.use(getUserAgentPlugin(this.config));
this.middlewareStack.use(
getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(),
identityProviderConfigProvider: this.getIdentityProviderConfigProvider(),
})
);
this.middlewareStack.use(getHttpSigningPlugin(this.config));
}

/**
Expand Down
72 changes: 72 additions & 0 deletions clients/client-sts/src/auth/httpAuthExtensionConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// smithy-typescript generated code
import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types";

import { STSHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";

/**
* @internal
*/
export interface HttpAuthExtensionConfiguration {
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void;
httpAuthSchemes(): HttpAuthScheme[];
setHttpAuthSchemeProvider(httpAuthSchemeProvider: STSHttpAuthSchemeProvider): void;
httpAuthSchemeProvider(): STSHttpAuthSchemeProvider;
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void;
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined;
}

/**
* @internal
*/
export type HttpAuthRuntimeConfig = Partial<{
httpAuthSchemes: HttpAuthScheme[];
httpAuthSchemeProvider: STSHttpAuthSchemeProvider;
credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
}>;

/**
* @internal
*/
export const getHttpAuthExtensionConfiguration = (
runtimeConfig: HttpAuthRuntimeConfig
): HttpAuthExtensionConfiguration => {
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!;
let _credentials = runtimeConfig.credentials;
return {
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void {
const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId);
if (index === -1) {
_httpAuthSchemes.push(httpAuthScheme);
} else {
_httpAuthSchemes.splice(index, 1, httpAuthScheme);
}
},
httpAuthSchemes(): HttpAuthScheme[] {
return _httpAuthSchemes;
},
setHttpAuthSchemeProvider(httpAuthSchemeProvider: STSHttpAuthSchemeProvider): void {
_httpAuthSchemeProvider = httpAuthSchemeProvider;
},
httpAuthSchemeProvider(): STSHttpAuthSchemeProvider {
return _httpAuthSchemeProvider;
},
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void {
_credentials = credentials;
},
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined {
return _credentials;
},
};
};

/**
* @internal
*/
export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => {
return {
httpAuthSchemes: config.httpAuthSchemes(),
httpAuthSchemeProvider: config.httpAuthSchemeProvider(),
credentials: config.credentials(),
};
};
Loading
Loading