condition

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEvaluationFailed = fmt.Errorf("failed to evaluate relationship condition")

Functions

func NewEvaluationError

func NewEvaluationError(condition string, cause error) error

Types

type CompilationError

type CompilationError struct {
	Condition string
	Cause     error
}

func (*CompilationError) Error

func (e *CompilationError) Error() string

func (*CompilationError) Unwrap

func (e *CompilationError) Unwrap() error

type EvaluableCondition

type EvaluableCondition struct {
	*openfgav1.Condition
	// contains filtered or unexported fields
}

EvaluableCondition represents a condition that can eventually be evaluated given a CEL expression and a set of parameters. Calling .Evaluate() will optionally call .Compile() which validates and compiles the expression and parameter type definitions if it hasn't been done already.

func NewCompiled

func NewCompiled(condition *openfgav1.Condition) (*EvaluableCondition, error)

NewCompiled returns a new EvaluableCondition with a validated and compiled expression.

func NewUncompiled

func NewUncompiled(condition *openfgav1.Condition) *EvaluableCondition

NewUncompiled returns a new EvaluableCondition that has not validated and compiled its expression.

func (*EvaluableCondition) CastContextToTypedParameters

func (e *EvaluableCondition) CastContextToTypedParameters(contextMap map[string]*structpb.Value) (map[string]any, error)

CastContextToTypedParameters converts the provided context to typed condition parameters and returns an error if any additional context fields are provided that are not defined by the evaluable condition.

func (*EvaluableCondition) Compile

func (e *EvaluableCondition) Compile() error

Compile compiles a condition expression with a CEL environment constructed from the condition's parameter type definitions into a valid AST that can be evaluated at a later time.

func (*EvaluableCondition) Evaluate

func (e *EvaluableCondition) Evaluate(
	ctx context.Context,
	contextMaps ...map[string]*structpb.Value,
) (EvaluationResult, error)

Evaluate evaluates the provided CEL condition expression with a CEL environment constructed from the condition's parameter type definitions and using the context maps provided. If more than one source map of context is provided, and if the keys provided in those map context(s) are overlapping, then the overlapping key for the last most context wins.

func (*EvaluableCondition) WithInterruptCheckFrequency added in v1.4.1

func (e *EvaluableCondition) WithInterruptCheckFrequency(checkFrequency uint) *EvaluableCondition

WithInterruptCheckFrequency defines the upper limit on the number of iterations within a CEL comprehension to evaluate before CEL will interrupt evaluation and check for cancellation. within a comprehension on the EvaluableCondition and returns the mutated EvaluableCondition. The expectation is that this is called on the Uncompiled condition because it modifies the behavior of the CEL program that is constructed after Compile.

func (*EvaluableCondition) WithMaxEvaluationCost

func (e *EvaluableCondition) WithMaxEvaluationCost(cost uint64) *EvaluableCondition

WithMaxEvaluationCost enables CEL evaluation cost enforcement on the EvaluableCondition and returns the mutated EvaluableCondition. The expectation is that this is called on the Uncompiled condition because it modifies the behavior of the CEL program that is constructed after Compile.

func (*EvaluableCondition) WithTrackEvaluationCost

func (e *EvaluableCondition) WithTrackEvaluationCost() *EvaluableCondition

WithTrackEvaluationCost enables CEL evaluation cost on the EvaluableCondition and returns the mutated EvaluableCondition. The expectation is that this is called on the Uncompiled condition because it modifies the behavior of the CEL program that is constructed after Compile.

type EvaluationError

type EvaluationError struct {
	Condition string
	Cause     error
}

func (*EvaluationError) Error

func (e *EvaluationError) Error() string

func (*EvaluationError) Unwrap

func (e *EvaluationError) Unwrap() error

type EvaluationResult

type EvaluationResult struct {
	Cost              uint64
	ConditionMet      bool
	MissingParameters []string
}

type ParameterTypeError

type ParameterTypeError struct {
	Condition string
	Cause     error
}

func (*ParameterTypeError) Error

func (e *ParameterTypeError) Error() string

func (*ParameterTypeError) Unwrap

func (e *ParameterTypeError) Unwrap() error

Directories

Path Synopsis
Package metrics provides various metric and telemetry definitions for OpenFGA Conditions.
Package metrics provides various metric and telemetry definitions for OpenFGA Conditions.

Jump to

Keyboard shortcuts

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