-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add support for missing authorizer members #1426
Conversation
This commit adds support for the `authorizerPayloadFormatVersion` and `enableSimpleResponses` members in `apiGateway#authorizers`. These members are used to properly define authorizers for HTTP APIs.
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 | ||
))); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great (:
...-traits/src/test/java/software/amazon/smithy/aws/apigateway/traits/AuthorizersTraitTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Chase Coalwell <782571+srchase@users.noreply.github.com>
Issue #, if available: N/A
Description of changes:
This commit adds support for the
authorizerPayloadFormatVersion
andenableSimpleResponses
members inapiGateway#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.