|
| 1 | +package before_resolution |
| 2 | + |
| 3 | +# This file enforces policies requiring all attributes to be defined within |
| 4 | +# a semantic convention "registry". This is a naming/structure convention |
| 5 | +# used by semantic conventions. |
| 6 | + |
| 7 | +# Helper to create attribute registry violations. |
| 8 | +attr_registry_violation(violation_id, group_id, attr_id) = violation { |
| 9 | + violation := { |
| 10 | + "id": violation_id, |
| 11 | + "type": "semantic_convention_policies", |
| 12 | + "category": "attribute_registry_checks", |
| 13 | + "group": group_id, |
| 14 | + "attr": attr_id, |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +# We only allow attribute groups in the attribute registry. |
| 19 | +deny[attr_registry_violation("attribute_registry_can_only_contain_attribute_groups", group.id, "")] { |
| 20 | + group := input.groups[_] |
| 21 | + startswith(group.id, "registry.") |
| 22 | + group.type != "attribute_group" |
| 23 | +} |
| 24 | + |
| 25 | +# Any group that is NOT in the attribute registry that has an attribute id is |
| 26 | +# in violation of not using the attribute registry. |
| 27 | +deny[attr_registry_violation("attributes_must_be_defined_in_attribute_registry", group.id, attr.id)] { |
| 28 | + group := input.groups[_] |
| 29 | + not startswith(group.id, "registry.") |
| 30 | + attr := group.attributes[_] |
| 31 | + attr.id != null |
| 32 | +} |
| 33 | + |
| 34 | +# A registry `attribute_group` containing at least one `ref` attribute is |
| 35 | +# considered invalid if it's not in the registry group. |
| 36 | +deny[attr_registry_violation("attributes_in_registry_cannot_reference_each_other", group.id, attr.ref)] { |
| 37 | + # TODO - this will need to be updated to support `embed` in the future. |
| 38 | + group := input.groups[_] |
| 39 | + startswith(group.id, "registry.") |
| 40 | + attr := group.attributes[_] |
| 41 | + attr.ref != null |
| 42 | +} |
0 commit comments