diff --git a/ast/compile.go b/ast/compile.go index 90a4ed8041..112571e7c4 100644 --- a/ast/compile.go +++ b/ast/compile.go @@ -335,7 +335,7 @@ func NewCompiler() *Compiler { {"BuildComprehensionIndices", "compile_stage_rebuild_comprehension_indices", c.buildComprehensionIndices}, } - _, c.generalRuleRefsEnabled = os.LookupEnv("OPA_ENABLE_GENERAL_RULE_REFS") + _, c.generalRuleRefsEnabled = os.LookupEnv("EXPERIMENTAL_GENERAL_RULE_REFS") return c } @@ -1757,7 +1757,7 @@ func (c *Compiler) rewriteRuleHeadRefs() { } for i := 1; i < len(ref); i++ { - // NOTE: Unless enabled via the OPA_ENABLE_GENERAL_RULE_REFS env var, non-string values in the refs are forbidden + // NOTE: Unless enabled via the EXPERIMENTAL_GENERAL_RULE_REFS env var, non-string values in the refs are forbidden // except for the last position, e.g. // OK: p.q.r[s] // NOT OK: p[q].r.s diff --git a/ast/compile_test.go b/ast/compile_test.go index 0dd6db7d76..bb8ca866a4 100644 --- a/ast/compile_test.go +++ b/ast/compile_test.go @@ -467,7 +467,7 @@ func toRef(s string) Ref { } func TestCompilerCheckRuleHeadRefs(t *testing.T) { - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") tests := []struct { note string @@ -1940,7 +1940,7 @@ func TestCompilerCheckRuleConflictsDefaultFunction(t *testing.T) { } func TestCompilerCheckRuleConflictsDotsInRuleHeads(t *testing.T) { - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") tests := []struct { note string @@ -2189,7 +2189,7 @@ func TestCompilerCheckRuleConflictsDotsInRuleHeads(t *testing.T) { // TODO: Remove when general rule refs are enabled by default. func TestGeneralRuleRefsDisabled(t *testing.T) { - // OPA_ENABLE_GENERAL_RULE_REFS env var not set + // EXPERIMENTAL_GENERAL_RULE_REFS env var not set tests := []struct { note string diff --git a/ast/parser.go b/ast/parser.go index ede432ae85..540d7b80c1 100644 --- a/ast/parser.go +++ b/ast/parser.go @@ -142,7 +142,7 @@ func NewParser() *Parser { s: &state{}, po: ParserOptions{}, } - _, p.po.generalRuleRefsEnabled = os.LookupEnv("OPA_ENABLE_GENERAL_RULE_REFS") + _, p.po.generalRuleRefsEnabled = os.LookupEnv("EXPERIMENTAL_GENERAL_RULE_REFS") return p } diff --git a/docs/content/policy-language.md b/docs/content/policy-language.md index 2321bf3110..043115b110 100644 --- a/docs/content/policy-language.md +++ b/docs/content/policy-language.md @@ -997,7 +997,7 @@ data.example Any term, except the very first, in a rule head's reference can be a variable. These variables can be assigned within the rule, just as for any other partial rule, to dynamically construct a nested collection of objects. {{< danger >}} -General refs in rule heads is an experimental feature, and can be enabled by setting the `OPA_ENABLE_GENERAL_RULE_REFS` environment variable. +General refs in rule heads is an experimental feature, and can be enabled by setting the `EXPERIMENTAL_GENERAL_RULE_REFS` environment variable. This feature is currently not supported for Wasm and IR. {{< /danger >}} @@ -1039,20 +1039,20 @@ package example import future.keywords # A partial object rule that converts a list of users to a mapping by "role" and then "id". -users_by_role[role][id] := user { +users_by_role[role][id] := user if { some user in data.users id := user.id role := user.role } # Partial rule with an explicit "admin" key override -users_by_role.admin[id] := user { +users_by_role.admin[id] := user if { some user in data.admins id := user.id } # Leaf entries can be partial sets -users_by_country[country] contains user.id { +users_by_country[country] contains user.id if { some user in data.users country := user.country } diff --git a/format/format_test.go b/format/format_test.go index d562b53a14..0c545fb557 100644 --- a/format/format_test.go +++ b/format/format_test.go @@ -78,7 +78,7 @@ func TestFormatSourceError(t *testing.T) { } func TestFormatSource(t *testing.T) { - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") regoFiles, err := filepath.Glob("testfiles/*.rego") if err != nil { diff --git a/test/cases/testdata/refheads/test-generic-refs.yaml b/test/cases/testdata/refheads/test-generic-refs.yaml index a0dae45f8c..74fb221f6e 100644 --- a/test/cases/testdata/refheads/test-generic-refs.yaml +++ b/test/cases/testdata/refheads/test-generic-refs.yaml @@ -1,7 +1,7 @@ cases: - note: 'refheads/general, single var' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -18,7 +18,7 @@ cases: r: 2 - note: 'refheads/general, multiple vars' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -35,7 +35,7 @@ cases: 2: true - note: 'refheads/general, deep query' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -47,7 +47,7 @@ cases: 1: true - note: 'refheads/general, overlapping rule, no conflict' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -65,7 +65,7 @@ cases: r: 2 - note: 'refheads/general, overlapping rule, conflict' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -76,7 +76,7 @@ cases: want_error: eval_conflict_error - note: 'refheads/general, set leaf' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -101,7 +101,7 @@ cases: r: [ "a", "b" ] - note: 'refheads/general, set leaf, deep query' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -120,7 +120,7 @@ cases: - x: "c" - note: 'refheads/general, input var' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -135,7 +135,7 @@ cases: r: "foo" - note: 'refheads/general, external non-ground var' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test @@ -159,7 +159,7 @@ cases: baz: 2 - note: 'refheads/general, multiple result-set entries' env: - OPA_ENABLE_GENERAL_RULE_REFS: "true" + EXPERIMENTAL_GENERAL_RULE_REFS: "true" modules: - | package test diff --git a/topdown/eval_test.go b/topdown/eval_test.go index 36531c018e..383f3a5ce5 100644 --- a/topdown/eval_test.go +++ b/topdown/eval_test.go @@ -248,7 +248,7 @@ func TestContainsNestedRefOrCall(t *testing.T) { func TestTopdownVirtualCache(t *testing.T) { // TODO: break out into separate tests - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") ctx := context.Background() store := inmem.New() @@ -604,7 +604,7 @@ func TestTopdownVirtualCache(t *testing.T) { } func TestPartialRule(t *testing.T) { - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") ctx := context.Background() store := inmem.New() @@ -1393,7 +1393,7 @@ func TestGeneralRuleRefsFeatureFlag(t *testing.T) { t.Fatal("Expected error but got:", c.Errors) } - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") c = ast.NewCompiler() c.Compile(mods) diff --git a/topdown/topdown_partial_test.go b/topdown/topdown_partial_test.go index 3a3472a888..126c7273a4 100644 --- a/topdown/topdown_partial_test.go +++ b/topdown/topdown_partial_test.go @@ -19,7 +19,7 @@ import ( func TestTopDownPartialEval(t *testing.T) { // TODO: break out into separate tests - t.Setenv("OPA_ENABLE_GENERAL_RULE_REFS", "true") + t.Setenv("EXPERIMENTAL_GENERAL_RULE_REFS", "true") tests := []struct { note string