-
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 AccountId and CredentialScope BuiltIns #1993
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5429a8b
Add AccountId and CredentialScope BuiltIns
alextwoods 11845db
Fix checkstyle, make docs more vague
alextwoods fd4b11b
Add AwsBuiltinValidator
alextwoods 48888f5
Cleanup from PR + add test cases
alextwoods 339698e
Change eventIdSuffix for AWS Builtin validator
alextwoods e192926
PR feedback
alextwoods bb2ba00
Remove extra prefix from eventId
alextwoods d08e9db
Formatting
kstich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...in/java/software/amazon/smithy/rulesengine/aws/validators/RuleSetAwsBuiltInValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rulesengine.aws.validators; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import software.amazon.smithy.model.FromSourceLocation; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.model.validation.AbstractValidator; | ||
import software.amazon.smithy.model.validation.ValidationEvent; | ||
import software.amazon.smithy.rulesengine.aws.language.functions.AwsBuiltIns; | ||
import software.amazon.smithy.rulesengine.language.EndpointRuleSet; | ||
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter; | ||
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait; | ||
import software.amazon.smithy.utils.SetUtils; | ||
|
||
|
||
/** | ||
* Validator that AWS built-ins used in RuleSet parameters are supported. | ||
*/ | ||
public class RuleSetAwsBuiltInValidator extends AbstractValidator { | ||
|
||
private static final Set<String> ADDITIONAL_APPROVAL_BUILT_INS = SetUtils.of( | ||
AwsBuiltIns.ACCOUNT_ID.getName().toString(), | ||
AwsBuiltIns.CREDENTIAL_SCOPE.getName().toString()); | ||
|
||
@Override | ||
public List<ValidationEvent> validate(Model model) { | ||
List<ValidationEvent> events = new ArrayList<>(); | ||
for (ServiceShape serviceShape : model.getServiceShapesWithTrait(EndpointRuleSetTrait.class)) { | ||
events.addAll(validateRuleSetAwsBuiltIns(serviceShape, serviceShape.expectTrait(EndpointRuleSetTrait.class) | ||
.getEndpointRuleSet())); | ||
} | ||
return events; | ||
} | ||
|
||
private List<ValidationEvent> validateRuleSetAwsBuiltIns(ServiceShape serviceShape, EndpointRuleSet ruleSet) { | ||
List<ValidationEvent> events = new ArrayList<>(); | ||
for (Parameter parameter : ruleSet.getParameters()) { | ||
if (parameter.isBuiltIn()) { | ||
validateBuiltIn(serviceShape, parameter.getBuiltIn().get(), parameter, "RuleSet") | ||
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.ifPresent(events::add); | ||
} | ||
} | ||
return events; | ||
} | ||
|
||
private Optional<ValidationEvent> validateBuiltIn( | ||
ServiceShape serviceShape, | ||
String builtInName, | ||
FromSourceLocation source, | ||
String... eventIdSuffixes | ||
) { | ||
if (ADDITIONAL_APPROVAL_BUILT_INS.contains(builtInName)) { | ||
return Optional.of(danger(serviceShape, source, String.format( | ||
kstich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"The `%s` built-in used requires additional consideration of the rules that use it.", | ||
builtInName), | ||
String.join(".", Arrays.asList(eventIdSuffixes)))); | ||
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return Optional.empty(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ts/src/main/resources/META-INF/services/software.amazon.smithy.model.validation.Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
software.amazon.smithy.rulesengine.aws.validators.RuleSetAwsBuiltInValidator |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These header formatting pieces on both of these need to match the length of the header they're for.
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.
Thanks - forgot to run
make html
- fixed (and fixed the duplicate account-id label).