package wasm
import "github.com/open-policy-agent/opa/internal/wasm/sdk/internal/wasm"
Index ¶
- type Pool
- func NewPool(poolSize, memoryMinPages, memoryMaxPages uint32) *Pool
- func (p *Pool) Acquire(ctx context.Context, metrics metrics.Metrics) (*VM, error)
- func (p *Pool) Close()
- func (p *Pool) ParsedData() (int32, []byte)
- func (p *Pool) Policy() []byte
- func (p *Pool) Release(vm *VM, metrics metrics.Metrics)
- func (p *Pool) RemoveDataPath(ctx context.Context, path []string) error
- func (p *Pool) SetDataPath(ctx context.Context, path []string, value interface{}) error
- func (p *Pool) SetPolicyData(ctx context.Context, policy []byte, data []byte) error
- func (p *Pool) Size() int
- func (p *Pool) Wait(i int) *VM
- type VM
- func (i *VM) Entrypoints() map[string]int32
- func (i *VM) Eval(ctx context.Context, entrypoint int32, input *interface{}, metrics metrics.Metrics, seed io.Reader, ns time.Time, iqbCache cache.InterQueryCache, ndbCache builtins.NDBCache, ph print.Hook, capabilities *ast.Capabilities) ([]byte, error)
- func (i *VM) Println(arg int32)
- func (i *VM) RemoveDataPath(ctx context.Context, path []string) error
- func (i *VM) SetDataPath(ctx context.Context, path []string, value interface{}) error
- func (i *VM) SetPolicyData(ctx context.Context, opts vmOpts) error
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool maintains a pool of WebAssemly VM instances.
func NewPool ¶
NewPool constructs a new pool with the pool and VM configuration provided.
func (*Pool) Acquire ¶
Acquire obtains a VM from the pool, waiting if all VMms are in use and building one as necessary. Returns either ErrNotReady or ErrInternal if an error.
func (*Pool) Close ¶
func (p *Pool) Close()
Close waits for all the evaluations to finish and then releases the VMs.
func (*Pool) ParsedData ¶
ParsedData returns a reference to the pools parsed external data used to initialize new VM's.
func (*Pool) Policy ¶
Policy returns the raw policy Wasm module used by VM's in the pool
func (*Pool) Release ¶
Release releases the VM back to the pool.
func (*Pool) RemoveDataPath ¶
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 (*Pool) SetDataPath ¶
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 (*Pool) SetPolicyData ¶
SetPolicyData re-initializes the vms within the pool with the new policy and data. The re-initialization takes place atomically: all new vms are constructed in advance before touching the pool. Returns either ErrNotReady, ErrInvalidPolicy or ErrInternal if an error occurs.
func (*Pool) Size ¶
Size returns the current number of VM's in the pool
func (*Pool) Wait ¶
Wait steals the i'th VM instance. The VM has to be released afterwards.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is a wrapper around a Wasm VM instance
func (*VM) Entrypoints ¶
Entrypoints returns a mapping of entrypoint name to ID for use by Eval().
func (*VM) Eval ¶
func (i *VM) Eval(ctx context.Context, entrypoint int32, input *interface{}, metrics metrics.Metrics, seed io.Reader, ns time.Time, iqbCache cache.InterQueryCache, ndbCache builtins.NDBCache, ph print.Hook, capabilities *ast.Capabilities) ([]byte, error)
Eval performs an evaluation of the specified entrypoint, with any provided input, and returns the resulting value dumped to a string.
func (*VM) Println ¶
Println is invoked if the policy WASM code calls opa_println().
func (*VM) RemoveDataPath ¶
RemoveDataPath will update the current data on the VM 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 (*VM) SetDataPath ¶
SetDataPath will update the current data on the VM 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 (*VM) SetPolicyData ¶
SetPolicyData Will either update the VM's data or, if the policy changed, re-initialize the VM.
Source Files ¶
- Version
- v0.49.2
- Published
- Feb 24, 2023
- Platform
- darwin/amd64
- Imports
- 21 packages
- Last checked
- 38 minutes ago –
Tools for package owners.