cel

package
v2.0.0-...-a7294fb Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SelfIdent   = "self"
	SecretIdent = "secret"
)

Variables

View Source
var (
	StringType = cel.StringType
	MapType    = cel.MapType(cel.StringType, cel.StringType)
)

Functions

func AllowedOutputTypes

func AllowedOutputTypes() []*cel.Type

AllowedOutputTypes defines the set of allowed CEL expression output types supported by ASO. Any CEL expression whose result is a type other than one of these will be rejected.

func CheckOutputTypeAllowed

func CheckOutputTypeAllowed(ast *cel.Ast, allowed ...*cel.Type) error

func NewEnv

func NewEnv(resource reflect.Type) (*cel.Env, error)

NewEnv returns a new cel.Env accepting two parameters:

self: The resource itself. The resulting Env contains knowledge of all types referenced by self, meaning CEL expressions involving self must all pass the type-checker.

secret: Optional (may be nil/empty), a map[string]string containing secrets retrieved from Azure. The keys of the secret are the same as the keys in the operatorSpec.secrets structure.

func ParseStructTag

func ParseStructTag(field reflect.StructField) string

func RegisterEvaluator

func RegisterEvaluator(e ExpressionEvaluator)

TODO: We could put this instead in genruntime if we thought it made more sense to keep the "static value for use by webhooks" TODO: there. RegisterEvaluator registers an evaluator as the default expression evaluator.

Types

type CompilationResult

type CompilationResult struct {
	AST     *cel.Ast
	Program cel.Program
}

func Compile

func Compile(env *cel.Env, expression string) (*CompilationResult, error)

Compile builds the specified expression and returns a CompilationResult containing the cel.AST and cel.Program.

type EnvCache

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

EnvCache caches cel.Env's for a fixed duration.

func NewEnvCache

func NewEnvCache(
	metrics asometrics.CEL,
	log logr.Logger,
	newEnv func(resource reflect.Type) (*cel.Env, error),
) *EnvCache

NewEnvCache creates a new EnvCache

func (*EnvCache) Get

func (c *EnvCache) Get(resource reflect.Type) (*cel.Env, error)

func (*EnvCache) Start

func (c *EnvCache) Start()

func (*EnvCache) Stop

func (c *EnvCache) Stop()

type ExpressionEvaluator

type ExpressionEvaluator interface {
	CompileAndRun(expression string, self any, secret map[string]string) (*ExpressionResult, error)
	Check(expression string, self any) (*cel.Type, error)
	FindSecretUsage(expression string, self any) (set.Set[string], error)
	Start()
	Stop()
}

ExpressionEvaluator defines an interface for evaluating expressions based on self (the resource) and an optional secret parameter (containing the secrets)

func Evaluator

func Evaluator() ExpressionEvaluator

Evaluator returns the default expression evaluator

func NewExpressionEvaluator

func NewExpressionEvaluator(
	opts ...ExpressionEvaluatorOption,
) (ExpressionEvaluator, error)

type ExpressionEvaluatorOption

type ExpressionEvaluatorOption func(e *expressionEvaluator) (*expressionEvaluator, error)

func Cache

Cache configures the program cache for the expression evaluator. The program cache is used to avoid re-compiling expressions or creating cel.Envs more than necessary.

func Log

Log configures CEL logging

func Metrics

func Metrics(metrics asometrics.CEL) ExpressionEvaluatorOption

Metrics configures CEL prometheus metrics

type ExpressionResult

type ExpressionResult struct {
	Value  string
	Values map[string]string
}

type ProgramCache

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

func NewProgramCache

func NewProgramCache(
	envCache *EnvCache,
	metrics asometrics.CEL,
	log logr.Logger,
	compile func(env *cel.Env, expression string) (*CompilationResult, error),
) *ProgramCache

NewProgramCache starts the program cache

func (*ProgramCache) Get

func (c *ProgramCache) Get(resource reflect.Type, expression string) (*CompilationResult, error)

func (*ProgramCache) Start

func (c *ProgramCache) Start()

func (*ProgramCache) Stop

func (c *ProgramCache) Stop()

type ProgramCacher

type ProgramCacher interface {
	Start()
	Stop()
	Get(resource reflect.Type, expression string) (*CompilationResult, error)
}

type UnCache

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

UnCache is a cache that doesn't cache, useful mostly for testing purposes

func NewUnCache

func NewUnCache(
	newEnv func(resource reflect.Type) (*cel.Env, error),
	compile func(env *cel.Env, expression string) (*CompilationResult, error),
) *UnCache

func (*UnCache) Get

func (c *UnCache) Get(resource reflect.Type, expression string) (*CompilationResult, error)

func (*UnCache) Start

func (c *UnCache) Start()

func (*UnCache) Stop

func (c *UnCache) Stop()

Jump to

Keyboard shortcuts

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