Skip to content

Commit 0f3e62f

Browse files
authored
chore(codegen): get token from environment if required (#7166)
1 parent ec3d275 commit 0f3e62f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/auth/http/integration/AwsSdkCustomizeHttpBearerTokenAuth.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
package software.amazon.smithy.aws.typescript.codegen.auth.http.integration;
77

88
import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isAwsService;
9+
import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isSigV4Service;
910

1011
import java.util.List;
12+
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
1113
import software.amazon.smithy.aws.typescript.codegen.AwsDependency;
1214
import software.amazon.smithy.model.Model;
1315
import software.amazon.smithy.model.shapes.ServiceShape;
@@ -56,7 +58,19 @@ public void customizeSupportedHttpAuthSchemes(
5658
.addImport("nodeProvider", null, AwsDependency.TOKEN_PROVIDERS)
5759
.addImport("FromSsoInit", null, AwsDependency.TOKEN_PROVIDERS)
5860
.openBlock("async (idProps) => {", "}", () -> {
59-
w.write("return await nodeProvider(idProps as FromSsoInit)(idProps);");
61+
String defaultProviderReturn = "return await nodeProvider(idProps as FromSsoInit)(idProps);";
62+
if (useFromEnvSigningName(service)) {
63+
w.openBlock("try {", "}", () -> {
64+
w.addImport("fromEnvSigningName", null, AwsDependency.TOKEN_PROVIDERS);
65+
w.write("return await fromEnvSigningName({ signingName: $S })();",
66+
service.expectTrait(SigV4Trait.class).getName());
67+
});
68+
w.openBlock("catch (error) {", "}", () -> {
69+
w.write(defaultProviderReturn);
70+
});
71+
} else {
72+
w.write(defaultProviderReturn);
73+
}
6074
}))
6175
// Add identityProperties for backward compatibility of the `nodeProvider` default provider.
6276
// If adding new properties that need to be passed into `nodeProvider`, make sure
@@ -88,4 +102,11 @@ public void customizeSupportedHttpAuthSchemes(
88102
supportedHttpAuthSchemesIndex.putHttpAuthScheme(authScheme.getSchemeId(), authScheme);
89103
}
90104
}
105+
106+
private static boolean useFromEnvSigningName(ServiceShape service) {
107+
if (isSigV4Service(service)) {
108+
return service.expectTrait(SigV4Trait.class).getName().equals("bedrock");
109+
}
110+
return false;
111+
}
91112
}

0 commit comments

Comments
 (0)