Documentation
¶
Index ¶
Constants ¶
const DefaultCacheSize = 1024
DefaultCacheSize is the default size for the expression cache.
Variables ¶
This section is empty.
Functions ¶
func ExtractEQMatches ¶
ExtractEQMatches extracts equality sub expressions from the match expression. It only extracts `attribute == literal` type equality matches. It returns a list of <attribute name, value> such that if **any** of these comparisons is false, the expression will evaluate to false. These sub expressions can be hoisted out of the match clause and evaluated separately. For example destination.service == "abc" -- Used to index rules by destination service. context.protocol == "tcp" -- Used to filter rules by context
Types ¶
type AttributeDescriptorFinder ¶
type AttributeDescriptorFinder interface {
// GetAttribute finds attribute descriptor in the vocabulary. returns nil if not found.
GetAttribute(name string) *cfgpb.AttributeManifest_AttributeInfo
}
AttributeDescriptorFinder finds attribute descriptors.
type Evaluator ¶
type Evaluator interface {
// Eval evaluates given expression using the attribute bag
Eval(expr string, attrs attribute.Bag) (interface{}, error)
// Eval evaluates given expression using the attribute bag to a string
EvalString(expr string, attrs attribute.Bag) (string, error)
PredicateEvaluator
TypeChecker
}
Evaluator evaluates an expression written in the implementation defined expression language. It uses attribute.Bag as variable bindings.
func NewCEXLEvaluator ¶
NewCEXLEvaluator returns a new Evaluator of this type.
type Expression ¶
Expression is a simplified expression AST
func Parse ¶
func Parse(src string) (ex *Expression, err error)
Parse parses a given expression to ast.Expression.
func (*Expression) EvalType ¶
func (e *Expression) EvalType(attrs AttributeDescriptorFinder, fMap map[string]FuncBase) (valueType dpb.ValueType, err error)
EvalType Function an expression using fMap and attribute vocabulary. Returns the type that this expression evaluates to.
func (*Expression) String ¶
func (e *Expression) String() string
String produces postfix version with all operators converted to function names
type Func ¶
type Func interface {
FuncBase
// Call performs the function call. It is guaranteed
// that call will be made with correct arity.
// may panic.
Call(attrs attribute.Bag, args []*Expression, fMap map[string]FuncBase) (interface{}, error)
}
Func implements a function call. It needs to know details about Expressions and attribute bag.
type FuncBase ¶
type FuncBase interface {
// Name uniquely identifies the function.
Name() string
// ReturnType specifies the return type of this function.
ReturnType() config.ValueType
// ArgTypes specifies the argument types in order expected by the function.
ArgTypes() []config.ValueType
}
FuncBase defines the interface that every expression function must implement.
type Function ¶
type Function struct {
Name string
Args []*Expression
}
Function models a function with multiple parameters 1st arg can be thought of as the receiver.
type PredicateEvaluator ¶
type PredicateEvaluator interface {
// EvalPredicate evaluates given predicate using the attribute bag
EvalPredicate(expr string, attrs attribute.Bag) (bool, error)
}
PredicateEvaluator evaluates a predicate to true or false
type TypeChecker ¶
type TypeChecker interface {
// EvalType produces the type of an expression or an error if the type cannot be evaluated.
// TODO: we probably want to use a golang type rather than pb.ValueType (a proto).
EvalType(expr string, finder AttributeDescriptorFinder) (pb.ValueType, error)
// AssertType evaluates the type of expr using the attribute set; if the evaluated type is equal to
// the expected type we return nil, and return an error otherwise.
AssertType(expr string, finder AttributeDescriptorFinder, expectedType pb.ValueType) error
}
TypeChecker validates a given expression for type safety.