diff --git a/README.md b/README.md index bb4d652..dcab429 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ go get -u github.com/aserto-dev/runtime ```go // Create a runtime -r, err := runtime.New(ctx, &logger, &runtime.Config{}) +r, err := runtime.New(ctx, &logger, &runtime.Config{}, runtime.WithRegoVersion(ast.RegoV1))) if err != nil { return errors.Wrap(err, "failed to create runtime") } diff --git a/options.go b/options.go index 7bc5221..6a84cc1 100644 --- a/options.go +++ b/options.go @@ -87,3 +87,9 @@ func WithImports(imp []string) Option { r.imports = append(r.imports, imp...) } } + +func WithRegoVersion(v ast.RegoVersion) Option { + return func(r *Runtime) { + r.regoVersion = v + } +} diff --git a/runtime.go b/runtime.go index 801e370..c01b3e5 100644 --- a/runtime.go +++ b/runtime.go @@ -32,6 +32,8 @@ import ( "github.com/rs/zerolog/log" ) +const DefaultRegoVersion = ast.RegoV1 + // Runtime manages the OPA runtime (plugins, store and info data). type Runtime struct { Logger *zerolog.Logger @@ -95,7 +97,7 @@ func New(ctx context.Context, cfg *Config, opts ...Option) (*Runtime, error) { pluginStates: &sync.Map{}, bundleStates: &sync.Map{}, plugins: map[string]plugins.Factory{}, - regoVersion: ast.RegoV0, + regoVersion: DefaultRegoVersion, } runtime.latestState.Store(&State{}) @@ -136,11 +138,6 @@ func New(ctx context.Context, cfg *Config, opts ...Option) (*Runtime, error) { return runtime, nil } -func (r *Runtime) WithRegoV1() *Runtime { - r.regoVersion = ast.RegoV1 - return r -} - // Start - triggers plugin manager to start all plugins. func (r *Runtime) Start(ctx context.Context) error { return r.pluginsManager.Start(ctx) diff --git a/runtime_test.go b/runtime_test.go index 749f751..7248478 100644 --- a/runtime_test.go +++ b/runtime_test.go @@ -6,6 +6,7 @@ import ( runtime "github.com/aserto-dev/runtime" "github.com/aserto-dev/runtime/testutil" + "github.com/open-policy-agent/opa/v1/ast" "github.com/open-policy-agent/opa/v1/plugins/bundle" "github.com/stretchr/testify/require" ) @@ -60,7 +61,7 @@ func TestFailingLocalBundle(t *testing.T) { assert.Error(err) } -func TestRemoteBundle(t *testing.T) { +func TestRemoteBundleV0(t *testing.T) { // Arrange assert := require.New(t) ctx := t.Context() @@ -81,7 +82,9 @@ func TestRemoteBundle(t *testing.T) { }, }, }, - }) + }, + runtime.WithRegoVersion(ast.RegoV0), + ) assert.NoError(err)