Skip to content

Add support for missing authorizer members#1426

Merged
jvschneid merged 2 commits intosmithy-lang:mainfrom
jvschneid:authorizer-trait-missing-members
Oct 3, 2022
Merged

Add support for missing authorizer members#1426
jvschneid merged 2 commits intosmithy-lang:mainfrom
jvschneid:authorizer-trait-missing-members

Conversation

@jvschneid
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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