From 3664f2da6aa3ff41fe4d9abf8bde3ac252c378d7 Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Mon, 25 Mar 2024 13:02:01 +0200 Subject: [PATCH] Allow setting the rego version for runtime --- options.go | 6 ++++++ runtime.go | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index 639d402..0fdfed9 100644 --- a/options.go +++ b/options.go @@ -15,6 +15,12 @@ func WithPlugin(name string, factory plugins.Factory) Option { } } +func WithRegoVersion(version ast.RegoVersion) Option { + return func(r *Runtime) { + r.regoVersion = version + } +} + func WithBuiltin1(decl *rego.Function, impl rego.Builtin1) Option { return func(r *Runtime) { r.builtins1[decl] = impl diff --git a/runtime.go b/runtime.go index 08137be..e26151a 100644 --- a/runtime.go +++ b/runtime.go @@ -56,6 +56,7 @@ type Runtime struct { storage storage.Store latestState atomic.Pointer[State] + regoVersion ast.RegoVersion } type BundleState struct { @@ -93,6 +94,7 @@ func newOPARuntime(ctx context.Context, log *zerolog.Logger, cfg *Config, opts . pluginStates: &sync.Map{}, bundleStates: &sync.Map{}, plugins: map[string]plugins.Factory{}, + regoVersion: ast.RegoV0, } runtime.latestState.Store(&State{}) @@ -354,7 +356,9 @@ func (r *Runtime) newOPAPluginsManager(ctx context.Context) (*plugins.Manager, e plugins.MaxErrors(r.Config.PluginsErrorLimit), plugins.GracefulShutdownPeriod(r.Config.GracefulShutdownPeriodSeconds), plugins.Logger(logger.NewOpaLogger(r.Logger)), + plugins.WithParserOptions(ast.ParserOptions{RegoVersion: r.regoVersion}), ) + if err != nil { return nil, errors.Wrap(err, "failed to initialize OPA plugins") } @@ -399,7 +403,7 @@ func (r *Runtime) loadPaths(paths []string) (map[string]*bundle.Bundle, error) { for _, path := range paths { r.Logger.Info().Str("path", path).Msg("Loading local bundle") result[path], err = loader.NewFileLoader().WithBundleVerificationConfig(verificationConfig). - WithSkipBundleVerification(skipVerify).AsBundle(path) + WithSkipBundleVerification(skipVerify).WithRegoVersion(r.regoVersion).AsBundle(path) if err != nil { errorStatus := bundleplugin.Status{