Skip to content

Add aggregate semantics to Policy Compiler - #4

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_913930387
Jul 31, 2026
Merged

Add aggregate semantics to Policy Compiler#4
copybara-service[bot] merged 1 commit into
mainfrom
test_913930387

Conversation

@copybara-service

@copybara-service copybara-service Bot commented May 13, 2026

Copy link
Copy Markdown

Add aggregate semantics to Policy Compiler

Aggregate walks through all matching rules (including nested ones) and appends them into a list:

rule:
  aggregate:
    - condition: "true"
      emit: "'FOO'"
    - condition: "true"
      emit: "'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:
name: aggregate_flat_flattening_example
rule:
  aggregate:
    - rule:
        match:
          - condition: "resource.is_admin == true"
            output: "['GDPR_STANDARD', 'EU_B2C_NOTICE']"
    - condition: "true"
      emit: "'FALLBACK'"
# Output: ['GDPR_STANDARD', 'EU_B2C_NOTICE', 'FALLBACK']
  1. 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()):
name: optional_pruning_example
rule:
  aggregate:
    - rule:
        match:
          - condition: "1 == 2"
            output: "'EU_NOTICE'"
    - condition: "true"
      emit: "'ALWAYS'"

# Output: ['ALWAYS']
name: explicit_optional_none_example
rule:
  aggregate:
    - rule:
        match:
          - condition: "resource.is_b2c == true"
            output: "optional.none()"   # Explicitly authored by user

    - condition: "true"
      emit: "optional.of('ALWAYS')"

# Output: [optional.none(), optional.of('ALWAYS')]

Note: nesting aggregate clauses is currently not allowed, and will result in a compilation error.

@copybara-service
copybara-service Bot force-pushed the test_913930387 branch 2 times, most recently from fbd6397 to 3c22f55 Compare May 20, 2026 21:37
@copybara-service
copybara-service Bot force-pushed the test_913930387 branch 11 times, most recently from 36f27d3 to 8404de9 Compare July 31, 2026 20:38
Aggregate walks through all matching rules (including nested ones) and appends them into a list:

```yaml
rule:
  aggregate:
    - condition: "true"
      emit: "'FOO'"
    - condition: "true"
      emit: "'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:
  aggregate:
    - rule:
        match:
          - condition: "resource.is_admin == true"
            output: "['GDPR_STANDARD', 'EU_B2C_NOTICE']"
    - condition: "true"
      emit: "'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:
  aggregate:
    - rule:
        match:
          - condition: "1 == 2"
            output: "'EU_NOTICE'"
    - condition: "true"
      emit: "'ALWAYS'"

# Output: ['ALWAYS']
```

```YAML
name: explicit_optional_none_example
rule:
  aggregate:
    - rule:
        match:
          - condition: "resource.is_b2c == true"
            output: "optional.none()"   # Explicitly authored by user

    - condition: "true"
      emit: "optional.of('ALWAYS')"

# Output: [optional.none(), optional.of('ALWAYS')]
```

Note: nesting `aggregate` clauses is currently not allowed, and will result in a compilation error.
PiperOrigin-RevId: 957321565
@copybara-service
copybara-service Bot merged commit ba3a185 into main Jul 31, 2026
@copybara-service
copybara-service Bot deleted the test_913930387 branch July 31, 2026 21:01
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.

1 participant