From 3f4f8a075c998af1b22a2c5c76d766c5c5293f1a Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 2 May 2024 21:20:34 +0000 Subject: [PATCH] chore(codegen): add dependencies required by default credential providers --- .../typescript/codegen/AddAwsAuthPlugin.java | 1 + .../codegen/AwsCredentialProviderUtils.java | 45 +++++++++++++++++++ .../aws/typescript/codegen/AwsDependency.java | 1 + .../integration/AddSTSAuthCustomizations.java | 3 ++ .../integration/AwsSdkCustomizeSigV4Auth.java | 2 + 5 files changed, 52 insertions(+) create mode 100644 codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsCredentialProviderUtils.java diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java index 6f7b5140d7e8e..bc2529cfedb3d 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsAuthPlugin.java @@ -212,6 +212,7 @@ public Map> getRuntimeConfigWriters( .addImport("defaultProvider", "credentialDefaultProvider", AwsDependency.CREDENTIAL_PROVIDER_NODE) .write("credentialDefaultProvider"); + AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(service, writer); } ); default: diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsCredentialProviderUtils.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsCredentialProviderUtils.java new file mode 100644 index 0000000000000..387386b875519 --- /dev/null +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsCredentialProviderUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + + package software.amazon.smithy.aws.typescript.codegen; + +import software.amazon.smithy.model.shapes.ServiceShape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.typescript.codegen.TypeScriptWriter; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Utility methods related to AWS traits. + */ +@SmithyInternalApi +public final class AwsCredentialProviderUtils { + + private AwsCredentialProviderUtils() {} + + /** + * Adds dependencies required by the default credential provider. + * The dependencies are skipped in first party credential providers to avoid circular dependency issue. + */ + public static void addAwsCredentialProviderDependencies(ServiceShape service, TypeScriptWriter writer) { + if (!service.getId().equals(ShapeId.from("com.amazonaws.ssooidc#AWSSSOOIDCService"))) { + // SSO OIDC client is required in Sso credential provider + writer.addDependency(AwsDependency.SSO_OIDC_CLIENT); + } + if (!service.getId().equals(ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"))) { + // STS client is required in Ini and WebIdentity credential providers + writer.addDependency(AwsDependency.STS_CLIENT); + } + } +} diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java index 60d24ce366492..074562dbbb465 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java @@ -67,6 +67,7 @@ public enum AwsDependency implements Dependency { TRANSCRIBE_STREAMING_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-transcribe-streaming"), STS_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-sts"), STS_CLIENT(NORMAL_DEPENDENCY, "@aws-sdk/client-sts"), + SSO_OIDC_CLIENT(NORMAL_DEPENDENCY, "@aws-sdk/client-sso-oidc"), MIDDLEWARE_LOGGER(NORMAL_DEPENDENCY, "@aws-sdk/middleware-logger"), MIDDLEWARE_USER_AGENT("dependencies", "@aws-sdk/middleware-user-agent"), AWS_SDK_UTIL_USER_AGENT_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/util-user-agent-browser"), diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddSTSAuthCustomizations.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddSTSAuthCustomizations.java index 4b2b14377a3f5..a7229b8543b15 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddSTSAuthCustomizations.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AddSTSAuthCustomizations.java @@ -14,6 +14,7 @@ import java.util.function.Consumer; import java.util.logging.Logger; import software.amazon.smithy.aws.traits.auth.SigV4Trait; +import software.amazon.smithy.aws.typescript.codegen.AwsCredentialProviderUtils; import software.amazon.smithy.aws.typescript.codegen.AwsDependency; import software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils; import software.amazon.smithy.codegen.core.Symbol; @@ -114,6 +115,8 @@ public Map> getRuntimeConfigWriters( .addImport("defaultProvider", "credentialDefaultProvider", AwsDependency.CREDENTIAL_PROVIDER_NODE) .write("credentialDefaultProvider"); + AwsCredentialProviderUtils.addAwsCredentialProviderDependencies( + settings.getService(model), writer); } ); default: diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AwsSdkCustomizeSigV4Auth.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AwsSdkCustomizeSigV4Auth.java index af3c1ece4d6dc..24eb193125584 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AwsSdkCustomizeSigV4Auth.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AwsSdkCustomizeSigV4Auth.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.function.Consumer; import software.amazon.smithy.aws.traits.auth.SigV4Trait; +import software.amazon.smithy.aws.typescript.codegen.AwsCredentialProviderUtils; import software.amazon.smithy.aws.typescript.codegen.AwsDependency; import software.amazon.smithy.codegen.core.Symbol; import software.amazon.smithy.codegen.core.SymbolProvider; @@ -115,6 +116,7 @@ public Map> getRuntimeConfigWriters( .addImport("defaultProvider", "credentialDefaultProvider", AwsDependency.CREDENTIAL_PROVIDER_NODE) .write("credentialDefaultProvider"); + AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(service, writer); } ); }