From 9a6a5ffa62f5ae000d510ffe2de248f1a884b9b6 Mon Sep 17 00:00:00 2001 From: Steven Yuan Date: Mon, 13 Nov 2023 12:37:53 -0800 Subject: [PATCH] chore(temp codegen): generate clients --- clients/client-codecatalyst/package.json | 4 +- .../src/CodeCatalystClient.ts | 39 +++++- .../auth/httpAuthExtensionConfiguration.ts | 72 ++++++++++ .../src/auth/httpAuthSchemeProvider.ts | 126 ++++++++++++++++++ .../src/extensionConfiguration.ts | 5 +- .../src/runtimeConfig.browser.ts | 13 ++ .../src/runtimeConfig.shared.ts | 11 ++ .../client-codecatalyst/src/runtimeConfig.ts | 11 ++ .../src/runtimeExtensions.ts | 3 + .../typescript/codegen/AddBuiltinPlugins.java | 1 - .../typescript/codegen/AwsTraitsUtils.java | 6 +- .../integration/AddAwsDefaultSigningName.java | 73 ++++++++++ ....codegen.integration.TypeScriptIntegration | 1 + 13 files changed, 353 insertions(+), 12 deletions(-) create mode 100644 clients/client-codecatalyst/src/auth/httpAuthExtensionConfiguration.ts create mode 100644 clients/client-codecatalyst/src/auth/httpAuthSchemeProvider.ts create mode 100644 codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddAwsDefaultSigningName.java diff --git a/clients/client-codecatalyst/package.json b/clients/client-codecatalyst/package.json index dd23de8f5663b..21d2e389b6d8f 100644 --- a/clients/client-codecatalyst/package.json +++ b/clients/client-codecatalyst/package.json @@ -25,14 +25,15 @@ "@aws-sdk/middleware-host-header": "*", "@aws-sdk/middleware-logger": "*", "@aws-sdk/middleware-recursion-detection": "*", - "@aws-sdk/middleware-token": "*", "@aws-sdk/middleware-user-agent": "*", "@aws-sdk/region-config-resolver": "*", + "@aws-sdk/token-providers": "*", "@aws-sdk/types": "*", "@aws-sdk/util-endpoints": "*", "@aws-sdk/util-user-agent-browser": "*", "@aws-sdk/util-user-agent-node": "*", "@smithy/config-resolver": "^2.0.17", + "@smithy/core": "^0.0.1", "@smithy/fetch-http-handler": "^2.2.5", "@smithy/hash-node": "^2.0.14", "@smithy/invalid-dependency": "^2.0.12", @@ -53,6 +54,7 @@ "@smithy/util-defaults-mode-browser": "^2.0.18", "@smithy/util-defaults-mode-node": "^2.0.24", "@smithy/util-endpoints": "^1.0.3", + "@smithy/util-middleware": "^2.0.5", "@smithy/util-retry": "^2.0.5", "@smithy/util-utf8": "^2.0.2", "tslib": "^2.5.0" diff --git a/clients/client-codecatalyst/src/CodeCatalystClient.ts b/clients/client-codecatalyst/src/CodeCatalystClient.ts index d3c8b80aebc27..a16a3137156e2 100644 --- a/clients/client-codecatalyst/src/CodeCatalystClient.ts +++ b/clients/client-codecatalyst/src/CodeCatalystClient.ts @@ -7,7 +7,6 @@ import { } from "@aws-sdk/middleware-host-header"; import { getLoggerPlugin } from "@aws-sdk/middleware-logger"; import { getRecursionDetectionPlugin } from "@aws-sdk/middleware-recursion-detection"; -import { getTokenPlugin, resolveTokenConfig, TokenInputConfig, TokenResolvedConfig } from "@aws-sdk/middleware-token"; import { getUserAgentPlugin, resolveUserAgentConfig, @@ -15,6 +14,11 @@ import { UserAgentResolvedConfig, } from "@aws-sdk/middleware-user-agent"; 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"; @@ -44,6 +48,12 @@ import { UserAgent as __UserAgent, } from "@smithy/types"; +import { + defaultCodeCatalystHttpAuthSchemeParametersProvider, + HttpAuthSchemeInputConfig, + HttpAuthSchemeResolvedConfig, + resolveHttpAuthSchemeConfig, +} from "./auth/httpAuthSchemeProvider"; import { CreateAccessTokenCommandInput, CreateAccessTokenCommandOutput } from "./commands/CreateAccessTokenCommand"; import { CreateDevEnvironmentCommandInput, @@ -338,8 +348,8 @@ export type CodeCatalystClientConfigType = Partial<__SmithyConfiguration<__HttpH EndpointInputConfig & RetryInputConfig & HostHeaderInputConfig & - TokenInputConfig & UserAgentInputConfig & + HttpAuthSchemeInputConfig & ClientInputEndpointParameters; /** * @public @@ -358,8 +368,8 @@ export type CodeCatalystClientResolvedConfigType = __SmithyResolvedConfiguration EndpointResolvedConfig & RetryResolvedConfig & HostHeaderResolvedConfig & - TokenResolvedConfig & UserAgentResolvedConfig & + HttpAuthSchemeResolvedConfig & ClientResolvedEndpointParameters; /** * @public @@ -534,6 +544,17 @@ export class CodeCatalystClient extends __Client< */ readonly config: CodeCatalystClientResolvedConfig; + private getDefaultHttpAuthSchemeParametersProvider() { + return defaultCodeCatalystHttpAuthSchemeParametersProvider; + } + + private getIdentityProviderConfigProvider() { + return async (config: CodeCatalystClientResolvedConfig) => + new DefaultIdentityProviderConfig({ + "smithy.api#httpBearerAuth": config.token, + }); + } + constructor(...[configuration]: __CheckOptionalClientConfig) { const _config_0 = __getRuntimeConfig(configuration || {}); const _config_1 = resolveClientEndpointParameters(_config_0); @@ -541,8 +562,8 @@ export class CodeCatalystClient extends __Client< const _config_3 = resolveEndpointConfig(_config_2); const _config_4 = resolveRetryConfig(_config_3); const _config_5 = resolveHostHeaderConfig(_config_4); - const _config_6 = resolveTokenConfig(_config_5); - 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; @@ -551,8 +572,14 @@ export class CodeCatalystClient extends __Client< this.middlewareStack.use(getHostHeaderPlugin(this.config)); this.middlewareStack.use(getLoggerPlugin(this.config)); this.middlewareStack.use(getRecursionDetectionPlugin(this.config)); - this.middlewareStack.use(getTokenPlugin(this.config)); this.middlewareStack.use(getUserAgentPlugin(this.config)); + this.middlewareStack.use( + getHttpAuthSchemeEndpointRuleSetPlugin(this.config, { + identityProviderConfigProvider: this.getIdentityProviderConfigProvider(), + httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(), + }) + ); + this.middlewareStack.use(getHttpSigningPlugin(this.config)); } /** diff --git a/clients/client-codecatalyst/src/auth/httpAuthExtensionConfiguration.ts b/clients/client-codecatalyst/src/auth/httpAuthExtensionConfiguration.ts new file mode 100644 index 0000000000000..30a5417819a22 --- /dev/null +++ b/clients/client-codecatalyst/src/auth/httpAuthExtensionConfiguration.ts @@ -0,0 +1,72 @@ +// smithy-typescript generated code +import { HttpAuthScheme, TokenIdentity, TokenIdentityProvider } from "@smithy/types"; + +import { CodeCatalystHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; + +/** + * @internal + */ +export interface HttpAuthExtensionConfiguration { + setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; + httpAuthSchemes(): HttpAuthScheme[]; + setHttpAuthSchemeProvider(httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider): void; + httpAuthSchemeProvider(): CodeCatalystHttpAuthSchemeProvider; + setToken(token: TokenIdentity | TokenIdentityProvider): void; + token(): TokenIdentity | TokenIdentityProvider | undefined; +} + +/** + * @internal + */ +export type HttpAuthRuntimeConfig = Partial<{ + httpAuthSchemes: HttpAuthScheme[]; + httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider; + token: TokenIdentity | TokenIdentityProvider; +}>; + +/** + * @internal + */ +export const getHttpAuthExtensionConfiguration = ( + runtimeConfig: HttpAuthRuntimeConfig +): HttpAuthExtensionConfiguration => { + const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!; + let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!; + let _token = runtimeConfig.token; + 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: CodeCatalystHttpAuthSchemeProvider): void { + _httpAuthSchemeProvider = httpAuthSchemeProvider; + }, + httpAuthSchemeProvider(): CodeCatalystHttpAuthSchemeProvider { + return _httpAuthSchemeProvider; + }, + setToken(token: TokenIdentity | TokenIdentityProvider): void { + _token = token; + }, + token(): TokenIdentity | TokenIdentityProvider | undefined { + return _token; + }, + }; +}; + +/** + * @internal + */ +export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => { + return { + httpAuthSchemes: config.httpAuthSchemes(), + httpAuthSchemeProvider: config.httpAuthSchemeProvider(), + token: config.token(), + }; +}; diff --git a/clients/client-codecatalyst/src/auth/httpAuthSchemeProvider.ts b/clients/client-codecatalyst/src/auth/httpAuthSchemeProvider.ts new file mode 100644 index 0000000000000..f11fcf7533492 --- /dev/null +++ b/clients/client-codecatalyst/src/auth/httpAuthSchemeProvider.ts @@ -0,0 +1,126 @@ +// smithy-typescript generated code +import { doesIdentityRequireRefresh, isIdentityExpired, memoizeIdentityProvider } from "@smithy/core"; +import { + HandlerExecutionContext, + HttpAuthOption, + HttpAuthScheme, + HttpAuthSchemeParameters, + HttpAuthSchemeParametersProvider, + HttpAuthSchemeProvider, + TokenIdentity, + TokenIdentityProvider, +} from "@smithy/types"; +import { getSmithyContext } from "@smithy/util-middleware"; + +import { CodeCatalystClientResolvedConfig } from "../CodeCatalystClient"; + +/** + * @internal + */ +export interface CodeCatalystHttpAuthSchemeParameters extends HttpAuthSchemeParameters {} + +/** + * @internal + */ +export interface CodeCatalystHttpAuthSchemeParametersProvider + extends HttpAuthSchemeParametersProvider< + CodeCatalystClientResolvedConfig, + HandlerExecutionContext, + CodeCatalystHttpAuthSchemeParameters, + object + > {} + +/** + * @internal + */ +export const defaultCodeCatalystHttpAuthSchemeParametersProvider = async ( + config: CodeCatalystClientResolvedConfig, + context: HandlerExecutionContext, + input: object +): Promise => { + return { + operation: getSmithyContext(context).operation as string, + }; +}; + +function createSmithyApiHttpBearerAuthHttpAuthOption( + authParameters: CodeCatalystHttpAuthSchemeParameters +): HttpAuthOption { + return { + schemeId: "smithy.api#httpBearerAuth", + }; +} + +/** + * @internal + */ +export interface CodeCatalystHttpAuthSchemeProvider + extends HttpAuthSchemeProvider {} + +/** + * @internal + */ +export const defaultCodeCatalystHttpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider = (authParameters) => { + const options: HttpAuthOption[] = []; + switch (authParameters.operation) { + default: { + options.push(createSmithyApiHttpBearerAuthHttpAuthOption(authParameters)); + } + } + return options; +}; + +/** + * @internal + */ +export interface HttpAuthSchemeInputConfig { + /** + * experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + httpAuthSchemes?: HttpAuthScheme[]; + + /** + * experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + httpAuthSchemeProvider?: CodeCatalystHttpAuthSchemeProvider; + + /** + * The token used to authenticate requests. + */ + token?: TokenIdentity | TokenIdentityProvider; +} + +/** + * @internal + */ +export interface HttpAuthSchemeResolvedConfig { + /** + * experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. + * @internal + */ + readonly httpAuthSchemes: HttpAuthScheme[]; + + /** + * experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. + * @internal + */ + readonly httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider; + + /** + * The token used to authenticate requests. + */ + readonly token?: TokenIdentityProvider; +} + +/** + * @internal + */ +export const resolveHttpAuthSchemeConfig = (config: HttpAuthSchemeInputConfig): HttpAuthSchemeResolvedConfig => { + const token = memoizeIdentityProvider(config.token, isIdentityExpired, doesIdentityRequireRefresh); + return { + ...config, + token, + } as HttpAuthSchemeResolvedConfig; +}; diff --git a/clients/client-codecatalyst/src/extensionConfiguration.ts b/clients/client-codecatalyst/src/extensionConfiguration.ts index 7bcb9972d2318..9574c77b1b5de 100644 --- a/clients/client-codecatalyst/src/extensionConfiguration.ts +++ b/clients/client-codecatalyst/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 CodeCatalystExtensionConfiguration extends HttpHandlerExtensionConfiguration, DefaultExtensionConfiguration, - AwsRegionExtensionConfiguration {} + AwsRegionExtensionConfiguration, + HttpAuthExtensionConfiguration {} diff --git a/clients/client-codecatalyst/src/runtimeConfig.browser.ts b/clients/client-codecatalyst/src/runtimeConfig.browser.ts index 27d40ffd6d3d0..211f1e9e73f20 100644 --- a/clients/client-codecatalyst/src/runtimeConfig.browser.ts +++ b/clients/client-codecatalyst/src/runtimeConfig.browser.ts @@ -5,7 +5,9 @@ import packageInfo from "../package.json"; // eslint-disable-line import { Sha256 } from "@aws-crypto/sha256-browser"; import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser"; import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver"; +import { HttpBearerAuthSigner } from "@smithy/core"; import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler"; +import { IdentityProviderConfig } from "@smithy/types"; import { calculateBodyLength } from "@smithy/util-body-length-browser"; import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@smithy/util-retry"; import { CodeCatalystClientConfig } from "./CodeCatalystClient"; @@ -29,6 +31,17 @@ export const getRuntimeConfig = (config: CodeCatalystClientConfig) => { defaultUserAgentProvider: config?.defaultUserAgentProvider ?? defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }), + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "smithy.api#httpBearerAuth", + identityProvider: (config: IdentityProviderConfig) => + config.getIdentityProvider("smithy.api#httpBearerAuth") || + (async () => { + throw new Error("`token` is missing"); + }), + signer: new HttpBearerAuthSigner(), + }, + ], maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS, requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider), retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE), diff --git a/clients/client-codecatalyst/src/runtimeConfig.shared.ts b/clients/client-codecatalyst/src/runtimeConfig.shared.ts index b943dc0d21d96..6f7761ab96cee 100644 --- a/clients/client-codecatalyst/src/runtimeConfig.shared.ts +++ b/clients/client-codecatalyst/src/runtimeConfig.shared.ts @@ -1,9 +1,12 @@ // smithy-typescript generated code +import { HttpBearerAuthSigner } from "@smithy/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 { defaultCodeCatalystHttpAuthSchemeProvider } from "./auth/httpAuthSchemeProvider"; import { CodeCatalystClientConfig } from "./CodeCatalystClient"; import { defaultEndpointResolver } from "./endpoint/endpointResolver"; @@ -18,6 +21,14 @@ export const getRuntimeConfig = (config: CodeCatalystClientConfig) => { disableHostPrefix: config?.disableHostPrefix ?? false, endpointProvider: config?.endpointProvider ?? defaultEndpointResolver, extensions: config?.extensions ?? [], + httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultCodeCatalystHttpAuthSchemeProvider, + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "smithy.api#httpBearerAuth", + identityProvider: (config: IdentityProviderConfig) => config.getIdentityProvider("smithy.api#httpBearerAuth"), + signer: new HttpBearerAuthSigner(), + }, + ], logger: config?.logger ?? new NoOpLogger(), serviceId: config?.serviceId ?? "CodeCatalyst", urlParser: config?.urlParser ?? parseUrl, diff --git a/clients/client-codecatalyst/src/runtimeConfig.ts b/clients/client-codecatalyst/src/runtimeConfig.ts index 0d76cdde0898e..938acd39bac6f 100644 --- a/clients/client-codecatalyst/src/runtimeConfig.ts +++ b/clients/client-codecatalyst/src/runtimeConfig.ts @@ -3,15 +3,18 @@ import packageInfo from "../package.json"; // eslint-disable-line import { emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core"; +import { nodeProvider } from "@aws-sdk/token-providers"; import { defaultUserAgent } from "@aws-sdk/util-user-agent-node"; import { NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, } from "@smithy/config-resolver"; +import { HttpBearerAuthSigner } from "@smithy/core"; import { Hash } from "@smithy/hash-node"; import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@smithy/middleware-retry"; import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider"; import { NodeHttpHandler as RequestHandler, streamCollector } from "@smithy/node-http-handler"; +import { IdentityProviderConfig } from "@smithy/types"; import { calculateBodyLength } from "@smithy/util-body-length-node"; import { DEFAULT_RETRY_MODE } from "@smithy/util-retry"; import { CodeCatalystClientConfig } from "./CodeCatalystClient"; @@ -38,6 +41,14 @@ export const getRuntimeConfig = (config: CodeCatalystClientConfig) => { defaultUserAgentProvider: config?.defaultUserAgentProvider ?? defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }), + httpAuthSchemes: config?.httpAuthSchemes ?? [ + { + schemeId: "smithy.api#httpBearerAuth", + identityProvider: (config: IdentityProviderConfig) => + config.getIdentityProvider("smithy.api#httpBearerAuth") || nodeProvider, + signer: new HttpBearerAuthSigner(), + }, + ], maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS), requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider), retryMode: diff --git a/clients/client-codecatalyst/src/runtimeExtensions.ts b/clients/client-codecatalyst/src/runtimeExtensions.ts index 0e9ccbc4a0219..9a3400cfdef1f 100644 --- a/clients/client-codecatalyst/src/runtimeExtensions.ts +++ b/clients/client-codecatalyst/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 { CodeCatalystExtensionConfiguration } 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/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java index 78455a23f5c49..a9671af5ba0f1 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java @@ -50,7 +50,6 @@ public List getClientPlugins() { RuntimeClientPlugin.builder() .withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Region", HAS_CONFIG) .servicePredicate((m, s) -> isAwsService(s) || isSigV4Service(s)) - .settingsPredicate((m, s, settings) -> !settings.getExperimentalIdentityAndAuth()) .build(), // Only one of Endpoints or CustomEndpoints should be used RuntimeClientPlugin.builder() diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsTraitsUtils.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsTraitsUtils.java index 18167fe6962e4..069071f05ed82 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsTraitsUtils.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsTraitsUtils.java @@ -28,7 +28,7 @@ * Utility methods related to AWS traits. */ @SmithyInternalApi -final class AwsTraitsUtils { +public final class AwsTraitsUtils { private AwsTraitsUtils() {} @@ -36,7 +36,7 @@ static boolean isAwsService(TypeScriptSettings settings, Model model) { return isAwsService(settings.getService(model)); } - static boolean isAwsService(ServiceShape serviceShape) { + public static boolean isAwsService(ServiceShape serviceShape) { return serviceShape.hasTrait(ServiceTrait.class); } @@ -44,7 +44,7 @@ static boolean isSigV4Service(TypeScriptSettings settings, Model model) { return isSigV4Service(settings.getService(model)); } - static boolean isSigV4Service(ServiceShape serviceShape) { + public static boolean isSigV4Service(ServiceShape serviceShape) { return serviceShape.hasTrait(SigV4Trait.class); } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddAwsDefaultSigningName.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddAwsDefaultSigningName.java new file mode 100644 index 0000000000000..f366a8e574e19 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddAwsDefaultSigningName.java @@ -0,0 +1,73 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.aws.typescript.codegen.auth.http.integration; + +import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isAwsService; +import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isSigV4Service; + +import java.util.logging.Logger; +import software.amazon.smithy.aws.traits.ServiceTrait; +import software.amazon.smithy.aws.traits.auth.SigV4Trait; +import software.amazon.smithy.aws.typescript.codegen.AddAwsAuthPlugin; +import software.amazon.smithy.codegen.core.SymbolProvider; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; +import software.amazon.smithy.typescript.codegen.TypeScriptWriter; +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Configure clients with Default AWS Signing Name. + * + * This is the experimental behavior for `experimentalIdentityAndAuth`. + */ +@SmithyInternalApi +public final class AddAwsDefaultSigningName implements TypeScriptIntegration { + private static final Logger LOGGER = Logger.getLogger(AddAwsAuthPlugin.class.getName()); + + /** + * Integration should only be used if `experimentalIdentityAndAuth` flag is true. + */ + @Override + public boolean matchesSettings(TypeScriptSettings settings) { + return settings.getExperimentalIdentityAndAuth(); + } + + @Override + public void addConfigInterfaceFields( + TypeScriptSettings settings, + Model model, + SymbolProvider symbolProvider, + TypeScriptWriter writer + ) { + ServiceShape service = settings.getService(model); + // Do nothing if service doesn't use sigv4 and is not an AWS service + if (!isSigV4Service(service) && !isAwsService(service)) { + return; + } + + // Write config field if service uses sigv4 and is not an AWS service + if (isSigV4Service(service) && !isAwsService(service)) { + writer + .writeDocs("The service name to use as the signing service for AWS Auth\n@internal") + .write("signingName?: string;\n"); + } + + // Set default name setting for service based on SigV4 and AWS Service traits + try { + ServiceTrait serviceTrait = service.getTrait(ServiceTrait.class).get(); + settings.setDefaultSigningName( + service.getTrait(SigV4Trait.class) + .map(SigV4Trait::getName) + .orElse(serviceTrait.getArnNamespace()) + ); + } catch (Exception e) { + LOGGER.warning("Unable to set service default signing name. A SigV4 or Service trait is needed."); + } + } + +} diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration index 5ab4b6c37bc02..83a28e5441e7a 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration @@ -26,3 +26,4 @@ software.amazon.smithy.aws.typescript.codegen.AddHttpChecksumDependency software.amazon.smithy.aws.typescript.codegen.AddEventBridgePlugin software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsCustomizeHttpBearerTokenAuthPlugin software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsCustomizeSigv4AuthPlugin +software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AddAwsDefaultSigningName