topdown

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 13 Imported by: 190

Documentation

Overview

Package topdown provides low-level query evaluation support.

The topdown implementation is a modified version of the standard top-down evaluation algorithm used in Datalog. References and comprehensions are evaluated eagerly while all other terms are evaluated lazily.

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.

Index

Constants

View Source
const (

	// InternalErr represents an unknown evaluation error.
	InternalErr = v1.InternalErr

	// CancelErr indicates the evaluation process was cancelled.
	CancelErr = v1.CancelErr

	// ConflictErr indicates a conflict was encountered during evaluation. For
	// instance, a conflict occurs if a rule produces multiple, differing values
	// for the same key in an object. Conflict errors indicate the policy does
	// not account for the data loaded into the policy engine.
	ConflictErr = v1.ConflictErr

	// TypeErr indicates evaluation stopped because an expression was applied to
	// a value of an inappropriate type.
	TypeErr = v1.TypeErr

	// BuiltinErr indicates a built-in function received a semantically invalid
	// input or encountered some kind of runtime error, e.g., connection
	// timeout, connection refused, etc.
	BuiltinErr = v1.BuiltinErr

	// WithMergeErr indicates that the real and replacement data could not be merged.
	WithMergeErr = v1.WithMergeErr
)
View Source
const (
	// HTTPSendInternalErr represents a runtime evaluation error.
	HTTPSendInternalErr = v1.HTTPSendInternalErr

	// HTTPSendNetworkErr represents a network error.
	HTTPSendNetworkErr = v1.HTTPSendNetworkErr
)
View Source
const (
	// EnterOp is emitted when a new query is about to be evaluated.
	EnterOp = v1.EnterOp

	// ExitOp is emitted when a query has evaluated to true.
	ExitOp = v1.ExitOp

	// EvalOp is emitted when an expression is about to be evaluated.
	EvalOp = v1.EvalOp

	// RedoOp is emitted when an expression, rule, or query is being re-evaluated.
	RedoOp = v1.RedoOp

	// SaveOp is emitted when an expression is saved instead of evaluated
	// during partial evaluation.
	SaveOp = v1.SaveOp

	// FailOp is emitted when an expression evaluates to false.
	FailOp = v1.FailOp

	// DuplicateOp is emitted when a query has produced a duplicate value. The search
	// will stop at the point where the duplicate was emitted and backtrack.
	DuplicateOp = v1.DuplicateOp

	// NoteOp is emitted when an expression invokes a tracing built-in function.
	NoteOp = v1.NoteOp

	// IndexOp is emitted during an expression evaluation to represent lookup
	// matches.
	IndexOp = v1.IndexOp

	// WasmOp is emitted when resolving a ref using an external
	// Resolver.
	WasmOp = v1.WasmOp

	// UnifyOp is emitted when two terms are unified.  Node will be set to an
	// equality expression with the two terms.  This Node will not have location
	// info.
	UnifyOp           = v1.UnifyOp
	FailedAssertionOp = v1.FailedAssertionOp
)

Variables

This section is empty.

Functions

func IsCancel added in v0.5.11

func IsCancel(err error) bool

IsCancel returns true if err was caused by cancellation.

func IsError added in v0.4.5

func IsError(err error) bool

IsError returns true if the err is an Error.

func NewPrintHook added in v0.34.0

func NewPrintHook(w io.Writer) print.Hook

func PrettyEvent added in v0.66.0

func PrettyEvent(w io.Writer, e *Event, opts PrettyEventOpts) error

func PrettyTrace added in v0.2.0

func PrettyTrace(w io.Writer, trace []*Event)

PrettyTrace pretty prints the trace to the writer.

func PrettyTraceWithLocation added in v0.17.2

func PrettyTraceWithLocation(w io.Writer, trace []*Event)

PrettyTraceWithLocation prints the trace to the writer and includes location information

func PrettyTraceWithOpts added in v0.66.0

func PrettyTraceWithOpts(w io.Writer, trace []*Event, opts PrettyTraceOptions)

func RegisterBuiltinFunc

func RegisterBuiltinFunc(name string, f BuiltinFunc)

RegisterBuiltinFunc adds a new built-in function to the evaluation engine.

func RegisterFunctionalBuiltin1 deprecated added in v0.4.0

func RegisterFunctionalBuiltin1(name string, fun FunctionalBuiltin1)

Deprecated: Functional-style builtins are deprecated. Use RegisterBuiltinFunc instead.

func RegisterFunctionalBuiltin2 deprecated added in v0.4.0

func RegisterFunctionalBuiltin2(name string, fun FunctionalBuiltin2)

Deprecated: Functional-style builtins are deprecated. Use RegisterBuiltinFunc instead.

func RegisterFunctionalBuiltin3 deprecated added in v0.4.0

func RegisterFunctionalBuiltin3(name string, fun FunctionalBuiltin3)

Deprecated: Functional-style builtins are deprecated. Use RegisterBuiltinFunc instead.

func RegisterFunctionalBuiltin4 deprecated added in v0.9.2

func RegisterFunctionalBuiltin4(name string, fun FunctionalBuiltin4)

Deprecated: Functional-style builtins are deprecated. Use RegisterBuiltinFunc instead.

Types

type BufferTracer added in v0.2.0

type BufferTracer = v1.BufferTracer

BufferTracer implements the Tracer and QueryTracer interface by simply buffering all events received.

func NewBufferTracer added in v0.2.0

func NewBufferTracer() *BufferTracer

NewBufferTracer returns a new BufferTracer.

