Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 6 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
9 changes: 3 additions & 6 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand All @@ -81,7 +82,9 @@ func TestRemoteBundle(t *testing.T) {
},
},
},
})
},
runtime.WithRegoVersion(ast.RegoV0),
)

assert.NoError(err)

Expand Down