ir

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Package ir defines an intermediate representation (IR) for Rego.

The IR specifies an imperative execution model for Rego policies similar to a query plan in traditional databases.

Index

Constants

View Source
const (
	// Input is the local variable that refers to the global input document.
	Input = v1.Input

	// Data is the local variable that refers to the global data document.
	Data = v1.Data

	// Unused is the free local variable that can be allocated in a plan.
	Unused = v1.Unused
)

Variables

This section is empty.

Functions

func Pretty

func Pretty(w io.Writer, x interface{}) error

Pretty writes a human-readable representation of an IR object to w.

func Walk

func Walk(vis Visitor, x interface{}) error

Walk invokes the visitor for nodes under x.

Types

type ArrayAppendStmt

type ArrayAppendStmt = v1.ArrayAppendStmt

ArrayAppendStmt represents a dynamic append operation of a value onto an array.

type AssignIntStmt

type AssignIntStmt = v1.AssignIntStmt

AssignIntStmt represents an assignment of an integer value to a local variable.

type AssignVarOnceStmt

type AssignVarOnceStmt = v1.AssignVarOnceStmt

AssignVarOnceStmt represents an assignment of one local variable to another. If the target is defined, execution aborts with a conflict error.

TODO(tsandall): is there a better name for this?

type AssignVarStmt

type AssignVarStmt = v1.AssignVarStmt

AssignVarStmt represents an assignment of one local variable to another.

type Block

type Block = v1.Block

Block represents an ordered sequence of statements to execute. Blocks are executed until a return statement is encountered, a statement is undefined, or there are no more statements. If all statements are defined but no return statement is encountered, the block is undefined.

type BlockStmt

type BlockStmt = v1.BlockStmt

BlockStmt represents a nested block. Nested blocks and break statements can be used to short-circuit execution.

type Bool

type Bool = v1.Bool

Bool represents a constant boolean.

type BreakStmt

type BreakStmt = v1.BreakStmt

BreakStmt represents a jump out of the current block. The index specifies how many blocks to jump starting from zero (the current block). Execution will continue from the end of the block that is jumped to.

type BuiltinFunc

type BuiltinFunc = v1.BuiltinFunc

BuiltinFunc represents a built-in function that may be required by the policy.

type CallDynamicStmt

type CallDynamicStmt = v1.CallDynamicStmt

CallDynamicStmt represents an indirect (data) function call. The result should be stored in the result local.

type CallStmt

type CallStmt = v1.CallStmt

CallStmt represents a named function call. The result should be stored in the result local.

type DotStmt

type DotStmt = v1.DotStmt

DotStmt represents a lookup operation on a value (e.g., array, object, etc.) The source of a DotStmt may be a scalar value in which case the statement will be undefined.

type EqualStmt

type EqualStmt = v1.EqualStmt

EqualStmt represents an value-equality check of two local variables.

type Func

type Func = v1.Func

Func represents a named plan (function) that can be invoked. Functions accept one or more parameters and return a value. By convention, the input document and data documents are always passed as the first and second arguments (respectively).

type Funcs

type Funcs = v1.Funcs

Funcs represents a collection of planned functions to include in the policy.

type IsArrayStmt

type IsArrayStmt = v1.IsArrayStmt

IsArrayStmt represents a dynamic type check on a local variable.

type IsDefinedStmt

type IsDefinedStmt = v1.IsDefinedStmt

IsDefinedStmt represents a check of whether a local variable is defined.

type IsObjectStmt

type IsObjectStmt = v1.IsObjectStmt

IsObjectStmt represents a dynamic type check on a local variable.

type IsSetStmt added in v0.65.0

type IsSetStmt = v1.IsSetStmt

IsSetStmt represents a dynamic type check on a local variable.

type IsUndefinedStmt

type IsUndefinedStmt = v1.IsUndefinedStmt

IsUndefinedStmt represents a check of whether local variable is undefined.

type LenStmt

type LenStmt = v1.LenStmt

LenStmt represents a length() operation on a local variable. The result is stored in the target local variable.

type Local

type Local = v1.Local

Local represents a plan-scoped variable.

TODO(tsandall): should this be int32 for safety?

type Location

type Location = v1.Location

Location records the filen index, and the row and column inside that file that a statement can be connected to.

type MakeArrayStmt

