Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
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.List;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.aws.typescript.codegen.AwsDependency;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.ServiceShape;
Expand Down Expand Up @@ -56,7 +58,19 @@ public void customizeSupportedHttpAuthSchemes(
.addImport("nodeProvider", null, AwsDependency.TOKEN_PROVIDERS)
.addImport("FromSsoInit", null, AwsDependency.TOKEN_PROVIDERS)
.openBlock("async (idProps) => {", "}", () -> {
w.write("return await nodeProvider(idProps as FromSsoInit)(idProps);");
String defaultProviderReturn = "return await nodeProvider(idProps as FromSsoInit)(idProps);";
if (useFromEnvSigningName(service)) {
w.openBlock("try {", "}", () -> {
w.addImport("fromEnvSigningName", null, AwsDependency.TOKEN_PROVIDERS);
w.write("return await fromEnvSigningName({ signingName: $S })();",
service.expectTrait(SigV4Trait.class).getName());
});
w.openBlock("catch (error) {", "}", () -> {
w.write(defaultProviderReturn);
});
} else {
w.write(defaultProviderReturn);
}
}))
// Add identityProperties for backward compatibility of the `nodeProvider` default provider.
// If adding new properties that need to be passed into `nodeProvider`, make sure
Expand Down Expand Up @@ -88,4 +102,11 @@ public void customizeSupportedHttpAuthSchemes(
supportedHttpAuthSchemesIndex.putHttpAuthScheme(authScheme.getSchemeId(), authScheme);
}
}

private static boolean useFromEnvSigningName(ServiceShape service) {
if (isSigV4Service(service)) {
return service.expectTrait(SigV4Trait.class).getName().equals("bedrock");
}
return false;
}
}
Loading