opa

package
v0.70.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvalOpts

type EvalOpts struct {
	Entrypoint             int32
	Input                  *interface{}
	Metrics                metrics.Metrics
	Time                   time.Time
	Seed                   io.Reader
	InterQueryBuiltinCache cache.InterQueryCache
	NDBuiltinCache         builtins.NDBCache
	PrintHook              print.Hook
	Capabilities           *ast.Capabilities
}

EvalOpts define options for performing an evaluation

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) Entrypoints

func (o *OPA) Entrypoints(ctx context.Context) (map[string]int32, error)

Entrypoints returns a mapping of entrypoint name to ID for use by Eval() and EvalBool().

func (*OPA) Eval

func (o *OPA) Eval(ctx context.Context, opts EvalOpts) (*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) RemoveDataPath

func (o *OPA) RemoveDataPath(ctx context.Context, path []string) error

RemoveDataPath will update the current data on the VMs by removing the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*OPA) SetData

func (o *OPA) SetData(ctx context.Context, v interface{}) error

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

func (*OPA) SetDataPath

func (o *OPA) SetDataPath(ctx context.Context, path []string, value interface{}) error

SetDataPath will update the current data on the VMs by setting the value at the specified path. If an error occurs the instance is still in a valid state, however the data will not have been modified.

func (*OPA) SetPolicy

func (o *OPA) SetPolicy(ctx context.Context, 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(ctx context.Context, 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 []byte
}

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