runtime

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package runtime implements the evaluation model for templates / instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator interface {
	DefaultDecision() model.DecisionValue

	Aggregate(cel.Program,
		interpreter.Activation,
		model.DecisionValue,
		model.Rule) (model.DecisionValue, error)
}

Aggregator defines the mechanism by which CEL evaluations within evaluator production rules are accumulated into a named decision emitted by the template runtime.

The aggregator starts with an initial decision and always only accumulates the previous value with the next. In this respect, the aggregator behaves like a continuous comprehension which is capable of indicating when to exit the comprehension by whether or not its marked final.

type AndAggregator

type AndAggregator struct {
	// contains filtered or unexported fields
}

AndAggregator accumulates boolean results until either a false is encountered, or the policy set is completely evaluated.

func (*AndAggregator) Aggregate

Aggregate combines the previous decision with the current value from CEl evaluation.

If the value is False, the decision is finalized as no additional information can change the aggregation result.

func (*AndAggregator) DefaultDecision

func (and *AndAggregator) DefaultDecision() model.DecisionValue

DefaultDecision returns a boolean decision initialized to 'true'.

type CollectAggregator

type CollectAggregator struct {
	// contains filtered or unexported fields
}

CollectAggregator accumulates each value emitted for the given decision name into a list of values associated with the decision.

func (*CollectAggregator) Aggregate

Aggregate appends the value produced by evaluating the CEL program (if not error) with the previous values observed for the decision.

Note: the collect aggregator does not quite follow CEL semantics with respect to list construction as the output decision value may include CEL types.Unknown values within it. It is up to the application to decide whether to error or resolve the unknowns.

func (*CollectAggregator) DefaultDecision

func (col *CollectAggregator) DefaultDecision() model.DecisionValue

DefaultDecision produces a decision whose default decision value is empty set.

type OrAggregator

type OrAggregator struct {
	// contains filtered or unexported fields
}

OrAggregator accumulates boolean results until either a true is encountered, or the policy set is has been completely evaluated.

func (*OrAggregator) Aggregate

Aggregate combines the value produced by the incoming CEL value with the previous value observed by the aggregator using CEL ORing semantics.

If the value is true, the decision is finalized as no additional information can change the aggregation result.

func (*OrAggregator) DefaultDecision

func (or *OrAggregator) DefaultDecision() model.DecisionValue

DefaultDecision produces a decision whose default decision value is 'false'.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template represents an evaluable version of a model.Template.

func NewTemplate

func NewTemplate(res model.Resolver,
	mdl *model.Template,
	opts ...TemplateOption) (*Template, error)

NewTemplate creates a validator / evaluator pair for a model.Template.

func (*Template) Eval

Eval returns the evaluation result of a policy instance against a given set of variables.

func (*Template) FindAggregator

func (t *Template) FindAggregator(name string) (Aggregator, bool)

FindAggregator returns the Aggregator for the decision if one is found.

func (*Template) Name

func (t *Template) Name() string

Name returns the template's metadata name value.

func (*Template) Validate

func (t *Template) Validate(src *model.Source, inst *model.Instance) *cel.Issues

Validate checks the content of an instance to ensure it conforms with the validation rules present within the template, if any.

type TemplateOption

type TemplateOption func(*Template) (*Template, error)

TemplateOption is a functional optoin for configuring template evaluation.

func DecisionAggregator

func DecisionAggregator(decision string, agg Aggregator) TemplateOption

DecisionAggregator registers an Aggregator for a given decision name.

func ExprOptions

func ExprOptions(opts ...cel.ProgramOption) TemplateOption

ExprOptions configues a set of options for use with constructing CEL programs within the template.

func Functions

func Functions(funcs ...*functions.Overload) TemplateOption

Functions configures the template runtime with function implementations that correspond with the compilation environment specification.

func Limits

func Limits(l *limits.Limits) TemplateOption

Limits configures limits which should be enforced during runtime evaluation.

func NewAndAggregator

func NewAndAggregator(name string) TemplateOption

NewAndAggregator returns a RuntimeOption which configures an ANDing aggregator for a given decision name.

func NewCollectAggregator

func NewCollectAggregator(name string) TemplateOption

NewCollectAggregator creates a new CollectAggregator which accumulates values emitted for the given decision name.

func NewOrAggregator

func NewOrAggregator(name string) TemplateOption

NewOrAggregator returns an OrAggregator which accumulates values into a boolean decision.

Jump to

Keyboard shortcuts

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