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

Add support for missing authorizer members #1426

Merged

Conversation

jvschneid
Copy link
Contributor

Issue #, if available: N/A

Description of changes:
This commit adds support for the authorizerPayloadFormatVersion and enableSimpleResponses members in apiGateway#authorizers. These members are used to properly define authorizers for HTTP APIs.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This commit adds support for the `authorizerPayloadFormatVersion` and
`enableSimpleResponses` members in `apiGateway#authorizers`. These members
are used to properly define authorizers for HTTP APIs.
@jvschneid jvschneid requested a review from a team as a code owner September 27, 2022 20:55
Comment on lines +97 to +118
private Optional<ValidationEvent> validateEnableSimpleResponsesConfig(Map<String, AuthorizerDefinition> authorizers,
ServiceShape service) {
String invalidConfigs = authorizers.entrySet().stream()
.filter(entry -> entry.getValue().getEnableSimpleResponses().isPresent())
.filter(entry -> entry.getValue().getAuthorizerPayloadFormatVersion().isPresent())
.filter(entry -> !entry.getValue().getAuthorizerPayloadFormatVersion().get().equals("2.0"))
.map(Map.Entry::getKey)
.sorted()
.collect(Collectors.joining(", "));

if (invalidConfigs.isEmpty()) {
return Optional.empty();
}

AuthorizersTrait authorizersTrait = service.getTrait(AuthorizersTrait.class).get();
return Optional.of(error(service, authorizersTrait, String.format(
"The enableSimpleResponses member of %s is only supported when authorizedPayloadFormatVersion "
+ "is 2.0. The following authorizers are misconfigured: %s",
AuthorizersTrait.ID,
invalidConfigs
)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this validator is being overzealous or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being overzealous. We do similar validation to assure compatible properties are set for other traits. The HttpApiKeyAuthTraitValidator does something similar for the @HttpApiKeyAuthTrait's in and scheme properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great (:

Co-authored-by: Chase Coalwell <782571+srchase@users.noreply.github.com>
@jvschneid jvschneid merged commit 9ccec2c into smithy-lang:main Oct 3, 2022
@jvschneid jvschneid deleted the authorizer-trait-missing-members branch October 3, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants