Skip to content

Commit

Permalink
Allow setting the rego version for runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
carabasdaniel committed Mar 25, 2024
1 parent 9f49f54 commit 3664f2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Runtime struct {

storage storage.Store
latestState atomic.Pointer[State]
regoVersion ast.RegoVersion
}

type BundleState struct {
Expand Down Expand Up @@ -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{})

Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 3664f2d

Please sign in to comment.