-
Notifications
You must be signed in to change notification settings - Fork 9
Pass --strict_message conformance (minus duration/timestamp)
#256
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
Merged
Merged
Changes from 1 commit
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -146,16 +146,30 @@ def format_string(self, arg: celtypes.Value) -> celpy.Result: | |
| if isinstance(arg, celtypes.StringType): | ||
| return arg | ||
| if isinstance(arg, celtypes.BytesType): | ||
| return celtypes.StringType(arg.hex()) | ||
| return celtypes.StringType(arg) | ||
| if isinstance(arg, celtypes.ListType): | ||
| return self.format_list(arg) | ||
| if isinstance(arg, celtypes.BoolType): | ||
| # True -> true | ||
| return celtypes.StringType(str(arg).lower()) | ||
| if isinstance(arg, celtypes.DoubleType): | ||
| return celtypes.StringType(f"{arg:.0f}") | ||
| if isinstance(arg, celtypes.TimestampType): | ||
| base = arg.isoformat() | ||
| if arg.getMilliseconds() != 0: | ||
| base = arg.isoformat(timespec="milliseconds") | ||
| return celtypes.StringType(base.removesuffix("+00:00") + "Z") | ||
| return celtypes.StringType(arg) | ||
|
|
||
| def format_value(self, arg: celtypes.Value) -> celpy.Result: | ||
| if isinstance(arg, (celtypes.StringType, str)): | ||
| return celtypes.StringType(quote(arg)) | ||
| if isinstance(arg, celtypes.UintType): | ||
| return celtypes.StringType(arg) | ||
| if isinstance(arg, celtypes.DurationType): | ||
| return celtypes.StringType(f'duration("{arg.seconds + (arg.microseconds // 1e6):.0f}s")') | ||
| if isinstance(arg, celtypes.DoubleType): | ||
| return celtypes.StringType(f"{arg:f}") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return self.format_string(arg) | ||
|
|
||
| def format_list(self, arg: celtypes.ListType) -> celpy.Result: | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| # celpy doesn't support nano seconds | ||
| # ref: https://github.com/cloud-custodian/cel-python/issues/43 | ||
| standard_constraints/well_known_types/duration: | ||
| - gte_lte/invalid/above | ||
| - lte/invalid | ||
| - not in/valid | ||
| - gte/invalid | ||
| - gt/invalid | ||
| - in/invalid | ||
| - "not in/valid" | ||
| standard_constraints/well_known_types/timestamp: | ||
| - gte_lte/invalid/above | ||
| - lte/invalid | ||
| standard_constraints/repeated: | ||
| - duration/gte/invalid |
Oops, something went wrong.
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.
just for context, most protovalidate rules are defined in CEL using the
%sverb (in fact, I don't think I've seen another verb used).format_stringhandles that verb, so we need to add some additional handling here.