Skip to content

Add aggregate semantics to Policy Compiler#4

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_913930387
Open

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

Conversation

@copybara-service

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:
  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:
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']
  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:
  semantics: aggregate
  match:
    - rule:
        semantics: first_match
        match:
          - condition: "1 == 2"
            output: "'EU_NOTICE'"
    - condition: "true"
      output: "'ALWAYS'"

# Output: ['ALWAYS']
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')]

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