Documentation ¶
Overview ¶
Package runtime implements the evaluation model for templates / instances.
Index ¶
- type Aggregator
- type AndAggregator
- type CollectAggregator
- type OrAggregator
- type Template
- type TemplateOption
- func DecisionAggregator(decision string, agg Aggregator) TemplateOption
- func ExprOptions(opts ...cel.ProgramOption) TemplateOption
- func Functions(funcs ...*functions.Overload) TemplateOption
- func Limits(l *limits.Limits) TemplateOption
- func NewAndAggregator(name string) TemplateOption
- func NewCollectAggregator(name string) TemplateOption
- func NewOrAggregator(name string) TemplateOption
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 ¶
func (and *AndAggregator) Aggregate(prg cel.Program, vars interpreter.Activation, prev model.DecisionValue, rule model.Rule) (model.DecisionValue, error)
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 ¶
func (col *CollectAggregator) Aggregate(prg cel.Program, vars interpreter.Activation, prev model.DecisionValue, rule model.Rule) (model.DecisionValue, error)
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 ¶
func (or *OrAggregator) Aggregate(prg cel.Program, vars interpreter.Activation, prev model.DecisionValue, rule model.Rule) (model.DecisionValue, error)
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 ¶
func (t *Template) Eval(inst *model.Instance, vars interpreter.Activation, selector model.DecisionSelector) ([]model.DecisionValue, error)
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.
type TemplateOption ¶
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.