Documentation
¶
Overview ¶
vm implements Rego interpreter evaluating compiled Rego IR.
Index ¶
- Constants
- Variables
- func BuiltinRegoEval(bctx topdown.BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error
- type BoolConst
- type CacheConfig
- type CacheHook
- type CallNamespace
- type Compiler
- type DataOperations
- func (*DataOperations) ArrayAppend(ctx context.Context, array any, value any) (any, bool, error)
- func (*DataOperations) Call(ctx context.Context, value any, args []*any, caller *State) (any, bool, bool, error)
- func (*DataOperations) CopyShallow(ctx context.Context, value any) (any, error)
- func (*DataOperations) Equal(ctx context.Context, a, b any) (bool, error)
- func (o *DataOperations) FromInterface(ctx context.Context, x any) (fjson.Json, error)
- func (*DataOperations) Get(ctx context.Context, value, key any) (any, bool, error)
- func (*DataOperations) GetCall(ctx context.Context, value, key any) (any, bool, error)
- func (*DataOperations) IsArray(ctx context.Context, v any) (bool, error)
- func (*DataOperations) IsCall(value any) (bool, error)
- func (*DataOperations) IsObject(ctx context.Context, v any) (bool, error)
- func (*DataOperations) IsSet(ctx context.Context, v any) (bool, error)
- func (o *DataOperations) Iter(ctx context.Context, v any, f func(key, value any) (bool, error)) error
- func (o *DataOperations) Len(ctx context.Context, v any) (fjson.Json, error)
- func (*DataOperations) MakeArray(capacity int32) fjson.Array
- func (*DataOperations) MakeBoolean(v bool) fjson.Json
- func (*DataOperations) MakeNull() fjson.Json
- func (*DataOperations) MakeNumberFloat(f float64) fjson.Float
- func (o *DataOperations) MakeNumberInt(i int64) fjson.Json
- func (*DataOperations) MakeNumberRef(n any) fjson.Float
- func (o *DataOperations) MakeNumberZero() fjson.Json
- func (*DataOperations) MakeObject() fjson.Object2
- func (*DataOperations) MakeSet() fjson.Set
- func (*DataOperations) MakeString(v string) *fjson.String
- func (*DataOperations) ObjectGet(ctx context.Context, object, key any) (any, bool, error)
- func (*DataOperations) ObjectInsert(ctx context.Context, object, key, value any) (any, bool, error)
- func (o *DataOperations) ObjectMerge(ctx context.Context, a, b any) (any, error)
- func (*DataOperations) SetAdd(ctx context.Context, set, value any) (any, error)
- func (o *DataOperations) ToAST(ctx context.Context, v any) (ast.Value, error)
- func (o *DataOperations) ToInterface(ctx context.Context, v any) (any, error)
- type EvalOpts
- type Executable
- type GetCallNamespace
- type Globals
- type IterableObject
- type Limits
- type Local
- type LocalOrConst
- type Locals
- type N
- type State
- func (s *State) Args(n int) []Value
- func (s *State) DataGet(ctx context.Context, value, key any) (any, bool, error)
- func (s *State) FindByPath(path []string) (function, int)
- func (s *State) Func(f int) function
- func (s *State) Instr(i int64) error
- func (s *State) IsData(l Local) bool
- func (s *State) IsDefined(v LocalOrConst) bool
- func (s *State) IsLocalDefined(v Local) bool
- func (s *State) Local(v Local) Value
- func (s *State) MemoizeGet(idx int, args []Value) (Value, bool)
- func (s *State) MemoizeInsert(idx int, args []Value, value Value)
- func (s *State) MemoizePop()
- func (s *State) MemoizePush()
- func (s *State) New() *State
- func (s *State) Release()
- func (s *State) Return() (Local, bool)
- func (s *State) Set(target Local, source LocalOrConst)
- func (s *State) SetData(l Local)
- func (s *State) SetLocal(target Local, source Local)
- func (s *State) SetReturn(source Local)
- func (s *State) SetReturnValue(source Local, value Value)
- func (s *State) SetValue(target Local, value Value)
- func (s *State) String(v StringIndexConst) *fjson.String
- func (s *State) Unset(target Local)
- func (s *State) Value(v LocalOrConst) Value
- func (s *State) ValueOps() *DataOperations
- type Statistics
- type StringIndexConst
- type VM
- type Value
Constants ¶
const (
RegoCompileName = "rego.compile"
)
Variables ¶
var ( ErrInvalidData = errors.New("invalid data") // Unsupported data type detected. ErrIllegalIter = errors.New("illegal iteration") // Illegal iteration over persisted table detected. )
var ( ErrVarAssignConflict = errors.New("var assignment conflict") ErrObjectInsertConflict = errors.New("object insert conflict") ErrFunctionCallToData = errors.New("function call to data") ErrInvalidExecutable = errors.New("invalid executable") ErrQueryNotFound = errors.New("query not found") ErrInstructionsLimitExceeded = errors.New("instructions limit exceeded") DefaultLimits = Limits{ Instructions: 100000000, } )
Functions ¶
func BuiltinRegoEval ¶
Types ¶
type CacheConfig ¶
type CacheConfig struct {
Enabled bool `json:"enabled"`
InputPaths []string `json:"input_paths"`
TTL string `json:"ttl"`
}
CacheConfig is under "extra/eval_cache" in OPA config.
type CacheHook ¶
type CacheHook struct {
// contains filtered or unexported fields
}
CacheHook receives OPA configuration change callbacks and holds the current cache configuration.
func NewCacheHook ¶
func NewCacheHook() *CacheHook
type CallNamespace ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
func NewCompiler ¶
func NewCompiler() *Compiler
func (*Compiler) Compile ¶
func (c *Compiler) Compile() (Executable, error)
Compile turns the IR into VM executable instructions
func (*Compiler) WithBuiltins ¶
type DataOperations ¶
type DataOperations struct{}
func (*DataOperations) ArrayAppend ¶
func (*DataOperations) CopyShallow ¶
func (*DataOperations) FromInterface ¶
FromInterface converts a golang native data to internal representation.
func (*DataOperations) MakeBoolean ¶
func (*DataOperations) MakeBoolean(v bool) fjson.Json
func (*DataOperations) MakeNull ¶
func (*DataOperations) MakeNull() fjson.Json
func (*DataOperations) MakeNumberFloat ¶
func (*DataOperations) MakeNumberFloat(f float64) fjson.Float
func (*DataOperations) MakeNumberInt ¶
func (o *DataOperations) MakeNumberInt(i int64) fjson.Json
func (*DataOperations) MakeNumberRef ¶
func (*DataOperations) MakeNumberRef(n any) fjson.Float
func (*DataOperations) MakeNumberZero ¶
func (o *DataOperations) MakeNumberZero() fjson.Json
func (*DataOperations) MakeObject ¶
func (*DataOperations) MakeObject() fjson.Object2
func (*DataOperations) MakeSet ¶
func (*DataOperations) MakeSet() fjson.Set
func (*DataOperations) MakeString ¶
func (*DataOperations) MakeString(v string) *fjson.String
func (*DataOperations) ObjectInsert ¶
func (*DataOperations) ObjectMerge ¶
func (*DataOperations) ToInterface ¶
ToInterface converts the data to golang native presentation.
type EvalOpts ¶
type EvalOpts struct {
Time time.Time
PrintHook print.Hook
Metrics metrics.Metrics
Seed io.Reader
Runtime any
InterQueryBuiltinCache cache.InterQueryCache
InterQueryBuiltinValueCache cache.InterQueryValueCache
Input *any // Input as golang native data.
Limits *Limits
Cache builtins.Cache
NDBCache builtins.NDBCache
Capabilities *ast.Capabilities
BuiltinFuncs map[string]*topdown.Builtin
TracingOpts tracing.Options
StrictBuiltinErrors bool
ExternalCancel topdown.Cancel
QueryTracers []topdown.QueryTracer
}
func EvalOptsFromContext ¶
type Executable ¶
type Executable []byte
func (Executable) Functions ¶
func (e Executable) Functions() functions
func (Executable) IsValid ¶
func (e Executable) IsValid() bool
func (Executable) Plans ¶
func (e Executable) Plans() plans
func (Executable) Strings ¶
func (e Executable) Strings() strings
type GetCallNamespace ¶
type Globals ¶
type Globals struct {
Time time.Time
Metrics metrics.Metrics
PrintHook print.Hook
InterQueryBuiltinCache cache.InterQueryCache
InterQueryBuiltinValueCache cache.InterQueryValueCache
Ctx context.Context
Seed io.Reader
Cache builtins.Cache
BuiltinFuncs map[string]*topdown.Builtin
Capabilities *ast.Capabilities
Input *any
NDBCache builtins.NDBCache
Runtime *ast.Term
ResultSet fjson.Set
BuiltinErrors []error
TracingOpts tracing.Options
Limits Limits
StrictBuiltinErrors bool
IntermediateResults map[int]any
QueryTracers []topdown.QueryTracer
// contains filtered or unexported fields
}
type IterableObject ¶
type IterableObject interface {
Get(ctx context.Context, key any) (any, bool, error)
Iter(ctx context.Context, f func(key, value any) (bool, error)) error
}
IterableObject is the interface for external, read-only (probably persisted) object implementations.
type LocalOrConst ¶
type LocalOrConst struct {
// contains filtered or unexported fields
}
func NewBoolConst ¶
func NewBoolConst(v bool) LocalOrConst
func NewLocal ¶
func NewLocal(v int) LocalOrConst
func NewStringIndexConst ¶
func NewStringIndexConst(v int) LocalOrConst
func (*LocalOrConst) BoolConst ¶
func (l *LocalOrConst) BoolConst() BoolConst
func (*LocalOrConst) Local ¶
func (l *LocalOrConst) Local() Local
func (*LocalOrConst) StringIndexConst ¶
func (l *LocalOrConst) StringIndexConst() StringIndexConst
func (*LocalOrConst) Type ¶
func (l *LocalOrConst) Type() int
type State ¶
type State struct {
Globals *Globals
// contains filtered or unexported fields
}
State holds all the evaluation state and is passed along the statements as the evaluation progresses.
func (*State) FindByPath ¶
func (*State) IsDefined ¶
func (s *State) IsDefined(v LocalOrConst) bool
func (*State) IsLocalDefined ¶
func (*State) MemoizePop ¶
func (s *State) MemoizePop()
func (*State) MemoizePush ¶
func (s *State) MemoizePush()
func (*State) Set ¶
func (s *State) Set(target Local, source LocalOrConst)
func (*State) SetReturnValue ¶
func (*State) Value ¶
func (s *State) Value(v LocalOrConst) Value
func (*State) ValueOps ¶
func (s *State) ValueOps() *DataOperations
type Statistics ¶
type Statistics struct {
EvalInstructions int64 `json:"eval_instructions"`
VirtualCacheHits int64 `json:"virtual_cache_hits"`
VirtualCacheMisses int64 `json:"virtual_cache_misses"`
}
func StatisticsGet ¶
func StatisticsGet(ctx context.Context) *Statistics
func WithStatistics ¶
func WithStatistics(ctx context.Context) (*Statistics, context.Context)
func (*Statistics) String ¶
func (s *Statistics) String() string
type StringIndexConst ¶
type StringIndexConst int
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
func (*VM) Eval ¶
Eval evaluates the query with the options given. Eval is thread safe. Return value is of ast.Value for now.
func (*VM) WithDataJSON ¶
WithDataJSON stores golang native data for the evaluation to use as 'data.'.
func (*VM) WithDataNamespace ¶
WithDataNamespace hooks an external namespace implementation to use as 'data.'.
func (*VM) WithExecutable ¶
func (vm *VM) WithExecutable(executable Executable) *VM