Skip to content

Commit

Permalink
Making changes suggested by @srenatus
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
  • Loading branch information
johanfylling committed Aug 31, 2023
1 parent c0d38ea commit ebf1503
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ast/compile.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ast/compile_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ast/parser.go
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions docs/content/policy-language.md
Expand Up @@ -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 >}}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion format/format_test.go
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions topdown/eval_test.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion topdown/topdown_partial_test.go
Expand Up @@ -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
Expand Down

0 comments on commit ebf1503

Please sign in to comment.