type MakeArrayStmt = v1.MakeArrayStmt

MakeArrayStmt constructs a local variable that refers to an array value.

type MakeNullStmt

type MakeNullStmt = v1.MakeNullStmt

MakeNullStmt constructs a local variable that refers to a null value.

type MakeNumberIntStmt

type MakeNumberIntStmt = v1.MakeNumberIntStmt

MakeNumberIntStmt constructs a local variable that refers to an integer value.

type MakeNumberRefStmt

type MakeNumberRefStmt = v1.MakeNumberRefStmt

MakeNumberRefStmt constructs a local variable that refers to a number stored as a string.

type MakeObjectStmt

type MakeObjectStmt = v1.MakeObjectStmt

MakeObjectStmt constructs a local variable that refers to an object value.

type MakeSetStmt

type MakeSetStmt = v1.MakeSetStmt

MakeSetStmt constructs a local variable that refers to a set value.

type NopStmt

type NopStmt = v1.NopStmt

NopStmt adds a nop instruction. Useful during development and debugging only.

type NotEqualStmt

type NotEqualStmt = v1.NotEqualStmt

NotEqualStmt represents a != check of two local variables.

type NotStmt

type NotStmt = v1.NotStmt

NotStmt represents a negated statement.

type ObjectInsertOnceStmt

type ObjectInsertOnceStmt = v1.ObjectInsertOnceStmt

ObjectInsertOnceStmt represents a dynamic insert operation of a key/value pair into an object. If the key already exists and the value differs, execution aborts with a conflict error.

type ObjectInsertStmt

type ObjectInsertStmt = v1.ObjectInsertStmt

ObjectInsertStmt represents a dynamic insert operation of a key/value pair into an object.

type ObjectMergeStmt

type ObjectMergeStmt = v1.ObjectMergeStmt

ObjectMergeStmt performs a recursive merge of two object values. If either of the locals refer to non-object values this operation will abort with a conflict error. Overlapping object keys are merged recursively.

type Operand

type Operand = v1.Operand

Operand represents a value that a statement operates on.

type Plan

type Plan = v1.Plan

Plan represents an ordered series of blocks to execute. Plan execution stops when a return statement is reached. Blocks are executed in-order.

type Plans

type Plans = v1.Plans

Plans represents a collection of named query plans to expose in the policy.

type Policy

type Policy = v1.Policy

Policy represents a planned policy query.

type ResetLocalStmt

type ResetLocalStmt = v1.ResetLocalStmt

ResetLocalStmt resets a local variable to 0.

type ResultSetAddStmt

type ResultSetAddStmt = v1.ResultSetAddStmt

ResultSetAddStmt adds a value into the result set returned by the query plan.

type ReturnLocalStmt

type ReturnLocalStmt = v1.ReturnLocalStmt

ReturnLocalStmt represents a return statement that yields a local value.

type ScanStmt

type ScanStmt = v1.ScanStmt

ScanStmt represents a linear scan over a composite value. The source may be a scalar in which case the block will never execute.

type SetAddStmt

type SetAddStmt = v1.SetAddStmt

SetAddStmt represents a dynamic add operation of an element into a set.

type Static

type Static = v1.Static

Static represents a static data segment that is indexed into by the policy.

type Stmt

type Stmt = v1.Stmt

Stmt represents an operation (e.g., comparison, loop, dot, etc.) to execute.

type StringConst

type StringConst = v1.StringConst

StringConst represents a string value.

type StringIndex

type StringIndex = v1.StringIndex

StringIndex represents the index into the plan's list of constant strings of a constant string.

type Val

type Val = v1.Val

Val represents an abstract value that statements operate on. There are currently 3 types of values:

1. Local - a local variable that can refer to any type. 2. StringIndex - a string constant that refers to a compiled string. 3. Bool - a boolean constant.

type Visitor

type Visitor = v1.Visitor

Visitor defines the interface for visiting IR nodes.

type WithStmt

type WithStmt = v1.WithStmt

WithStmt replaces the Local or a portion of the document referred to by the Local with the Value and executes the contained block. If the Path is non-empty, the Value is upserted into the Local. If the intermediate nodes in the Local referred to by the Path do not exist, they will be created. When the WithStmt finishes the Local is reset to it's original value.

Directories

Path Synopsis
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended.
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended.

Jump to

Keyboard shortcuts

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