Add aggregate semantics to Policy Compiler#1052
Open
copybara-service[bot] wants to merge 1 commit into
Open
Conversation
a194d42 to
634780b
Compare
fa760aa to
6714afc
Compare
Aggregate walks through all matching rules (including nested ones) and appends them into a list:
```yaml
rule:
semantics: aggregate
match:
- condition: "true"
output: "'FOO'"
- condition: "true"
output: "'BAR'"
# Output: ['FOO','BAR']
```
Few noteworthy design decisions below. All examples assume all conditions matched:
1. For usability reasons, subrules under an aggregate ancestor will always have their **lists flattened**:
```YAML
name: aggregate_flat_flattening_example
rule:
semantics: aggregate
match:
- rule:
semantics: first_match
match:
- condition: "resource.is_admin == true"
rule:
semantics: aggregate
match:
- condition: "resource.has_standard_pii == true"
output: "'GDPR_STANDARD'"
- condition: "resource.is_b2c == true"
output: "'EU_B2C_NOTICE'"
- condition: "true"
output: "'FALLBACK'"
# Output: ['GDPR_STANDARD', 'EU_B2C_NOTICE', 'FALLBACK']
```
2. Base case of an aggregate rule is an empty list. Nested conditional rules within an aggregate rule which outputs `optional.none()` are pruned (except in cases where policy output explicitly emits an `optional.none()`):
```YAML
name: optional_pruning_example
rule:
semantics: aggregate
match:
- rule:
semantics: first_match
match:
- condition: "1 == 2"
output: "'EU_NOTICE'"
- condition: "true"
output: "'ALWAYS'"
# Output: ['ALWAYS']
```
```YAML
name: explicit_optional_none_example
rule:
semantics: aggregate
match:
- rule:
semantics: first_match
match:
- condition: "resource.is_b2c == true"
output: "optional.none()" # Explicitly authored by user
- condition: "true"
output: "optional.of('ALWAYS')"
# Output: [optional.none(), optional.of('ALWAYS')]
```
PiperOrigin-RevId: 913930387
6714afc to
380bcf3
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add aggregate semantics to Policy Compiler
Aggregate walks through all matching rules (including nested ones) and appends them into a list:
Few noteworthy design decisions below. All examples assume all conditions matched:
optional.none()are pruned (except in cases where policy output explicitly emits anoptional.none()):