type Builtin added in v0.14.0

type Builtin = v1.Builtin

Builtin represents a built-in function that queries can call.

type BuiltinContext added in v0.5.11

type BuiltinContext = v1.BuiltinContext

BuiltinContext contains context from the evaluator that may be used by built-in functions.

type BuiltinEmpty deprecated added in v0.4.0

type BuiltinEmpty = v1.Builtin

Deprecated: The BuiltinEmpty type is no longer needed. Use nil return values instead.

type BuiltinFunc

type BuiltinFunc = v1.BuiltinFunc

BuiltinFunc defines an interface for implementing built-in functions. The built-in function is called with the plugged operands from the call (including the output operands.) The implementation should evaluate the operands and invoke the iterator for each successful/defined output value.

func GetBuiltin added in v0.17.2

func GetBuiltin(name string) BuiltinFunc

GetBuiltin returns a built-in function implementation, nil if no built-in found.

type Cancel added in v0.5.1

type Cancel = v1.Cancel

Cancel defines the interface for cancelling topdown queries. Cancel operations are thread-safe and idempotent.

func NewCancel added in v0.5.1

func NewCancel() Cancel

NewCancel returns a new Cancel object.

type Error

type Error = v1.Error

Error is the error type returned by the Eval and Query functions when an evaluation error occurs.

type Event added in v0.2.0

type Event = v1.Event

Event contains state associated with a tracing event.

type FunctionalBuiltin1 deprecated added in v0.4.0

type FunctionalBuiltin1 = v1.FunctionalBuiltin1 //nolint:staticcheck // SA1019: Intentional use of deprecated type.

Deprecated: Functional-style builtins are deprecated. Use BuiltinFunc instead.

type FunctionalBuiltin2 deprecated added in v0.4.0

type FunctionalBuiltin2 = v1.FunctionalBuiltin2 //nolint:staticcheck // SA1019: Intentional use of deprecated type.

Deprecated: Functional-style builtins are deprecated. Use BuiltinFunc instead.

type FunctionalBuiltin3 deprecated added in v0.4.0

type FunctionalBuiltin3 = v1.FunctionalBuiltin3 //nolint:staticcheck // SA1019: Intentional use of deprecated type.

Deprecated: Functional-style builtins are deprecated. Use BuiltinFunc instead.

type FunctionalBuiltin4 deprecated added in v0.9.2

type FunctionalBuiltin4 = v1.FunctionalBuiltin4 //nolint:staticcheck // SA1019: Intentional use of deprecated type.

Deprecated: Functional-style builtins are deprecated. Use BuiltinFunc instead.

type Halt added in v0.25.0

type Halt = v1.Halt

Halt is a special error type that built-in function implementations return to indicate that policy evaluation should stop immediately.

type Instrumentation added in v0.7.0

type Instrumentation = v1.Instrumentation

Instrumentation implements helper functions to instrument query evaluation to diagnose performance issues. Instrumentation may be expensive in some cases, so it is disabled by default.

func NewInstrumentation added in v0.7.0

func NewInstrumentation(m metrics.Metrics) *Instrumentation

NewInstrumentation returns a new Instrumentation object. Performance diagnostics recorded on this Instrumentation object will stored in m.

type Op added in v0.2.0

type Op = v1.Op

Op defines the types of tracing events.

type PrettyEventOpts added in v0.66.0

type PrettyEventOpts = v1.PrettyEventOpts

type PrettyTraceOptions added in v0.66.0

type PrettyTraceOptions = v1.PrettyTraceOptions

type Query

type Query = v1.Query

Query provides a configurable interface for performing query evaluation.

func NewQuery added in v0.5.11

func NewQuery(query ast.Body) *Query

NewQuery returns a new Query object that can be run.

type QueryResult added in v0.2.1

type QueryResult = v1.QueryResult

QueryResult represents a single result returned by a query. The result contains bindings for all variables that appear in the query.

type QueryResultSet added in v0.2.1

type QueryResultSet = v1.QueryResultSet

QueryResultSet represents a collection of results returned by a query.

type QueryTracer added in v0.21.0

type QueryTracer = v1.QueryTracer

QueryTracer defines the interface for tracing in the top-down evaluation engine. The implementation can provide additional configuration to modify the tracing behavior for query evaluations.

func WrapLegacyTracer added in v0.22.0

func WrapLegacyTracer(tracer Tracer) QueryTracer

WrapLegacyTracer will create a new QueryTracer which wraps an older Tracer instance.

type TraceConfig added in v0.21.0

type TraceConfig = v1.TraceConfig

TraceConfig defines some common configuration for Tracer implementations

type Tracer

type Tracer = v1.Tracer

Tracer defines the interface for tracing in the top-down evaluation engine. Deprecated: Use QueryTracer instead.

type VarMetadata added in v0.15.0

type VarMetadata = v1.VarMetadata

VarMetadata provides some user facing information about a variable in some policy.

type VirtualCache added in v0.68.0

type VirtualCache = v1.VirtualCache

VirtualCache defines the interface for a cache that stores the results of evaluated virtual documents (rules). The cache is a stack of frames, where each frame is a mapping from references to values.

func NewVirtualCache added in v0.68.0

func NewVirtualCache() VirtualCache

Directories

Path Synopsis
Package builtins contains utilities for implementing built-in functions.
Package builtins contains utilities for implementing built-in functions.
Package cache defines the inter-query cache interface that can cache data across queries
Package cache defines the inter-query cache interface that can cache data across queries
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.
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.
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