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

chore(codegen): move eventstream services to id-auth sra #6340

Merged
merged 1 commit into from
Jul 31, 2024
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
2 changes: 1 addition & 1 deletion clients/client-lex-runtime-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down Expand Up @@ -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",
Expand Down
63 changes: 38 additions & 25 deletions clients/client-lex-runtime-v2/src/LexRuntimeV2Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,6 +41,7 @@ import {
SmithyResolvedConfiguration as __SmithyResolvedConfiguration,
} from "@smithy/smithy-client";
import {
AwsCredentialIdentityProvider,
BodyLengthCalculator as __BodyLengthCalculator,
CheckOptionalClientConfig as __CheckOptionalClientConfig,
ChecksumConstructor as __ChecksumConstructor,
Expand All @@ -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";
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -260,9 +264,9 @@ export type LexRuntimeV2ClientConfigType = Partial<__SmithyConfiguration<__HttpH
RegionInputConfig &
HostHeaderInputConfig &
EndpointInputConfig<EndpointParameters> &
AwsAuthInputConfig &
EventStreamInputConfig &
EventStreamSerdeInputConfig &
HttpAuthSchemeInputConfig &
EventStreamInputConfig &
ClientInputEndpointParameters;
/**
* @public
Expand All @@ -282,9 +286,9 @@ export type LexRuntimeV2ClientResolvedConfigType = __SmithyResolvedConfiguration
RegionResolvedConfig &
HostHeaderResolvedConfig &
EndpointResolvedConfig<EndpointParameters> &
AwsAuthResolvedConfig &
EventStreamResolvedConfig &
EventStreamSerdeResolvedConfig &
HttpAuthSchemeResolvedConfig &
EventStreamResolvedConfig &
ClientResolvedEndpointParameters;
/**
* @public
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand Down
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 { 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(),
};
};
138 changes: 138 additions & 0 deletions clients/client-lex-runtime-v2/src/auth/httpAuthSchemeProvider.ts
Original file line number Diff line number Diff line change
@@ -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<LexRuntimeV2HttpAuthSchemeParameters> => {
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<LexRuntimeV2ClientConfig>, context) => ({
/**
* @internal
*/
signingProperties: {
config,
context,
},
}),
};
}

/**
* @internal
*/
export interface LexRuntimeV2HttpAuthSchemeProvider
extends HttpAuthSchemeProvider<LexRuntimeV2HttpAuthSchemeParameters> {}

/**
* @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 = <T>(
config: T & HttpAuthSchemeInputConfig & AwsSdkSigV4PreviouslyResolved
): T & HttpAuthSchemeResolvedConfig => {
const config_0 = resolveAwsSdkSigV4Config(config);
return {
...config_0,
} as T & HttpAuthSchemeResolvedConfig;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
1 change: 0 additions & 1 deletion clients/client-lex-runtime-v2/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Loading
Loading