From 5d79bbfe1da361aeef115fe49df0107a8364ce34 Mon Sep 17 00:00:00 2001 From: Evan Anderson Date: Wed, 8 Jan 2025 09:32:53 -0800 Subject: [PATCH] Adjust imports for opa v1.0.0 release, hold back evaluator version to v0 language --- internal/engine/eval/rego/datasources.go | 6 +++--- internal/engine/eval/rego/eval.go | 10 +++++++--- internal/engine/eval/rego/lib.go | 6 +++--- internal/engine/eval/rego/result.go | 2 +- pkg/api/protobuf/go/minder/v1/validators.go | 6 ++++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/internal/engine/eval/rego/datasources.go b/internal/engine/eval/rego/datasources.go index 78b9c8e26a..8e9398b925 100644 --- a/internal/engine/eval/rego/datasources.go +++ b/internal/engine/eval/rego/datasources.go @@ -8,9 +8,9 @@ import ( "fmt" "strings" - "github.com/open-policy-agent/opa/ast" - "github.com/open-policy-agent/opa/rego" - "github.com/open-policy-agent/opa/types" + "github.com/open-policy-agent/opa/v1/ast" + "github.com/open-policy-agent/opa/v1/rego" + "github.com/open-policy-agent/opa/v1/types" v1datasources "github.com/mindersec/minder/pkg/datasources/v1" "github.com/mindersec/minder/pkg/engine/v1/interfaces" diff --git a/internal/engine/eval/rego/eval.go b/internal/engine/eval/rego/eval.go index fd2a597360..0b2dabf0d7 100644 --- a/internal/engine/eval/rego/eval.go +++ b/internal/engine/eval/rego/eval.go @@ -10,8 +10,9 @@ import ( "os" "github.com/open-feature/go-sdk/openfeature" - "github.com/open-policy-agent/opa/rego" - "github.com/open-policy-agent/opa/topdown/print" + "github.com/open-policy-agent/opa/v1/ast" + "github.com/open-policy-agent/opa/v1/rego" + "github.com/open-policy-agent/opa/v1/topdown/print" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/known/structpb" @@ -124,7 +125,10 @@ func (e *Evaluator) Eval( obj := res.Object // Register options to expose functions - regoFuncOptions := []func(*rego.Rego){} + regoFuncOptions := []func(*rego.Rego){ + // TODO: figure out a Rego V1 migration path (https://github.com/mindersec/minder/issues/5262) + rego.SetRegoVersion(ast.RegoV0), + } // Initialize the built-in minder library rego functions regoFuncOptions = append(regoFuncOptions, instantiateRegoLib(ctx, e.featureFlags, res)...) diff --git a/internal/engine/eval/rego/lib.go b/internal/engine/eval/rego/lib.go index 77752e09d4..e7f3f2697e 100644 --- a/internal/engine/eval/rego/lib.go +++ b/internal/engine/eval/rego/lib.go @@ -20,9 +20,9 @@ import ( "github.com/go-git/go-billy/v5" billyutil "github.com/go-git/go-billy/v5/util" "github.com/open-feature/go-sdk/openfeature" - "github.com/open-policy-agent/opa/ast" - "github.com/open-policy-agent/opa/rego" - "github.com/open-policy-agent/opa/types" + "github.com/open-policy-agent/opa/v1/ast" + "github.com/open-policy-agent/opa/v1/rego" + "github.com/open-policy-agent/opa/v1/types" "github.com/stacklok/frizbee/pkg/replacer" "github.com/stacklok/frizbee/pkg/utils/config" "gopkg.in/yaml.v3" diff --git a/internal/engine/eval/rego/result.go b/internal/engine/eval/rego/result.go index d713aa2557..0e020e6db9 100644 --- a/internal/engine/eval/rego/result.go +++ b/internal/engine/eval/rego/result.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "github.com/open-policy-agent/opa/rego" + "github.com/open-policy-agent/opa/v1/rego" "google.golang.org/protobuf/reflect/protoreflect" engerrors "github.com/mindersec/minder/internal/engine/errors" diff --git a/pkg/api/protobuf/go/minder/v1/validators.go b/pkg/api/protobuf/go/minder/v1/validators.go index ed41311872..5ed534ffc5 100644 --- a/pkg/api/protobuf/go/minder/v1/validators.go +++ b/pkg/api/protobuf/go/minder/v1/validators.go @@ -11,7 +11,7 @@ import ( "github.com/go-playground/validator/v10" "github.com/itchyny/gojq" - "github.com/open-policy-agent/opa/ast" + "github.com/open-policy-agent/opa/v1/ast" "github.com/mindersec/minder/internal/util" ) @@ -224,7 +224,9 @@ func (rego *RuleType_Definition_Eval_Rego) Validate() error { return fmt.Errorf("%w: rego definition is empty", ErrInvalidRuleTypeDefinition) } - _, err := ast.ParseModule("minder-ruletype-def.rego", rego.Def) + // TODO: figure out a Rego V1 migration path (https://github.com/mindersec/minder/issues/5262) + _, err := ast.ParseModuleWithOpts("minder-ruletype-def.rego", rego.Def, + ast.ParserOptions{RegoVersion: ast.RegoV0}) if err != nil { return fmt.Errorf("%w: rego definition is invalid: %s", ErrInvalidRuleTypeDefinition, err) }