Skip to content

Commit

Permalink
chore(codegen): awsAuthPlugin to set default signing name (#4259)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Dec 6, 2022
1 parent 0ca342d commit 14d93f0
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.Logger;

import jdk.internal.net.http.common.Log;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.codegen.core.Symbol;
Expand Down Expand Up @@ -62,6 +65,8 @@ public final class AddAwsAuthPlugin implements TypeScriptIntegration {
static final String ROLE_ASSUMERS_TEST_FILE = "defaultRoleAssumers.spec";
static final String STS_ROLE_ASSUMERS_FILE = "defaultStsRoleAssumers";

private static final Logger LOGGER = Logger.getLogger(AddAwsAuthPlugin.class.getName());

@Override
public void addConfigInterfaceFields(
TypeScriptSettings settings,
Expand All @@ -70,6 +75,14 @@ public void addConfigInterfaceFields(
TypeScriptWriter writer
) {
ServiceShape service = settings.getService(model);
if (!isSigV4Service(service) && isAwsService(service)) {
ServiceTrait serviceTrait = service.getTrait(ServiceTrait.class).get();
settings.setDefaultSigningName(
serviceTrait.getArnNamespace()
);
return;
}

if (!isSigV4Service(service)) {
return;
}
Expand All @@ -85,6 +98,16 @@ public void addConfigInterfaceFields(
+ "@internal");
writer.write("credentialDefaultProvider?: (input: any) => __Provider<__Credentials>;\n");
}

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.");
}
}

// Only one of AwsAuth or SigV4Auth should be used
Expand Down

0 comments on commit 14d93f0

Please sign in to comment.