Skip to content

Commit

Permalink
chore(codegen): add dependencies required by default credential provi…
Browse files Browse the repository at this point in the history
…ders
  • Loading branch information
trivikr committed May 2, 2024
1 parent 003de3f commit 3f4f8a0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(service, writer);
}
);
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,6 +115,8 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(
settings.getService(model), writer);
}
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +116,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(service, writer);
}
);
}
Expand Down

0 comments on commit 3f4f8a0

Please sign in to comment.