opa

package
v0.0.0-...-8041bec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2020 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig is the error returned if the OPA initialization fails due to an invalid config.
	ErrInvalidConfig = errors.New("invalid config")
	// ErrInvalidPolicyOrData is the error returned if either policy or data is invalid.
	ErrInvalidPolicyOrData = errors.New("invalid policy or data")
	// ErrInvalidBundle is the error returned if the bundle loaded is corrupted.
	ErrInvalidBundle = errors.New("invalid bundle")
	// ErrNotReady is the error returned if the OPA instance is not initialized.
	ErrNotReady = errors.New("not ready")
	// ErrUndefined is the error returned if the evaluation result is undefined.
	ErrUndefined = errors.New("undefined decision")
	// ErrNonBoolean is the error returned if the evaluation result is not of boolean value.
	ErrNonBoolean = errors.New("non-boolean decision")
	// ErrInternal is the error returned if the evaluation fails due to an internal error.
	ErrInternal = errors.New("internal error")
)

Functions

func EvalBool

func EvalBool(ctx context.Context, o *OPA, input *interface{}) (bool, error)

EvalBool evaluates the boolean policy with the given input. The possible error values returned are as with Eval with addition of ErrUndefined indicating an undefined policy decision and ErrNonBoolean indicating a non-boolean policy decision.

Types

type Loader

type Loader interface {
	// Load loads a bundle. This can be invoked without starting the polling.
	Load(ctx context.Context) error

	// Start starts the bundle polling.
	Start(ctx context.Context) error

	// Close stops the polling.
	Close()
}

Loader is the interface all bundle loaders implement.

type OPA

type OPA struct {
	// contains filtered or unexported fields
}

OPA executes WebAssembly compiled Rego policies.

func New

func New() *OPA

New constructs a new OPA SDK instance, ready to be configured with With functions. If no policy is provided as a part of configuration, policy (and data) needs to be set before invoking Eval. Once constructed and configured, the instance needs to be initialized before invoking the Eval.

func (*OPA) Close

func (o *OPA) Close()

Close waits until all the pending evaluations complete and then releases all the resources allocated. Eval will return ErrClosed afterwards.

func (*OPA) Eval

func (o *OPA) Eval(ctx context.Context, input *interface{}) (*Result, error)

Eval evaluates the policy with the given input, returning the evaluation results. If no policy was configured at construction time nor set after, the function returns ErrNotReady. It returns ErrInternal if any other error occurs.

func (*OPA) Init

func (o *OPA) Init() (*OPA, error)

Init initializes the SDK instance after the construction and configuration. If the configuration is invalid, it returns ErrInvalidConfig.

func (*OPA) SetData

func (o *OPA) SetData(v interface{}) error

SetData updates the data for the subsequent Eval calls. Returns either ErrNotReady, ErrInvalidPolicyOrData, or ErrInternal if an error occurs.

func (*OPA) SetPolicy

func (o *OPA) SetPolicy(p []byte) error

SetPolicy updates the policy for the subsequent Eval calls. Returns either ErrNotReady, ErrInvalidPolicy or ErrInternal if an error occurs.

func (*OPA) SetPolicyData

func (o *OPA) SetPolicyData(policy []byte, data *interface{}) error

SetPolicyData updates both the policy and data for the subsequent Eval calls. Returns either ErrNotReady, ErrInvalidPolicyOrData, or ErrInternal if an error occurs.

func (*OPA) WithDataBytes

func (o *OPA) WithDataBytes(data []byte) *OPA

WithDataBytes configures the JSON data to load.

func (*OPA) WithDataFile

func (o *OPA) WithDataFile(fileName string) *OPA

WithDataFile configures the JSON data file to load.

func (*OPA) WithDataJSON

func (o *OPA) WithDataJSON(data interface{}) *OPA

WithDataJSON configures the JSON data to load.

func (*OPA) WithErrorLogger

func (o *OPA) WithErrorLogger(logger func(error)) *OPA

WithErrorLogger configures an error logger invoked with all the errors.

func (*OPA) WithMemoryLimits

func (o *OPA) WithMemoryLimits(min, max uint32) *OPA

WithMemoryLimits configures the memory limits (in bytes) for a single policy evaluation.

func (*OPA) WithPolicyBytes

func (o *OPA) WithPolicyBytes(policy []byte) *OPA

WithPolicyBytes configures the compiled policy to load.

func (*OPA) WithPolicyFile

func (o *OPA) WithPolicyFile(fileName string) *OPA

WithPolicyFile configures a policy file to load.

func (*OPA) WithPoolSize

func (o *OPA) WithPoolSize(size uint32) *OPA

WithPoolSize configures the maximum number of simultaneous policy evaluations, i.e., the maximum number of underlying WASM instances active at any time. The default is the number of logical CPUs usable for the process as per runtime.NumCPU().

type Result

type Result struct {
	Result interface{}
}

Result holds the evaluation result.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL