diff --git a/clients/client-lex-runtime-v2/package.json b/clients/client-lex-runtime-v2/package.json index d4e770fdc912d..5946b37ab76c8 100644 --- a/clients/client-lex-runtime-v2/package.json +++ b/clients/client-lex-runtime-v2/package.json @@ -29,7 +29,6 @@ "@aws-sdk/middleware-host-header": "*", "@aws-sdk/middleware-logger": "*", "@aws-sdk/middleware-recursion-detection": "*", - "@aws-sdk/middleware-signing": "*", "@aws-sdk/middleware-user-agent": "*", "@aws-sdk/region-config-resolver": "*", "@aws-sdk/types": "*", @@ -61,6 +60,7 @@ "@smithy/util-defaults-mode-browser": "^3.0.13", "@smithy/util-defaults-mode-node": "^3.0.13", "@smithy/util-endpoints": "^2.0.5", + "@smithy/util-middleware": "^3.0.3", "@smithy/util-retry": "^3.0.3", "@smithy/util-stream": "^3.1.3", "@smithy/util-utf8": "^3.0.0", diff --git a/clients/client-lex-runtime-v2/src/LexRuntimeV2Client.ts b/clients/client-lex-runtime-v2/src/LexRuntimeV2Client.ts index e8ffe791dca90..561f8467100ad 100644 --- a/clients/client-lex-runtime-v2/src/LexRuntimeV2Client.ts +++ b/clients/client-lex-runtime-v2/src/LexRuntimeV2Client.ts @@ -12,23 +12,19 @@ import { } from "@aws-sdk/middleware-host-header"; import { getLoggerPlugin } from "@aws-sdk/middleware-logger"; import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection"; -import { - AwsAuthInputConfig, - AwsAuthResolvedConfig, - getAwsAuthPlugin, - resolveAwsAuthConfig, -} from "@aws-sdk/middleware-signing"; import { getUserAgentPlugin, resolveUserAgentConfig, UserAgentInputConfig, UserAgentResolvedConfig, } from "@aws-sdk/middleware-user-agent"; -import { - Credentials as __Credentials, - EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider, -} from "@aws-sdk/types"; +import { EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider } from "@aws-sdk/types"; import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver"; +import { + DefaultIdentityProviderConfig, + getHttpAuthSchemeEndpointRuleSetPlugin, + getHttpSigningPlugin, +} from "@smithy/core"; import { EventStreamSerdeInputConfig, EventStreamSerdeResolvedConfig, @@ -45,6 +41,7 @@ import { SmithyResolvedConfiguration as __SmithyResolvedConfiguration, } from "@smithy/smithy-client"; import { + AwsCredentialIdentityProvider, BodyLengthCalculator as __BodyLengthCalculator, CheckOptionalClientConfig as __CheckOptionalClientConfig, ChecksumConstructor as __ChecksumConstructor, @@ -63,6 +60,12 @@ import { UserAgent as __UserAgent, } from "@smithy/types"; +import { + defaultLexRuntimeV2HttpAuthSchemeParametersProvider, + HttpAuthSchemeInputConfig, + HttpAuthSchemeResolvedConfig, + resolveHttpAuthSchemeConfig, +} from "./auth/httpAuthSchemeProvider"; import { DeleteSessionCommandInput, DeleteSessionCommandOutput } from "./commands/DeleteSessionCommand"; import { GetSessionCommandInput, GetSessionCommandOutput } from "./commands/GetSessionCommand"; import { PutSessionCommandInput, PutSessionCommandOutput } from "./commands/PutSessionCommand"; @@ -201,15 +204,10 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand /** * Default credentials provider; Not available in browser runtime. + * @deprecated * @internal */ - credentialDefaultProvider?: (input: any) => __Provider<__Credentials>; - - /** - * The function that provides necessary utilities for handling request event stream. - * @internal - */ - eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; + credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider; /** * Value for how many times a request will be made at most in case of retry. @@ -243,6 +241,12 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand */ defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>; + /** + * The function that provides necessary utilities for handling request event stream. + * @internal + */ + eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; + /** * The internal function that inject utilities to runtime-specific stream to help users consume the data * @internal @@ -260,9 +264,9 @@ export type LexRuntimeV2ClientConfigType = Partial<__SmithyConfiguration<__HttpH RegionInputConfig & HostHeaderInputConfig & EndpointInputConfig & - AwsAuthInputConfig & - EventStreamInputConfig & EventStreamSerdeInputConfig & + HttpAuthSchemeInputConfig & + EventStreamInputConfig & ClientInputEndpointParameters; /** * @public @@ -282,9 +286,9 @@ export type LexRuntimeV2ClientResolvedConfigType = __SmithyResolvedConfiguration RegionResolvedConfig & HostHeaderResolvedConfig & EndpointResolvedConfig & - AwsAuthResolvedConfig & - EventStreamResolvedConfig & EventStreamSerdeResolvedConfig & + HttpAuthSchemeResolvedConfig & + EventStreamResolvedConfig & ClientResolvedEndpointParameters; /** * @public @@ -316,9 +320,9 @@ export class LexRuntimeV2Client extends __Client< const _config_4 = resolveRegionConfig(_config_3); const _config_5 = resolveHostHeaderConfig(_config_4); const _config_6 = resolveEndpointConfig(_config_5); - const _config_7 = resolveAwsAuthConfig(_config_6); - const _config_8 = resolveEventStreamConfig(_config_7); - const _config_9 = resolveEventStreamSerdeConfig(_config_8); + const _config_7 = resolveEventStreamSerdeConfig(_config_6); + const _config_8 = resolveHttpAuthSchemeConfig(_config_7); + const _config_9 = resolveEventStreamConfig(_config_8); const _config_10 = resolveRuntimeExtensions(_config_9, configuration?.extensions || []); super(_config_10); this.config = _config_10; @@ -328,7 +332,16 @@ export class LexRuntimeV2Client extends __Client< this.middlewareStack.use(getHostHeaderPlugin(this.config)); this.middlewareStack.use(getLoggerPlugin(this.config)); this.middlewareStack.use(getRecursionDetectionPlugin(this.config)); - this.middlewareStack.use(getAwsAuthPlugin(this.config)); + this.middlewareStack.use( + getHttpAuthSchemeEndpointRuleSetPlugin(this.config, { + httpAuthSchemeParametersProvider: defaultLexRuntimeV2HttpAuthSchemeParametersProvider, + identityProviderConfigProvider: async (config: LexRuntimeV2ClientResolvedConfig) => + new DefaultIdentityProviderConfig({ + "aws.auth#sigv4": config.credentials, + }), + }) + ); + this.middlewareStack.use(getHttpSigningPlugin(this.config)); } /** diff --git a/clients/client-lex-runtime-v2/src/auth/httpAuthExtensionConfiguration.ts b/clients/client-lex-runtime-v2/src/auth/httpAuthExtensionConfiguration.ts new file mode 100644 index 0000000000000..aa287311f6788 --- /dev/null +++ b/clients/client-lex-runtime-v2/src/auth/httpAuthExtensionConfiguration.ts @@ -0,0 +1,72 @@ +// smithy-typescript generated code +import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types"; + +import { LexRuntimeV2HttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; + +/** + * @internal + */ +export interface HttpAuthExtensionConfiguration { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; + httpAuthSchemes(): HttpAuthScheme[]; + setHttpAuthSchemeProvider(httpAuthSchemeProvider: LexRuntimeV2HttpAuthSchemeProvider): void; + httpAuthSchemeProvider(): LexRuntimeV2HttpAuthSchemeProvider; + setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void; + credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined; +} + +/** + * @internal + */ +export type HttpAuthRuntimeConfig = Partial<{ + httpAuthSchemes: HttpAuthScheme[]; + httpAuthSchemeProvider: LexRuntimeV2HttpAuthSchemeProvider; + 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: LexRuntimeV2HttpAuthSchemeProvider): void { + _httpAuthSchemeProvider = httpAuthSchemeProvider; + }, + httpAuthSchemeProvider(): LexRuntimeV2HttpAuthSchemeProvider { + 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(), + }; +}; diff --git a/clients/client-lex-runtime-v2/src/auth/httpAuthSchemeProvider.ts b/clients/client-lex-runtime-v2/src/auth/httpAuthSchemeProvider.ts new file mode 100644 index 0000000000000..52efa6e24914f --- /dev/null +++ b/clients/client-lex-runtime-v2/src/auth/httpAuthSchemeProvider.ts @@ -0,0 +1,138 @@ +// smithy-typescript generated code +import { + AwsSdkSigV4AuthInputConfig, + AwsSdkSigV4AuthResolvedConfig, + AwsSdkSigV4PreviouslyResolved, + resolveAwsSdkSigV4Config, +} from "@aws-sdk/core"; +import { + HandlerExecutionContext, + HttpAuthOption, + HttpAuthScheme, + HttpAuthSchemeParameters, + HttpAuthSchemeParametersProvider, + HttpAuthSchemeProvider, +} from "@smithy/types"; +import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; + +import { LexRuntimeV2ClientConfig, LexRuntimeV2ClientResolvedConfig } from "../LexRuntimeV2Client"; + +/** + * @internal + */ +export interface LexRuntimeV2HttpAuthSchemeParameters extends HttpAuthSchemeParameters { + region?: string; +} + +/** + * @internal + */ +export interface LexRuntimeV2HttpAuthSchemeParametersProvider + extends HttpAuthSchemeParametersProvider< + LexRuntimeV2ClientResolvedConfig, + HandlerExecutionContext, + LexRuntimeV2HttpAuthSchemeParameters, + object + > {} + +/** + * @internal + */ +export const defaultLexRuntimeV2HttpAuthSchemeParametersProvider = async ( + config: LexRuntimeV2ClientResolvedConfig, + context: HandlerExecutionContext, + input: object +): Promise => { + return { + operation: getSmithyContext(context).operation as string, + region: + (await normalizeProvider(config.region)()) || + (() => { + throw new Error("expected `region` to be configured for `aws.auth#sigv4`"); + })(), + }; +}; + +function createAwsAuthSigv4HttpAuthOption(authParameters: LexRuntimeV2HttpAuthSchemeParameters): HttpAuthOption { + return { + schemeId: "aws.auth#sigv4", + signingProperties: { + name: "lex", + region: authParameters.region, + }, + propertiesExtractor: (config: Partial, context) => ({ + /** + * @internal + */ + signingProperties: { + config, + context, + }, + }), + }; +} + +/** + * @internal + */ +export interface LexRuntimeV2HttpAuthSchemeProvider + extends HttpAuthSchemeProvider {} + +/** + * @internal + */ +export const defaultLexRuntimeV2HttpAuthSchemeProvider: LexRuntimeV2HttpAuthSchemeProvider = (authParameters) => { + const options: HttpAuthOption[] = []; + switch (authParameters.operation) { + default: { + options.push(createAwsAuthSigv4HttpAuthOption(authParameters)); + } + } + return options; +}; + +/** + * @internal + */ +export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + httpAuthSchemes?: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + httpAuthSchemeProvider?: LexRuntimeV2HttpAuthSchemeProvider; +} + +/** + * @internal + */ +export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + readonly httpAuthSchemes: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + readonly httpAuthSchemeProvider: LexRuntimeV2HttpAuthSchemeProvider; +} + +/** + * @internal + */ +export const resolveHttpAuthSchemeConfig = ( + config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved +): T & HttpAuthSchemeResolvedConfig => { + const config_0 = resolveAwsSdkSigV4Config(config); + return { + ...config_0, + } as T & HttpAuthSchemeResolvedConfig; +}; diff --git a/clients/client-lex-runtime-v2/src/extensionConfiguration.ts b/clients/client-lex-runtime-v2/src/extensionConfiguration.ts index 9e84f4166fbb6..c492af206223a 100644 --- a/clients/client-lex-runtime-v2/src/extensionConfiguration.ts +++ b/clients/client-lex-runtime-v2/src/extensionConfiguration.ts @@ -3,10 +3,13 @@ import { AwsRegionExtensionConfiguration } from "@aws-sdk/types"; import { HttpHandlerExtensionConfiguration } from "@smithy/protocol-http"; import { DefaultExtensionConfiguration } from "@smithy/types"; +import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration"; + /** * @internal */ export interface LexRuntimeV2ExtensionConfiguration extends HttpHandlerExtensionConfiguration, DefaultExtensionConfiguration, - AwsRegionExtensionConfiguration {} + AwsRegionExtensionConfiguration, + HttpAuthExtensionConfiguration {} diff --git a/clients/client-lex-runtime-v2/src/models/models_0.ts b/clients/client-lex-runtime-v2/src/models/models_0.ts index d69dad1331062..e027b325afa89 100644 --- a/clients/client-lex-runtime-v2/src/models/models_0.ts +++ b/clients/client-lex-runtime-v2/src/models/models_0.ts @@ -1,6 +1,5 @@ // smithy-typescript generated code import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client"; - import { StreamingBlobTypes } from "@smithy/types"; import { LexRuntimeV2ServiceException as __BaseException } from "./LexRuntimeV2ServiceException"; diff --git a/clients/client-lex-runtime-v2/src/runtimeConfig.shared.ts b/clients/client-lex-runtime-v2/src/runtimeConfig.shared.ts index ab7da3f214a5e..244a46eb505f8 100644 --- a/clients/client-lex-runtime-v2/src/runtimeConfig.shared.ts +++ b/clients/client-lex-runtime-v2/src/runtimeConfig.shared.ts @@ -1,10 +1,13 @@ // smithy-typescript generated code +import { AwsSdkSigV4Signer } from "@aws-sdk/core"; import { NoOpLogger } from "@smithy/smithy-client"; +import { IdentityProviderConfig } from "@smithy/types"; import { parseUrl } from "@smithy/url-parser"; import { fromBase64, toBase64 } from "@smithy/util-base64"; import { sdkStreamMixin } from "@smithy/util-stream"; import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; +import { defaultLexRuntimeV2HttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider"; import { defaultEndpointResolver } from "./endpoint/endpointResolver"; import { LexRuntimeV2ClientConfig } from "./LexRuntimeV2Client"; @@ -19,6 +22,14 @@ export const getRuntimeConfig = (config: LexRuntimeV2ClientConfig) => { disableHostPrefix: config?.disableHostPrefix ?? false, endpointProvider: config?.endpointProvider ?? defaultEndpointResolver, extensions: config?.extensions ?? [], + httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultLexRuntimeV2HttpAuthSchemeProvider, + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "aws.auth#sigv4", + identityProvider: (ipc: IdentityProviderConfig) => ipc.getIdentityProvider("aws.auth#sigv4"), + signer: new AwsSdkSigV4Signer(), + }, + ], logger: config?.logger ?? new NoOpLogger(), sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin, serviceId: config?.serviceId ?? "Lex Runtime V2", diff --git a/clients/client-lex-runtime-v2/src/runtimeExtensions.ts b/clients/client-lex-runtime-v2/src/runtimeExtensions.ts index a62683cbeedde..b0c31c648a84a 100644 --- a/clients/client-lex-runtime-v2/src/runtimeExtensions.ts +++ b/clients/client-lex-runtime-v2/src/runtimeExtensions.ts @@ -6,6 +6,7 @@ import { import { getHttpHandlerExtensionConfiguration, resolveHttpHandlerRuntimeConfig } from "@smithy/protocol-http"; import { getDefaultExtensionConfiguration, resolveDefaultRuntimeConfig } from "@smithy/smithy-client"; +import { getHttpAuthExtensionConfiguration, resolveHttpAuthRuntimeConfig } from "./auth/httpAuthExtensionConfiguration"; import { LexRuntimeV2ExtensionConfiguration } from "./extensionConfiguration"; /** @@ -32,6 +33,7 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...asPartial(getAwsRegionExtensionConfiguration(runtimeConfig)), ...asPartial(getDefaultExtensionConfiguration(runtimeConfig)), ...asPartial(getHttpHandlerExtensionConfiguration(runtimeConfig)), + ...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)), }; extensions.forEach((extension) => extension.configure(extensionConfiguration)); @@ -41,5 +43,6 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...resolveAwsRegionExtensionConfiguration(extensionConfiguration), ...resolveDefaultRuntimeConfig(extensionConfiguration), ...resolveHttpHandlerRuntimeConfig(extensionConfiguration), + ...resolveHttpAuthRuntimeConfig(extensionConfiguration), }; }; diff --git a/clients/client-rekognitionstreaming/package.json b/clients/client-rekognitionstreaming/package.json index c598d808979dd..937de215f8442 100644 --- a/clients/client-rekognitionstreaming/package.json +++ b/clients/client-rekognitionstreaming/package.json @@ -29,7 +29,6 @@ "@aws-sdk/middleware-host-header": "*", "@aws-sdk/middleware-logger": "*", "@aws-sdk/middleware-recursion-detection": "*", - "@aws-sdk/middleware-signing": "*", "@aws-sdk/middleware-user-agent": "*", "@aws-sdk/middleware-websocket": "*", "@aws-sdk/region-config-resolver": "*", @@ -62,6 +61,7 @@ "@smithy/util-defaults-mode-browser": "^3.0.13", "@smithy/util-defaults-mode-node": "^3.0.13", "@smithy/util-endpoints": "^2.0.5", + "@smithy/util-middleware": "^3.0.3", "@smithy/util-retry": "^3.0.3", "@smithy/util-utf8": "^3.0.0", "tslib": "^2.6.2" diff --git a/clients/client-rekognitionstreaming/src/RekognitionStreamingClient.ts b/clients/client-rekognitionstreaming/src/RekognitionStreamingClient.ts index 22cf432933a80..6245cb0d917e0 100644 --- a/clients/client-rekognitionstreaming/src/RekognitionStreamingClient.ts +++ b/clients/client-rekognitionstreaming/src/RekognitionStreamingClient.ts @@ -12,12 +12,6 @@ import { } from "@aws-sdk/middleware-host-header"; import { getLoggerPlugin } from "@aws-sdk/middleware-logger"; import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection"; -import { - AwsAuthInputConfig, - AwsAuthResolvedConfig, - getAwsAuthPlugin, - resolveAwsAuthConfig, -} from "@aws-sdk/middleware-signing"; import { getUserAgentPlugin, resolveUserAgentConfig, @@ -25,11 +19,13 @@ import { UserAgentResolvedConfig, } from "@aws-sdk/middleware-user-agent"; import { resolveWebSocketConfig, WebSocketInputConfig, WebSocketResolvedConfig } from "@aws-sdk/middleware-websocket"; -import { - Credentials as __Credentials, - EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider, -} from "@aws-sdk/types"; +import { EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider } from "@aws-sdk/types"; import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver"; +import { + DefaultIdentityProviderConfig, + getHttpAuthSchemeEndpointRuleSetPlugin, + getHttpSigningPlugin, +} from "@smithy/core"; import { EventStreamSerdeInputConfig, EventStreamSerdeResolvedConfig, @@ -46,6 +42,7 @@ import { SmithyResolvedConfiguration as __SmithyResolvedConfiguration, } from "@smithy/smithy-client"; import { + AwsCredentialIdentityProvider, BodyLengthCalculator as __BodyLengthCalculator, CheckOptionalClientConfig as __CheckOptionalClientConfig, ChecksumConstructor as __ChecksumConstructor, @@ -63,6 +60,12 @@ import { UserAgent as __UserAgent, } from "@smithy/types"; +import { + defaultRekognitionStreamingHttpAuthSchemeParametersProvider, + HttpAuthSchemeInputConfig, + HttpAuthSchemeResolvedConfig, + resolveHttpAuthSchemeConfig, +} from "./auth/httpAuthSchemeProvider"; import { StartFaceLivenessSessionCommandInput, StartFaceLivenessSessionCommandOutput, @@ -187,15 +190,10 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand /** * Default credentials provider; Not available in browser runtime. + * @deprecated * @internal */ - credentialDefaultProvider?: (input: any) => __Provider<__Credentials>; - - /** - * The function that provides necessary utilities for handling request event stream. - * @internal - */ - eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; + credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider; /** * Value for how many times a request will be made at most in case of retry. @@ -228,6 +226,12 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand * The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK. */ defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>; + + /** + * The function that provides necessary utilities for handling request event stream. + * @internal + */ + eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; } /** @@ -240,10 +244,10 @@ export type RekognitionStreamingClientConfigType = Partial<__SmithyConfiguration RegionInputConfig & HostHeaderInputConfig & EndpointInputConfig & - AwsAuthInputConfig & + EventStreamSerdeInputConfig & + HttpAuthSchemeInputConfig & EventStreamInputConfig & WebSocketInputConfig & - EventStreamSerdeInputConfig & ClientInputEndpointParameters; /** * @public @@ -263,10 +267,10 @@ export type RekognitionStreamingClientResolvedConfigType = __SmithyResolvedConfi RegionResolvedConfig & HostHeaderResolvedConfig & EndpointResolvedConfig & - AwsAuthResolvedConfig & + EventStreamSerdeResolvedConfig & + HttpAuthSchemeResolvedConfig & EventStreamResolvedConfig & WebSocketResolvedConfig & - EventStreamSerdeResolvedConfig & ClientResolvedEndpointParameters; /** * @public @@ -319,10 +323,10 @@ export class RekognitionStreamingClient extends __Client< const _config_4 = resolveRegionConfig(_config_3); const _config_5 = resolveHostHeaderConfig(_config_4); const _config_6 = resolveEndpointConfig(_config_5); - const _config_7 = resolveAwsAuthConfig(_config_6); - const _config_8 = resolveEventStreamConfig(_config_7); - const _config_9 = resolveWebSocketConfig(_config_8); - const _config_10 = resolveEventStreamSerdeConfig(_config_9); + const _config_7 = resolveEventStreamSerdeConfig(_config_6); + const _config_8 = resolveHttpAuthSchemeConfig(_config_7); + const _config_9 = resolveEventStreamConfig(_config_8); + const _config_10 = resolveWebSocketConfig(_config_9); const _config_11 = resolveRuntimeExtensions(_config_10, configuration?.extensions || []); super(_config_11); this.config = _config_11; @@ -332,7 +336,16 @@ export class RekognitionStreamingClient extends __Client< this.middlewareStack.use(getHostHeaderPlugin(this.config)); this.middlewareStack.use(getLoggerPlugin(this.config)); this.middlewareStack.use(getRecursionDetectionPlugin(this.config)); - this.middlewareStack.use(getAwsAuthPlugin(this.config)); + this.middlewareStack.use( + getHttpAuthSchemeEndpointRuleSetPlugin(this.config, { + httpAuthSchemeParametersProvider: defaultRekognitionStreamingHttpAuthSchemeParametersProvider, + identityProviderConfigProvider: async (config: RekognitionStreamingClientResolvedConfig) => + new DefaultIdentityProviderConfig({ + "aws.auth#sigv4": config.credentials, + }), + }) + ); + this.middlewareStack.use(getHttpSigningPlugin(this.config)); } /** diff --git a/clients/client-rekognitionstreaming/src/auth/httpAuthExtensionConfiguration.ts b/clients/client-rekognitionstreaming/src/auth/httpAuthExtensionConfiguration.ts new file mode 100644 index 0000000000000..8b502d5049144 --- /dev/null +++ b/clients/client-rekognitionstreaming/src/auth/httpAuthExtensionConfiguration.ts @@ -0,0 +1,72 @@ +// smithy-typescript generated code +import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types"; + +import { RekognitionStreamingHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; + +/** + * @internal + */ +export interface HttpAuthExtensionConfiguration { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; + httpAuthSchemes(): HttpAuthScheme[]; + setHttpAuthSchemeProvider(httpAuthSchemeProvider: RekognitionStreamingHttpAuthSchemeProvider): void; + httpAuthSchemeProvider(): RekognitionStreamingHttpAuthSchemeProvider; + setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void; + credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined; +} + +/** + * @internal + */ +export type HttpAuthRuntimeConfig = Partial<{ + httpAuthSchemes: HttpAuthScheme[]; + httpAuthSchemeProvider: RekognitionStreamingHttpAuthSchemeProvider; + 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: RekognitionStreamingHttpAuthSchemeProvider): void { + _httpAuthSchemeProvider = httpAuthSchemeProvider; + }, + httpAuthSchemeProvider(): RekognitionStreamingHttpAuthSchemeProvider { + 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(), + }; +}; diff --git a/clients/client-rekognitionstreaming/src/auth/httpAuthSchemeProvider.ts b/clients/client-rekognitionstreaming/src/auth/httpAuthSchemeProvider.ts new file mode 100644 index 0000000000000..5d6be003f90d9 --- /dev/null +++ b/clients/client-rekognitionstreaming/src/auth/httpAuthSchemeProvider.ts @@ -0,0 +1,145 @@ +// smithy-typescript generated code +import { + AwsSdkSigV4AuthInputConfig, + AwsSdkSigV4AuthResolvedConfig, + AwsSdkSigV4PreviouslyResolved, + resolveAwsSdkSigV4Config, +} from "@aws-sdk/core"; +import { + HandlerExecutionContext, + HttpAuthOption, + HttpAuthScheme, + HttpAuthSchemeParameters, + HttpAuthSchemeParametersProvider, + HttpAuthSchemeProvider, +} from "@smithy/types"; +import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; + +import { + RekognitionStreamingClientConfig, + RekognitionStreamingClientResolvedConfig, +} from "../RekognitionStreamingClient"; + +/** + * @internal + */ +export interface RekognitionStreamingHttpAuthSchemeParameters extends HttpAuthSchemeParameters { + region?: string; +} + +/** + * @internal + */ +export interface RekognitionStreamingHttpAuthSchemeParametersProvider + extends HttpAuthSchemeParametersProvider< + RekognitionStreamingClientResolvedConfig, + HandlerExecutionContext, + RekognitionStreamingHttpAuthSchemeParameters, + object + > {} + +/** + * @internal + */ +export const defaultRekognitionStreamingHttpAuthSchemeParametersProvider = async ( + config: RekognitionStreamingClientResolvedConfig, + context: HandlerExecutionContext, + input: object +): Promise => { + return { + operation: getSmithyContext(context).operation as string, + region: + (await normalizeProvider(config.region)()) || + (() => { + throw new Error("expected `region` to be configured for `aws.auth#sigv4`"); + })(), + }; +}; + +function createAwsAuthSigv4HttpAuthOption( + authParameters: RekognitionStreamingHttpAuthSchemeParameters +): HttpAuthOption { + return { + schemeId: "aws.auth#sigv4", + signingProperties: { + name: "rekognition", + region: authParameters.region, + }, + propertiesExtractor: (config: Partial, context) => ({ + /** + * @internal + */ + signingProperties: { + config, + context, + }, + }), + }; +} + +/** + * @internal + */ +export interface RekognitionStreamingHttpAuthSchemeProvider + extends HttpAuthSchemeProvider {} + +/** + * @internal + */ +export const defaultRekognitionStreamingHttpAuthSchemeProvider: RekognitionStreamingHttpAuthSchemeProvider = ( + authParameters +) => { + const options: HttpAuthOption[] = []; + switch (authParameters.operation) { + default: { + options.push(createAwsAuthSigv4HttpAuthOption(authParameters)); + } + } + return options; +}; + +/** + * @internal + */ +export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + httpAuthSchemes?: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + httpAuthSchemeProvider?: RekognitionStreamingHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + readonly httpAuthSchemes: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + readonly httpAuthSchemeProvider: RekognitionStreamingHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export const resolveHttpAuthSchemeConfig = ( + config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved +): T & HttpAuthSchemeResolvedConfig => { + const config_0 = resolveAwsSdkSigV4Config(config); + return { + ...config_0, + } as T & HttpAuthSchemeResolvedConfig; +}; diff --git a/clients/client-rekognitionstreaming/src/extensionConfiguration.ts b/clients/client-rekognitionstreaming/src/extensionConfiguration.ts index d71b27be1e6c7..d905e101120c0 100644 --- a/clients/client-rekognitionstreaming/src/extensionConfiguration.ts +++ b/clients/client-rekognitionstreaming/src/extensionConfiguration.ts @@ -3,10 +3,13 @@ import { AwsRegionExtensionConfiguration } from "@aws-sdk/types"; import { HttpHandlerExtensionConfiguration } from "@smithy/protocol-http"; import { DefaultExtensionConfiguration } from "@smithy/types"; +import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration"; + /** * @internal */ export interface RekognitionStreamingExtensionConfiguration extends HttpHandlerExtensionConfiguration, DefaultExtensionConfiguration, - AwsRegionExtensionConfiguration {} + AwsRegionExtensionConfiguration, + HttpAuthExtensionConfiguration {} diff --git a/clients/client-rekognitionstreaming/src/runtimeConfig.shared.ts b/clients/client-rekognitionstreaming/src/runtimeConfig.shared.ts index 34fd97689d7c8..e45a30fc0ced6 100644 --- a/clients/client-rekognitionstreaming/src/runtimeConfig.shared.ts +++ b/clients/client-rekognitionstreaming/src/runtimeConfig.shared.ts @@ -1,9 +1,12 @@ // smithy-typescript generated code +import { AwsSdkSigV4Signer } from "@aws-sdk/core"; import { NoOpLogger } from "@smithy/smithy-client"; +import { IdentityProviderConfig } from "@smithy/types"; import { parseUrl } from "@smithy/url-parser"; import { fromBase64, toBase64 } from "@smithy/util-base64"; import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; +import { defaultRekognitionStreamingHttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider"; import { defaultEndpointResolver } from "./endpoint/endpointResolver"; import { RekognitionStreamingClientConfig } from "./RekognitionStreamingClient"; @@ -18,6 +21,14 @@ export const getRuntimeConfig = (config: RekognitionStreamingClientConfig) => { disableHostPrefix: config?.disableHostPrefix ?? false, endpointProvider: config?.endpointProvider ?? defaultEndpointResolver, extensions: config?.extensions ?? [], + httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultRekognitionStreamingHttpAuthSchemeProvider, + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "aws.auth#sigv4", + identityProvider: (ipc: IdentityProviderConfig) => ipc.getIdentityProvider("aws.auth#sigv4"), + signer: new AwsSdkSigV4Signer(), + }, + ], logger: config?.logger ?? new NoOpLogger(), serviceId: config?.serviceId ?? "RekognitionStreaming", urlParser: config?.urlParser ?? parseUrl, diff --git a/clients/client-rekognitionstreaming/src/runtimeExtensions.ts b/clients/client-rekognitionstreaming/src/runtimeExtensions.ts index b76973858e770..c817a40922370 100644 --- a/clients/client-rekognitionstreaming/src/runtimeExtensions.ts +++ b/clients/client-rekognitionstreaming/src/runtimeExtensions.ts @@ -6,6 +6,7 @@ import { import { getHttpHandlerExtensionConfiguration, resolveHttpHandlerRuntimeConfig } from "@smithy/protocol-http"; import { getDefaultExtensionConfiguration, resolveDefaultRuntimeConfig } from "@smithy/smithy-client"; +import { getHttpAuthExtensionConfiguration, resolveHttpAuthRuntimeConfig } from "./auth/httpAuthExtensionConfiguration"; import { RekognitionStreamingExtensionConfiguration } from "./extensionConfiguration"; /** @@ -32,6 +33,7 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...asPartial(getAwsRegionExtensionConfiguration(runtimeConfig)), ...asPartial(getDefaultExtensionConfiguration(runtimeConfig)), ...asPartial(getHttpHandlerExtensionConfiguration(runtimeConfig)), + ...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)), }; extensions.forEach((extension) => extension.configure(extensionConfiguration)); @@ -41,5 +43,6 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...resolveAwsRegionExtensionConfiguration(extensionConfiguration), ...resolveDefaultRuntimeConfig(extensionConfiguration), ...resolveHttpHandlerRuntimeConfig(extensionConfiguration), + ...resolveHttpAuthRuntimeConfig(extensionConfiguration), }; }; diff --git a/clients/client-transcribe-streaming/package.json b/clients/client-transcribe-streaming/package.json index aec4bfc0eb45a..01f3744fe388b 100644 --- a/clients/client-transcribe-streaming/package.json +++ b/clients/client-transcribe-streaming/package.json @@ -31,7 +31,6 @@ "@aws-sdk/middleware-logger": "*", "@aws-sdk/middleware-recursion-detection": "*", "@aws-sdk/middleware-sdk-transcribe-streaming": "*", - "@aws-sdk/middleware-signing": "*", "@aws-sdk/middleware-user-agent": "*", "@aws-sdk/middleware-websocket": "*", "@aws-sdk/region-config-resolver": "*", @@ -64,6 +63,7 @@ "@smithy/util-defaults-mode-browser": "^3.0.13", "@smithy/util-defaults-mode-node": "^3.0.13", "@smithy/util-endpoints": "^2.0.5", + "@smithy/util-middleware": "^3.0.3", "@smithy/util-retry": "^3.0.3", "@smithy/util-utf8": "^3.0.0", "tslib": "^2.6.2" diff --git a/clients/client-transcribe-streaming/src/TranscribeStreamingClient.ts b/clients/client-transcribe-streaming/src/TranscribeStreamingClient.ts index c38e3f776a6f6..40cd42bc7dc74 100644 --- a/clients/client-transcribe-streaming/src/TranscribeStreamingClient.ts +++ b/clients/client-transcribe-streaming/src/TranscribeStreamingClient.ts @@ -13,12 +13,6 @@ import { import { getLoggerPlugin } from "@aws-sdk/middleware-logger"; import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection"; import { getTranscribeStreamingPlugin } from "@aws-sdk/middleware-sdk-transcribe-streaming"; -import { - AwsAuthInputConfig, - AwsAuthResolvedConfig, - getAwsAuthPlugin, - resolveAwsAuthConfig, -} from "@aws-sdk/middleware-signing"; import { getUserAgentPlugin, resolveUserAgentConfig, @@ -26,11 +20,13 @@ import { UserAgentResolvedConfig, } from "@aws-sdk/middleware-user-agent"; import { resolveWebSocketConfig, WebSocketInputConfig, WebSocketResolvedConfig } from "@aws-sdk/middleware-websocket"; -import { - Credentials as __Credentials, - EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider, -} from "@aws-sdk/types"; +import { EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider } from "@aws-sdk/types"; import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver"; +import { + DefaultIdentityProviderConfig, + getHttpAuthSchemeEndpointRuleSetPlugin, + getHttpSigningPlugin, +} from "@smithy/core"; import { EventStreamSerdeInputConfig, EventStreamSerdeResolvedConfig, @@ -47,6 +43,7 @@ import { SmithyResolvedConfiguration as __SmithyResolvedConfiguration, } from "@smithy/smithy-client"; import { + AwsCredentialIdentityProvider, BodyLengthCalculator as __BodyLengthCalculator, CheckOptionalClientConfig as __CheckOptionalClientConfig, ChecksumConstructor as __ChecksumConstructor, @@ -64,6 +61,12 @@ import { UserAgent as __UserAgent, } from "@smithy/types"; +import { + defaultTranscribeStreamingHttpAuthSchemeParametersProvider, + HttpAuthSchemeInputConfig, + HttpAuthSchemeResolvedConfig, + resolveHttpAuthSchemeConfig, +} from "./auth/httpAuthSchemeProvider"; import { StartCallAnalyticsStreamTranscriptionCommandInput, StartCallAnalyticsStreamTranscriptionCommandOutput, @@ -202,15 +205,10 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand /** * Default credentials provider; Not available in browser runtime. + * @deprecated * @internal */ - credentialDefaultProvider?: (input: any) => __Provider<__Credentials>; - - /** - * The function that provides necessary utilities for handling request event stream. - * @internal - */ - eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; + credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider; /** * Value for how many times a request will be made at most in case of retry. @@ -243,6 +241,12 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand * The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK. */ defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>; + + /** + * The function that provides necessary utilities for handling request event stream. + * @internal + */ + eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider; } /** @@ -255,10 +259,10 @@ export type TranscribeStreamingClientConfigType = Partial<__SmithyConfiguration< RegionInputConfig & HostHeaderInputConfig & EndpointInputConfig & - AwsAuthInputConfig & + EventStreamSerdeInputConfig & + HttpAuthSchemeInputConfig & EventStreamInputConfig & WebSocketInputConfig & - EventStreamSerdeInputConfig & ClientInputEndpointParameters; /** * @public @@ -278,10 +282,10 @@ export type TranscribeStreamingClientResolvedConfigType = __SmithyResolvedConfig RegionResolvedConfig & HostHeaderResolvedConfig & EndpointResolvedConfig & - AwsAuthResolvedConfig & + EventStreamSerdeResolvedConfig & + HttpAuthSchemeResolvedConfig & EventStreamResolvedConfig & WebSocketResolvedConfig & - EventStreamSerdeResolvedConfig & ClientResolvedEndpointParameters; /** * @public @@ -335,10 +339,10 @@ export class TranscribeStreamingClient extends __Client< const _config_4 = resolveRegionConfig(_config_3); const _config_5 = resolveHostHeaderConfig(_config_4); const _config_6 = resolveEndpointConfig(_config_5); - const _config_7 = resolveAwsAuthConfig(_config_6); - const _config_8 = resolveEventStreamConfig(_config_7); - const _config_9 = resolveWebSocketConfig(_config_8); - const _config_10 = resolveEventStreamSerdeConfig(_config_9); + const _config_7 = resolveEventStreamSerdeConfig(_config_6); + const _config_8 = resolveHttpAuthSchemeConfig(_config_7); + const _config_9 = resolveEventStreamConfig(_config_8); + const _config_10 = resolveWebSocketConfig(_config_9); const _config_11 = resolveRuntimeExtensions(_config_10, configuration?.extensions || []); super(_config_11); this.config = _config_11; @@ -348,8 +352,17 @@ export class TranscribeStreamingClient extends __Client< this.middlewareStack.use(getHostHeaderPlugin(this.config)); this.middlewareStack.use(getLoggerPlugin(this.config)); this.middlewareStack.use(getRecursionDetectionPlugin(this.config)); - this.middlewareStack.use(getAwsAuthPlugin(this.config)); this.middlewareStack.use(getTranscribeStreamingPlugin(this.config)); + this.middlewareStack.use( + getHttpAuthSchemeEndpointRuleSetPlugin(this.config, { + httpAuthSchemeParametersProvider: defaultTranscribeStreamingHttpAuthSchemeParametersProvider, + identityProviderConfigProvider: async (config: TranscribeStreamingClientResolvedConfig) => + new DefaultIdentityProviderConfig({ + "aws.auth#sigv4": config.credentials, + }), + }) + ); + this.middlewareStack.use(getHttpSigningPlugin(this.config)); } /** diff --git a/clients/client-transcribe-streaming/src/auth/httpAuthExtensionConfiguration.ts b/clients/client-transcribe-streaming/src/auth/httpAuthExtensionConfiguration.ts new file mode 100644 index 0000000000000..0804f922448d2 --- /dev/null +++ b/clients/client-transcribe-streaming/src/auth/httpAuthExtensionConfiguration.ts @@ -0,0 +1,72 @@ +// smithy-typescript generated code +import { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types"; + +import { TranscribeStreamingHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; + +/** + * @internal + */ +export interface HttpAuthExtensionConfiguration { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; + httpAuthSchemes(): HttpAuthScheme[]; + setHttpAuthSchemeProvider(httpAuthSchemeProvider: TranscribeStreamingHttpAuthSchemeProvider): void; + httpAuthSchemeProvider(): TranscribeStreamingHttpAuthSchemeProvider; + setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void; + credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined; +} + +/** + * @internal + */ +export type HttpAuthRuntimeConfig = Partial<{ + httpAuthSchemes: HttpAuthScheme[]; + httpAuthSchemeProvider: TranscribeStreamingHttpAuthSchemeProvider; + 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: TranscribeStreamingHttpAuthSchemeProvider): void { + _httpAuthSchemeProvider = httpAuthSchemeProvider; + }, + httpAuthSchemeProvider(): TranscribeStreamingHttpAuthSchemeProvider { + 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(), + }; +}; diff --git a/clients/client-transcribe-streaming/src/auth/httpAuthSchemeProvider.ts b/clients/client-transcribe-streaming/src/auth/httpAuthSchemeProvider.ts new file mode 100644 index 0000000000000..1fb27105be03c --- /dev/null +++ b/clients/client-transcribe-streaming/src/auth/httpAuthSchemeProvider.ts @@ -0,0 +1,140 @@ +// smithy-typescript generated code +import { + AwsSdkSigV4AuthInputConfig, + AwsSdkSigV4AuthResolvedConfig, + AwsSdkSigV4PreviouslyResolved, + resolveAwsSdkSigV4Config, +} from "@aws-sdk/core"; +import { + HandlerExecutionContext, + HttpAuthOption, + HttpAuthScheme, + HttpAuthSchemeParameters, + HttpAuthSchemeParametersProvider, + HttpAuthSchemeProvider, +} from "@smithy/types"; +import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; + +import { TranscribeStreamingClientConfig, TranscribeStreamingClientResolvedConfig } from "../TranscribeStreamingClient"; + +/** + * @internal + */ +export interface TranscribeStreamingHttpAuthSchemeParameters extends HttpAuthSchemeParameters { + region?: string; +} + +/** + * @internal + */ +export interface TranscribeStreamingHttpAuthSchemeParametersProvider + extends HttpAuthSchemeParametersProvider< + TranscribeStreamingClientResolvedConfig, + HandlerExecutionContext, + TranscribeStreamingHttpAuthSchemeParameters, + object + > {} + +/** + * @internal + */ +export const defaultTranscribeStreamingHttpAuthSchemeParametersProvider = async ( + config: TranscribeStreamingClientResolvedConfig, + context: HandlerExecutionContext, + input: object +): Promise => { + return { + operation: getSmithyContext(context).operation as string, + region: + (await normalizeProvider(config.region)()) || + (() => { + throw new Error("expected `region` to be configured for `aws.auth#sigv4`"); + })(), + }; +}; + +function createAwsAuthSigv4HttpAuthOption(authParameters: TranscribeStreamingHttpAuthSchemeParameters): HttpAuthOption { + return { + schemeId: "aws.auth#sigv4", + signingProperties: { + name: "transcribe", + region: authParameters.region, + }, + propertiesExtractor: (config: Partial, context) => ({ + /** + * @internal + */ + signingProperties: { + config, + context, + }, + }), + }; +} + +/** + * @internal + */ +export interface TranscribeStreamingHttpAuthSchemeProvider + extends HttpAuthSchemeProvider {} + +/** + * @internal + */ +export const defaultTranscribeStreamingHttpAuthSchemeProvider: TranscribeStreamingHttpAuthSchemeProvider = ( + authParameters +) => { + const options: HttpAuthOption[] = []; + switch (authParameters.operation) { + default: { + options.push(createAwsAuthSigv4HttpAuthOption(authParameters)); + } + } + return options; +}; + +/** + * @internal + */ +export interface HttpAuthSchemeInputConfig extends AwsSdkSigV4AuthInputConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + httpAuthSchemes?: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + httpAuthSchemeProvider?: TranscribeStreamingHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export interface HttpAuthSchemeResolvedConfig extends AwsSdkSigV4AuthResolvedConfig { + /** + * Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + readonly httpAuthSchemes: HttpAuthScheme[]; + + /** + * Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + readonly httpAuthSchemeProvider: TranscribeStreamingHttpAuthSchemeProvider; +} + +/** + * @internal + */ +export const resolveHttpAuthSchemeConfig = ( + config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved +): T & HttpAuthSchemeResolvedConfig => { + const config_0 = resolveAwsSdkSigV4Config(config); + return { + ...config_0, + } as T & HttpAuthSchemeResolvedConfig; +}; diff --git a/clients/client-transcribe-streaming/src/extensionConfiguration.ts b/clients/client-transcribe-streaming/src/extensionConfiguration.ts index d33d8d32fa28a..76a86b118d3c1 100644 --- a/clients/client-transcribe-streaming/src/extensionConfiguration.ts +++ b/clients/client-transcribe-streaming/src/extensionConfiguration.ts @@ -3,10 +3,13 @@ import { AwsRegionExtensionConfiguration } from "@aws-sdk/types"; import { HttpHandlerExtensionConfiguration } from "@smithy/protocol-http"; import { DefaultExtensionConfiguration } from "@smithy/types"; +import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration"; + /** * @internal */ export interface TranscribeStreamingExtensionConfiguration extends HttpHandlerExtensionConfiguration, DefaultExtensionConfiguration, - AwsRegionExtensionConfiguration {} + AwsRegionExtensionConfiguration, + HttpAuthExtensionConfiguration {} diff --git a/clients/client-transcribe-streaming/src/runtimeConfig.browser.ts b/clients/client-transcribe-streaming/src/runtimeConfig.browser.ts index 879dc726a9e83..239b90ced4566 100644 --- a/clients/client-transcribe-streaming/src/runtimeConfig.browser.ts +++ b/clients/client-transcribe-streaming/src/runtimeConfig.browser.ts @@ -3,10 +3,10 @@ import packageInfo from "../package.json"; // eslint-disable-line import { Sha256 } from "@aws-crypto/sha256-browser"; -import { eventStreamPayloadHandler } from "@aws-sdk/middleware-sdk-transcribe-streaming"; import { WebSocketFetchHandlerOptions, WebSocketFetchHandler as WebSocketRequestHandler, + eventStreamPayloadHandlerProvider, } from "@aws-sdk/middleware-websocket"; import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser"; import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver"; @@ -38,7 +38,7 @@ export const getRuntimeConfig = (config: TranscribeStreamingClientConfig) => { defaultUserAgentProvider: config?.defaultUserAgentProvider ?? defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }), - eventStreamPayloadHandlerProvider: config?.eventStreamPayloadHandlerProvider ?? (() => eventStreamPayloadHandler), + eventStreamPayloadHandlerProvider: config?.eventStreamPayloadHandlerProvider ?? eventStreamPayloadHandlerProvider, eventStreamSerdeProvider: config?.eventStreamSerdeProvider ?? eventStreamSerdeProvider, maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS, region: config?.region ?? invalidProvider("Region is missing"), diff --git a/clients/client-transcribe-streaming/src/runtimeConfig.native.ts b/clients/client-transcribe-streaming/src/runtimeConfig.native.ts index 2e896b0999573..1f4bc2b396c4d 100644 --- a/clients/client-transcribe-streaming/src/runtimeConfig.native.ts +++ b/clients/client-transcribe-streaming/src/runtimeConfig.native.ts @@ -1,6 +1,6 @@ // smithy-typescript generated code import { Sha256 } from "@aws-crypto/sha256-js"; -import { eventStreamPayloadHandler } from "@aws-sdk/middleware-sdk-transcribe-streaming"; +import { invalidFunction } from "@smithy/invalid-dependency"; import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser"; import { TranscribeStreamingClientConfig } from "./TranscribeStreamingClient"; @@ -14,7 +14,9 @@ export const getRuntimeConfig = (config: TranscribeStreamingClientConfig) => { ...browserDefaults, ...config, runtime: "react-native", - eventStreamPayloadHandlerProvider: config?.eventStreamPayloadHandlerProvider ?? (() => eventStreamPayloadHandler), + eventStreamPayloadHandlerProvider: + config?.eventStreamPayloadHandlerProvider ?? + (() => ({ handle: invalidFunction("event stream request is not supported in ReactNative.") })), sha256: config?.sha256 ?? Sha256, }; }; diff --git a/clients/client-transcribe-streaming/src/runtimeConfig.shared.ts b/clients/client-transcribe-streaming/src/runtimeConfig.shared.ts index 3f1d04ae68bb8..1a3d938e2729f 100644 --- a/clients/client-transcribe-streaming/src/runtimeConfig.shared.ts +++ b/clients/client-transcribe-streaming/src/runtimeConfig.shared.ts @@ -1,9 +1,12 @@ // smithy-typescript generated code +import { AwsSdkSigV4Signer } from "@aws-sdk/core"; import { NoOpLogger } from "@smithy/smithy-client"; +import { IdentityProviderConfig } from "@smithy/types"; import { parseUrl } from "@smithy/url-parser"; import { fromBase64, toBase64 } from "@smithy/util-base64"; import { fromUtf8, toUtf8 } from "@smithy/util-utf8"; +import { defaultTranscribeStreamingHttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider"; import { defaultEndpointResolver } from "./endpoint/endpointResolver"; import { TranscribeStreamingClientConfig } from "./TranscribeStreamingClient"; @@ -18,6 +21,14 @@ export const getRuntimeConfig = (config: TranscribeStreamingClientConfig) => { disableHostPrefix: config?.disableHostPrefix ?? false, endpointProvider: config?.endpointProvider ?? defaultEndpointResolver, extensions: config?.extensions ?? [], + httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultTranscribeStreamingHttpAuthSchemeProvider, + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "aws.auth#sigv4", + identityProvider: (ipc: IdentityProviderConfig) => ipc.getIdentityProvider("aws.auth#sigv4"), + signer: new AwsSdkSigV4Signer(), + }, + ], logger: config?.logger ?? new NoOpLogger(), serviceId: config?.serviceId ?? "Transcribe Streaming", urlParser: config?.urlParser ?? parseUrl, diff --git a/clients/client-transcribe-streaming/src/runtimeExtensions.ts b/clients/client-transcribe-streaming/src/runtimeExtensions.ts index ed9af1d01b563..d4a610a0b56ff 100644 --- a/clients/client-transcribe-streaming/src/runtimeExtensions.ts +++ b/clients/client-transcribe-streaming/src/runtimeExtensions.ts @@ -6,6 +6,7 @@ import { import { getHttpHandlerExtensionConfiguration, resolveHttpHandlerRuntimeConfig } from "@smithy/protocol-http"; import { getDefaultExtensionConfiguration, resolveDefaultRuntimeConfig } from "@smithy/smithy-client"; +import { getHttpAuthExtensionConfiguration, resolveHttpAuthRuntimeConfig } from "./auth/httpAuthExtensionConfiguration"; import { TranscribeStreamingExtensionConfiguration } from "./extensionConfiguration"; /** @@ -32,6 +33,7 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...asPartial(getAwsRegionExtensionConfiguration(runtimeConfig)), ...asPartial(getDefaultExtensionConfiguration(runtimeConfig)), ...asPartial(getHttpHandlerExtensionConfiguration(runtimeConfig)), + ...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)), }; extensions.forEach((extension) => extension.configure(extensionConfiguration)); @@ -41,5 +43,6 @@ export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: Runtime ...resolveAwsRegionExtensionConfiguration(extensionConfiguration), ...resolveDefaultRuntimeConfig(extensionConfiguration), ...resolveHttpHandlerRuntimeConfig(extensionConfiguration), + ...resolveHttpAuthRuntimeConfig(extensionConfiguration), }; }; diff --git a/codegen/sdk-codegen/build.gradle.kts b/codegen/sdk-codegen/build.gradle.kts index d145c6727ae35..3480ced0db777 100644 --- a/codegen/sdk-codegen/build.gradle.kts +++ b/codegen/sdk-codegen/build.gradle.kts @@ -107,17 +107,12 @@ tasks.register("generate-smithy-build") { .readText() ).expectObjectNode() val nonExperimentalIdentityAndAuthServices = setOf( - // Services with EventStream input - "Lex Runtime V2", - "RekognitionStreaming", - "Transcribe Streaming", // Endpoint Ruleset Auth Scheme Resolvers "EventBridge", "CloudFront KeyValueStore", // S3 "S3", ) - check(nonExperimentalIdentityAndAuthServices.size == 6) val projectionContents = Node.objectNodeBuilder() .withMember("imports", Node.fromStrings("${models.getAbsolutePath()}${File.separator}${file.name}")) .withMember("plugins", Node.objectNode()