Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EndpointsV2: Do not error without aws.api#service trait #644

Merged
merged 1 commit into from
Dec 6, 2022
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 @@ -17,6 +17,8 @@

import java.nio.file.Paths;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.model.Model;
Expand Down Expand Up @@ -110,12 +112,7 @@ private void generateEndpointParameters() {
ruleSet.getObjectMember("parameters").ifPresent(parameters -> {
parameters.accept(new RuleSetParametersVisitor(writer, true));
});
ServiceTrait serviceTrait = service.getTrait(ServiceTrait.class).get();
writer.write(
"defaultSigningName: \"$L\",",
service.getTrait(SigV4Trait.class).map(SigV4Trait::getName)
.orElse(serviceTrait.getArnNamespace())
);
writer.write("defaultSigningName: \"$L\",", defaultSigningName());
});
}
);
Expand All @@ -135,6 +132,21 @@ private void generateEndpointParameters() {
);
}

private String defaultSigningName() {
Optional<SigV4Trait> sigv4Trait = service.getTrait(SigV4Trait.class);
if (sigv4Trait.isPresent()) {
return sigv4Trait.get().getName();
}
Optional<ServiceTrait> serviceTrait = service.getTrait(ServiceTrait.class);
if (serviceTrait.isPresent()) {
return serviceTrait.get().getArnNamespace();
}
throw new NoSuchElementException(String.format(
"No %s or %s trait, required for Endpoint default signing name",
SigV4Trait.ID,
ServiceTrait.ID));
}

/**
* Generate the resolver function for this service.
*/
Expand Down