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 rego exposes high level APIs for evaluating Rego policies.
Index ¶
- func BuiltinErrorList(list *[]topdown.Error) func(r *Rego)
- func Capabilities(c *ast.Capabilities) func(r *Rego)
- func Compiler(c *ast.Compiler) func(r *Rego)
- func DisableInlining(paths []string) func(r *Rego)
- func DistributedTracingOpts(tr tracing.Options) func(r *Rego)
- func Dump(w io.Writer) func(r *Rego)
- func EnablePrintStatements(yes bool) func(r *Rego)
- func Function1(decl *Function, f Builtin1) func(*Rego)
- func Function2(decl *Function, f Builtin2) func(*Rego)
- func Function3(decl *Function, f Builtin3) func(*Rego)
- func Function4(decl *Function, f Builtin4) func(*Rego)
- func FunctionDecl(decl *Function) func(*Rego)
- func FunctionDyn(decl *Function, f BuiltinDyn) func(*Rego)
- func GenerateJSON(f func(*ast.Term, *EvalContext) (interface{}, error)) func(r *Rego)
- func Imports(p []string) func(r *Rego)
- func Input(x interface{}) func(r *Rego)
- func Instrument(yes bool) func(r *Rego)
- func InterQueryBuiltinCache(c cache.InterQueryCache) func(r *Rego)
- func InterQueryBuiltinValueCache(c cache.InterQueryValueCache) func(r *Rego)
- func IsPartialEvaluationNotEffectiveErr(err error) bool
- func Load(paths []string, filter loader.Filter) func(r *Rego)
- func LoadBundle(path string) func(r *Rego)
- func Metrics(m metrics.Metrics) func(r *Rego)
- func Module(filename, input string) func(r *Rego)
- func NDBuiltinCache(c builtins.NDBCache) func(r *Rego)
- func NewHaltError(err error) error
- func Package(p string) func(r *Rego)
- func ParsedBundle(name string, b *bundle.Bundle) func(r *Rego)
- func ParsedImports(imp []*ast.Import) func(r *Rego)
- func ParsedInput(x ast.Value) func(r *Rego)
- func ParsedModule(module *ast.Module) func(*Rego)
- func ParsedPackage(pkg *ast.Package) func(r *Rego)
- func ParsedQuery(q ast.Body) func(r *Rego)
- func ParsedUnknowns(unknowns []*ast.Term) func(r *Rego)
- func PartialNamespace(ns string) func(r *Rego)
- func PrintHook(h print.Hook) func(r *Rego)
- func PrintTrace(w io.Writer, r *Rego)
- func PrintTraceWithLocation(w io.Writer, r *Rego)
- func Query(q string) func(r *Rego)
- func QueryTracer(t topdown.QueryTracer) func(r *Rego)
- func RegisterBuiltin1(decl *Function, impl Builtin1)
- func RegisterBuiltin2(decl *Function, impl Builtin2)
- func RegisterBuiltin3(decl *Function, impl Builtin3)
- func RegisterBuiltin4(decl *Function, impl Builtin4)
- func RegisterBuiltinDyn(decl *Function, impl BuiltinDyn)
- func RegisterPlugin(name string, p TargetPlugin)
- func Resolver(ref ast.Ref, r resolver.Resolver) func(r *Rego)
- func Runtime(term *ast.Term) func(r *Rego)
- func Schemas(x *ast.SchemaSet) func(r *Rego)
- func Seed(r io.Reader) func(*Rego)
- func SetRegoVersion(version ast.RegoVersion) func(r *Rego)
- func ShallowInlining(yes bool) func(r *Rego)
- func SkipBundleVerification(yes bool) func(r *Rego)
- func SkipPartialNamespace(yes bool) func(r *Rego)
- func Store(s storage.Store) func(r *Rego)
- func StoreReadAST(enabled bool) func(r *Rego)
- func Strict(yes bool) func(r *Rego)
- func StrictBuiltinErrors(yes bool) func(r *Rego)
- func Target(t string) func(r *Rego)
- func Time(x time.Time) func(r *Rego)
- func Trace(yes bool) func(r *Rego)
- func Tracer(t topdown.Tracer) func(r *Rego)
- func Transaction(txn storage.Transaction) func(r *Rego)
- func Unknowns(unknowns []string) func(r *Rego)
- func UnsafeBuiltins(unsafeBuiltins map[string]struct{}) func(r *Rego)
- type Builtin1
- type Builtin2
- type Builtin3
- type Builtin4
- type BuiltinContext
- type BuiltinDyn
- type CompileContext
- type CompileOption
- type CompileResult
- type ErrorDetails
- type Errors
- type EvalContext
- type EvalOption
- func EvalCopyMaps(yes bool) EvalOption
- func EvalDisableInlining(paths []ast.Ref) EvalOption
- func EvalEarlyExit(enabled bool) EvalOption
- func EvalInput(input interface{}) EvalOption
- func EvalInstrument(instrument bool) EvalOption
- func EvalInterQueryBuiltinCache(c cache.InterQueryCache) EvalOption
- func EvalInterQueryBuiltinValueCache(c cache.InterQueryValueCache) EvalOption
- func EvalMetrics(metric metrics.Metrics) EvalOption
- func EvalNDBuiltinCache(c builtins.NDBCache) EvalOption
- func EvalParsedInput(input ast.Value) EvalOption
- func EvalParsedUnknowns(unknowns []*ast.Term) EvalOption
- func EvalPartialNamespace(ns string) EvalOption
- func EvalPrintHook(ph print.Hook) EvalOption
- func EvalQueryTracer(tracer topdown.QueryTracer) EvalOption
- func EvalResolver(ref ast.Ref, r resolver.Resolver) EvalOption
- func EvalRuleIndexing(enabled bool) EvalOption
- func EvalSeed(r io.Reader) EvalOption
- func EvalSortSets(yes bool) EvalOption
- func EvalTime(x time.Time) EvalOption
- func EvalTracer(tracer topdown.Tracer) EvalOption
- func EvalTransaction(txn storage.Transaction) EvalOption
- func EvalUnknowns(unknowns []string) EvalOption
- func EvalVirtualCache(vc topdown.VirtualCache) EvalOption
- type ExpressionValue
- type Function
- type HaltError
- type Location
- type PartialQueries
- type PartialResult
- type PrepareConfig
- type PrepareOption
- type PreparedEvalQuery
- type PreparedPartialQuery
- type Rego
- type Result
- type ResultSet
- type TargetPlugin
- type TargetPluginEval
- type Vars
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuiltinErrorList ¶ added in v0.48.0
BuiltinErrorList supplies an error slice to store built-in function errors.
func Capabilities ¶ added in v0.32.0
func Capabilities(c *ast.Capabilities) func(r *Rego)
Capabilities configures the underlying compiler's capabilities. This option is ignored for module compilation if the caller supplies the compiler.
func DisableInlining ¶ added in v0.13.0
DisableInlining adds a set of paths to exclude from partial evaluation inlining.
func DistributedTracingOpts ¶ added in v0.36.0
DistributedTracingOpts sets the options to be used by distributed tracing.
func Dump ¶ added in v0.10.0
Dump returns an argument that sets the writer to dump debugging information to.
func EnablePrintStatements ¶ added in v0.34.0
EnablePrintStatements enables print() calls. If this option is not provided, print() calls will be erased from the policy. This option only applies to queries and policies that passed as raw strings, i.e., this function will not have any affect if the caller supplies the ast.Compiler instance.
func Function1 ¶ added in v0.14.0
Function1 returns an option that adds a built-in function to the Rego object.
func Function2 ¶ added in v0.14.0
Function2 returns an option that adds a built-in function to the Rego object.
func Function3 ¶ added in v0.14.0
Function3 returns an option that adds a built-in function to the Rego object.
func Function4 ¶ added in v0.14.0
Function4 returns an option that adds a built-in function to the Rego object.
func FunctionDecl ¶ added in v0.15.1
FunctionDecl returns an option that adds a custom-built-in function __declaration__. NO implementation is provided. This is used for non-interpreter execution envs (e.g., Wasm).
func FunctionDyn ¶ added in v0.14.0
func FunctionDyn(decl *Function, f BuiltinDyn) func(*Rego)
FunctionDyn returns an option that adds a built-in function to the Rego object.
func GenerateJSON ¶ added in v0.32.0
func GenerateJSON(f func(*ast.Term, *EvalContext) (interface{}, error)) func(r *Rego)
GenerateJSON sets the AST to JSON converter for the results.
func Input ¶
func Input(x interface{}) func(r *Rego)
Input returns an argument that sets the Rego input document. Input should be a native Go value representing the input document.
func Instrument ¶ added in v0.7.0
Instrument returns an argument that enables instrumentation for diagnosing performance issues.
func InterQueryBuiltinCache ¶ added in v0.23.0
func InterQueryBuiltinCache(c cache.InterQueryCache) func(r *Rego)
InterQueryBuiltinCache sets the inter-query cache that built-in functions can utilize during evaluation.
func InterQueryBuiltinValueCache ¶ added in v0.69.0
func InterQueryBuiltinValueCache(c cache.InterQueryValueCache) func(r *Rego)
InterQueryBuiltinValueCache sets the inter-query value cache that built-in functions can utilize during evaluation.
func IsPartialEvaluationNotEffectiveErr ¶ added in v0.21.0
IsPartialEvaluationNotEffectiveErr returns true if err is an error returned by this package to indicate that partial evaluation was ineffective.
func Load ¶ added in v0.14.0
Load returns an argument that adds a filesystem path to load data and Rego modules from. Any file with a *.rego, *.yaml, or *.json extension will be loaded. The path can be either a directory or file, directories are loaded recursively. The optional ignore string patterns can be used to filter which files are used. The Load option can only be used once. Note: Loading files will require a write transaction on the store.
func LoadBundle ¶ added in v0.14.0
LoadBundle returns an argument that adds a filesystem path to load a bundle from. The path can be a compressed bundle file or a directory to be loaded as a bundle. Note: Loading bundles will require a write transaction on the store.
func NDBuiltinCache ¶ added in v0.44.0
NDBuiltinCache sets the non-deterministic builtins cache.
func NewHaltError ¶ added in v0.31.0
NewHaltError wraps an error such that the evaluation process will stop when it occurs.
func ParsedBundle ¶ added in v0.14.0
ParsedBundle returns an argument that adds a bundle to be loaded.
func ParsedImports ¶ added in v0.7.0
ParsedImports returns an argument that adds Rego imports to the query's context.
func ParsedInput ¶ added in v0.7.0
ParsedInput returns an argument that sets the Rego input document.
func ParsedModule ¶ added in v0.13.0
ParsedModule returns an argument that adds a parsed Rego module. If a string module with the same filename name is added, it will override the parsed module.
func ParsedPackage ¶ added in v0.7.0
ParsedPackage returns an argument that sets the Rego package on the query's context.
func ParsedQuery ¶ added in v0.7.0
ParsedQuery returns an argument that sets the Rego query.
func ParsedUnknowns ¶ added in v0.9.0
ParsedUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.
func PartialNamespace ¶ added in v0.7.0
PartialNamespace returns an argument that sets the namespace to use for partial evaluation results. The namespace must be a valid package path component.
func PrintHook ¶ added in v0.34.0
PrintHook sets the object to use for handling print statement outputs.
func PrintTrace ¶ added in v0.10.2
PrintTrace is a helper function to write a human-readable version of the trace to the writer w.
func PrintTraceWithLocation ¶ added in v0.20.0
PrintTraceWithLocation is a helper function to write a human-readable version of the trace to the writer w.
func QueryTracer ¶ added in v0.22.0
func QueryTracer(t topdown.QueryTracer) func(r *Rego)
QueryTracer returns an argument that adds a query tracer to r.
func RegisterBuiltin1 ¶ added in v0.19.0
RegisterBuiltin1 adds a built-in function globally inside the OPA runtime.
func RegisterBuiltin2 ¶ added in v0.19.0
RegisterBuiltin2 adds a built-in function globally inside the OPA runtime.
func RegisterBuiltin3 ¶ added in v0.19.0
RegisterBuiltin3 adds a built-in function globally inside the OPA runtime.
func RegisterBuiltin4 ¶ added in v0.19.0
RegisterBuiltin4 adds a built-in function globally inside the OPA runtime.
func RegisterBuiltinDyn ¶ added in v0.19.0
func RegisterBuiltinDyn(decl *Function, impl BuiltinDyn)
RegisterBuiltinDyn adds a built-in function globally inside the OPA runtime.
func RegisterPlugin ¶ added in v0.53.0
func RegisterPlugin(name string, p TargetPlugin)
func Runtime ¶ added in v0.10.0
Runtime returns an argument that sets the runtime data to provide to the evaluation engine.
func Seed ¶ added in v0.30.0
Seed sets a reader that will seed randomization required by built-in functions. If a seed is not provided crypto/rand.Reader is used.
func SetRegoVersion ¶ added in v0.60.0
func SetRegoVersion(version ast.RegoVersion) func(r *Rego)
func ShallowInlining ¶ added in v0.22.0
ShallowInlining prevents rules that depend on unknown values from being inlined. Rules that only depend on known values are inlined.
func SkipBundleVerification ¶ added in v0.22.0
SkipBundleVerification skips verification of a signed bundle.
func SkipPartialNamespace ¶ added in v0.20.0
SkipPartialNamespace disables namespacing of partial evalution results for support rules generated from policy. Synthetic support rules are still namespaced.
func Store ¶ added in v0.5.0
Store returns an argument that sets the policy engine's data storage layer.
If using the Load, LoadBundle, or ParsedBundle options then a transaction must also be provided via the Transaction() option. After loading files or bundles the transaction should be aborted or committed.
func StoreReadAST ¶ added in v0.70.0
StoreReadAST returns an argument that sets whether the store should eagerly convert data to AST values.
Only applicable when no store has been set on the Rego object through the Store option.
func StrictBuiltinErrors ¶ added in v0.25.0
StrictBuiltinErrors tells the evaluator to treat all built-in function errors as fatal errors.
func Time ¶ added in v0.23.0
Time sets the wall clock time to use during policy evaluation. Prepared queries do not inherit this parameter. Use EvalTime to set the wall clock time when executing a prepared query.
func Tracer ¶ added in v0.5.3
Tracer returns an argument that adds a query tracer to r. Deprecated: Use QueryTracer instead.
func Transaction ¶ added in v0.5.2
func Transaction(txn storage.Transaction) func(r *Rego)
Transaction returns an argument that sets the transaction to use for storage layer operations.
Requires the store associated with the transaction to be provided via the Store() option. If using Load(), LoadBundle(), or ParsedBundle() options the transaction will likely require write params.
func Unknowns ¶ added in v0.7.0
Unknowns returns an argument that sets the values to treat as unknown during partial evaluation.
func UnsafeBuiltins ¶ added in v0.13.0
UnsafeBuiltins sets the built-in functions to treat as unsafe and not allow. This option is ignored for module compilation if the caller supplies the compiler. This option is always honored for query compilation. Provide an empty (non-nil) map to disable checks on queries.
Types ¶
type BuiltinContext ¶ added in v0.14.0
type BuiltinContext = v1.BuiltinContext
BuiltinContext contains additional attributes from the evaluator that built-in functions can use, e.g., the request context.Context, caches, etc.
type BuiltinDyn ¶ added in v0.14.0
type BuiltinDyn = v1.BuiltinDyn
BuiltinDyn defines a built-in function that accepts a list of arguments.
type CompileContext ¶ added in v0.11.0
type CompileContext = v1.CompileContext
CompileContext contains options for Compile calls.
type CompileOption ¶ added in v0.11.0
type CompileOption = v1.CompileOption
CompileOption defines a function to set options on Compile calls.
func CompilePartial ¶ added in v0.11.0
func CompilePartial(yes bool) CompileOption
CompilePartial defines an option to control whether partial evaluation is run before the query is planned and compiled.
type CompileResult ¶ added in v0.10.0
type CompileResult = v1.CompileResult
CompileResult represents the result of compiling a Rego query, zero or more Rego modules, and arbitrary contextual data into an executable.
type ErrorDetails ¶ added in v0.32.0
type ErrorDetails = v1.ErrorDetails
ErrorDetails interface is satisfied by an error that provides further details.
type EvalContext ¶ added in v0.11.0
type EvalContext = v1.EvalContext
EvalContext defines the set of options allowed to be set at evaluation time. Any other options will need to be set on a new Rego object.
type EvalOption ¶ added in v0.11.0
type EvalOption = v1.EvalOption
EvalOption defines a function to set an option on an EvalConfig
func EvalCopyMaps ¶ added in v0.47.0
func EvalCopyMaps(yes bool) EvalOption
EvalCopyMaps causes the evaluator to copy `map[string]interface{}`s before returning them.
func EvalDisableInlining ¶ added in v0.13.0
func EvalDisableInlining(paths []ast.Ref) EvalOption
EvalDisableInlining returns an argument that adds a set of paths to exclude from partial evaluation inlining.
func EvalEarlyExit ¶ added in v0.35.0
func EvalEarlyExit(enabled bool) EvalOption
EvalEarlyExit will disable 'early exit' optimizations for the evaluation. This should only be used when tracing in debug mode.
func EvalInput ¶ added in v0.11.0
func EvalInput(input interface{}) EvalOption
EvalInput configures the input for a Prepared Query's evaluation
func EvalInstrument ¶ added in v0.11.0
func EvalInstrument(instrument bool) EvalOption
EvalInstrument enables or disables instrumenting for a Prepared Query's evaluation
func EvalInterQueryBuiltinCache ¶ added in v0.23.0
func EvalInterQueryBuiltinCache(c cache.InterQueryCache) EvalOption
EvalInterQueryBuiltinCache sets the inter-query cache that built-in functions can utilize during evaluation.
func EvalInterQueryBuiltinValueCache ¶ added in v0.69.0
func EvalInterQueryBuiltinValueCache(c cache.InterQueryValueCache) EvalOption
EvalInterQueryBuiltinValueCache sets the inter-query value cache that built-in functions can utilize during evaluation.
func EvalMetrics ¶ added in v0.11.0
func EvalMetrics(metric metrics.Metrics) EvalOption
EvalMetrics configures the metrics for a Prepared Query's evaluation
func EvalNDBuiltinCache ¶ added in v0.44.0
func EvalNDBuiltinCache(c builtins.NDBCache) EvalOption
EvalNDBuiltinCache sets the non-deterministic builtin cache that built-in functions can use during evaluation.
func EvalParsedInput ¶ added in v0.11.0
func EvalParsedInput(input ast.Value) EvalOption
EvalParsedInput configures the input for a Prepared Query's evaluation
func EvalParsedUnknowns ¶ added in v0.11.0
func EvalParsedUnknowns(unknowns []*ast.Term) EvalOption
EvalParsedUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.
func EvalPartialNamespace ¶ added in v0.11.0
func EvalPartialNamespace(ns string) EvalOption
EvalPartialNamespace returns an argument that sets the namespace to use for partial evaluation results. The namespace must be a valid package path component.
func EvalPrintHook ¶ added in v0.35.0
func EvalPrintHook(ph print.Hook) EvalOption
EvalPrintHook sets the object to use for handling print statement outputs.
func EvalQueryTracer ¶ added in v0.22.0
func EvalQueryTracer(tracer topdown.QueryTracer) EvalOption
EvalQueryTracer configures a tracer for a Prepared Query's evaluation
func EvalResolver ¶ added in v0.25.0
func EvalResolver(ref ast.Ref, r resolver.Resolver) EvalOption
EvalResolver sets a Resolver for a specified ref path for this evaluation.
func EvalRuleIndexing ¶ added in v0.15.0
func EvalRuleIndexing(enabled bool) EvalOption
EvalRuleIndexing will disable indexing optimizations for the evaluation. This should only be used when tracing in debug mode.
func EvalSeed ¶ added in v0.30.0
func EvalSeed(r io.Reader) EvalOption
EvalSeed sets a reader that will seed randomization required by built-in functions. If a seed is not provided crypto/rand.Reader is used.
func EvalSortSets ¶ added in v0.27.1
func EvalSortSets(yes bool) EvalOption
EvalSortSets causes the evaluator to sort sets before returning them as JSON arrays.
func EvalTime ¶ added in v0.23.0
func EvalTime(x time.Time) EvalOption
EvalTime sets the wall clock time to use during policy evaluation. time.now_ns() calls will return this value.
func EvalTracer ¶ added in v0.11.0
func EvalTracer(tracer topdown.Tracer) EvalOption
EvalTracer configures a tracer for a Prepared Query's evaluation Deprecated: Use EvalQueryTracer instead.
func EvalTransaction ¶ added in v0.11.0
func EvalTransaction(txn storage.Transaction) EvalOption
EvalTransaction configures the Transaction for a Prepared Query's evaluation
func EvalUnknowns ¶ added in v0.11.0
func EvalUnknowns(unknowns []string) EvalOption
EvalUnknowns returns an argument that sets the values to treat as unknown during partial evaluation.
func EvalVirtualCache ¶ added in v0.68.0
func EvalVirtualCache(vc topdown.VirtualCache) EvalOption
EvalVirtualCache sets the topdown.VirtualCache to use for evaluation. This is optional, and if not set, the default cache is used.
type ExpressionValue ¶
type ExpressionValue = v1.ExpressionValue
ExpressionValue defines the value of an expression in a Rego query.
type HaltError ¶ added in v0.31.0
HaltError is an error type to return from a custom function implementation that will abort the evaluation process (analogous to topdown.Halt).
type PartialQueries ¶ added in v0.9.0
type PartialQueries = v1.PartialQueries
PartialQueries contains the queries and support modules produced by partial evaluation.
type PartialResult ¶ added in v0.7.0
type PartialResult = v1.PartialResult
PartialResult represents the result of partial evaluation. The result can be used to generate a new query that can be run when inputs are known.
type PrepareConfig ¶ added in v0.11.0
type PrepareConfig = v1.PrepareConfig
PrepareConfig holds settings to control the behavior of the Prepare call.
type PrepareOption ¶ added in v0.11.0
type PrepareOption = v1.PrepareOption
PrepareOption defines a function to set an option to control the behavior of the Prepare call.
func WithBuiltinFuncs ¶ added in v0.56.0
func WithBuiltinFuncs(bis map[string]*topdown.Builtin) PrepareOption
WithBuiltinFuncs carries the rego.Function{1,2,3} per-query function definitions to the target plugins.
func WithNoInline ¶ added in v0.13.0
func WithNoInline(paths []string) PrepareOption
WithNoInline adds a set of paths to exclude from partial evaluation inlining.
func WithPartialEval ¶ added in v0.11.0
func WithPartialEval() PrepareOption
WithPartialEval configures an option for PrepareForEval which will have it perform partial evaluation while preparing the query (similar to rego.Rego#PartialResult)
type PreparedEvalQuery ¶ added in v0.11.0
type PreparedEvalQuery = v1.PreparedEvalQuery
PreparedEvalQuery holds the prepared Rego state that has been pre-processed for subsequent evaluations.
type PreparedPartialQuery ¶ added in v0.11.0
type PreparedPartialQuery = v1.PreparedPartialQuery
PreparedPartialQuery holds the prepared Rego state that has been pre-processed for partial evaluations.
type ResultSet ¶
ResultSet represents a collection of output from Rego evaluation. An empty result set represents an undefined query.
type TargetPlugin ¶ added in v0.53.0
type TargetPlugin = v1.TargetPlugin
type TargetPluginEval ¶ added in v0.53.0
type TargetPluginEval = v1.TargetPluginEval