env
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package env provides a representation of a CEL environment.
Index¶
- type Config
- func (c *Config) AddExtensions(exts ...*Extension) *Config
- func (c *Config) AddFeatures(feats ...*Feature) *Config
- func (c *Config) AddFunctionDecls(funcs ...*decls.FunctionDecl) *Config
- func (c *Config) AddFunctions(funcs ...*Function) *Config
- func (c *Config) AddImports(imps ...*Import) *Config
- func (c *Config) AddValidators(vals ...*Validator) *Config
- func (c *Config) AddVariableDecls(vars ...*decls.VariableDecl) *Config
- func (c *Config) AddVariables(vars ...*Variable) *Config
- func (c *Config) SetContainer(container string) *Config
- func (c *Config) SetContextVariable(ctx *ContextVariable) *Config
- func (c *Config) SetStdLib(subset *LibrarySubset) *Config
- func (c *Config) Validate() error
- type ContextVariable
- type Extension
- type Feature
- type Function
- type Import
- type LibrarySubset
- func (lib *LibrarySubset) AddExcludedFunctions(funcs ...*Function) *LibrarySubset
- func (lib *LibrarySubset) AddExcludedMacros(macros ...string) *LibrarySubset
- func (lib *LibrarySubset) AddIncludedFunctions(funcs ...*Function) *LibrarySubset
- func (lib *LibrarySubset) AddIncludedMacros(macros ...string) *LibrarySubset
- func (lib *LibrarySubset) SetDisableMacros(value bool) *LibrarySubset
- func (lib *LibrarySubset) SetDisabled(value bool) *LibrarySubset
- func (lib *LibrarySubset) SubsetFunction(fn *decls.FunctionDecl) (*decls.FunctionDecl, bool)
- func (lib *LibrarySubset) SubsetMacro(macroFunction string) bool
- func (lib *LibrarySubset) Validate() error
- type Overload
- type TypeDesc
- type Validator
- type Variable
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeConfig¶
type Config struct {Namestring `yaml:"name,omitempty"`Descriptionstring `yaml:"description,omitempty"`Containerstring `yaml:"container,omitempty"`Imports []*Import `yaml:"imports,omitempty"`StdLib *LibrarySubset `yaml:"stdlib,omitempty"`Extensions []*Extension `yaml:"extensions,omitempty"`ContextVariable *ContextVariable `yaml:"context_variable,omitempty"`Variables []*Variable `yaml:"variables,omitempty"`Functions []*Function `yaml:"functions,omitempty"`Validators []*Validator `yaml:"validators,omitempty"`Features []*Feature `yaml:"features,omitempty"`}Config represents a serializable form of the CEL environment configuration.
Note: custom validations, feature flags, and performance tuning parameters are not (yet)considered part of the core CEL environment configuration and should be managed separatelyuntil a common convention for such settings is developed.
func (*Config)AddExtensions¶
AddExtensions appends a set of extensions to the config.
func (*Config)AddFeatures¶
AddFeatures appends one or more features to the config.
func (*Config)AddFunctionDecls¶
func (c *Config) AddFunctionDecls(funcs ...*decls.FunctionDecl) *Config
AddFunctionDecls adds one or more functions to the config, converting them to serializable values first.
FunctionDecl inputs are expected to be well-formed.
func (*Config)AddFunctions¶
AddFunctions adds one or more functions to the config.
func (*Config)AddImports¶
AddImports appends a set of imports to the config.
func (*Config)AddValidators¶
AddValidators appends one or more validators to the config.
func (*Config)AddVariableDecls¶
func (c *Config) AddVariableDecls(vars ...*decls.VariableDecl) *Config
AddVariableDecls adds one or more variables to the config, converting them to serializable values first.
VariableDecl inputs are expected to be well-formed.
func (*Config)AddVariables¶
AddVariables adds one or more vairables to the config.
func (*Config)SetContainer¶
SetContainer configures the container name for this configuration.
func (*Config)SetContextVariable¶
func (c *Config) SetContextVariable(ctx *ContextVariable) *Config
SetContextVariable configures the ContextVariable for this configuration.
func (*Config)SetStdLib¶
func (c *Config) SetStdLib(subset *LibrarySubset) *Config
SetStdLib configures the LibrarySubset for the standard library.
typeContextVariable¶
type ContextVariable struct {// TypeName represents the fully qualified typename of the context variable.// Currently, only protobuf types are supported.TypeNamestring `yaml:"type_name"`}ContextVariable represents a structured message whose fields are to be treated as the top-levelvariable identifiers within CEL expressions.
funcNewContextVariable¶
func NewContextVariable(typeNamestring) *ContextVariable
NewContextVariable returns a serializable context variable with a specific type name.
func (*ContextVariable)Validate¶
func (ctx *ContextVariable) Validate()error
Validate validates the context-variable configuration is well-formed.
typeExtension¶
type Extension struct {// Name is either the LibraryName() or some short-hand simple identifier which is understood by the config-handler.Namestring `yaml:"name"`// Version may either be an unsigned long value or the string 'latest'. If empty, the value is treated as '0'.Versionstring `yaml:"version,omitempty"`}Extension represents a named and optionally versioned extension library configured in the environment.
funcNewExtension¶
NewExtension creates a serializable Extension from a name and version string.
func (*Extension)VersionNumber¶
VersionNumber returns the parsed version string, or an error if the version cannot be parsed.
typeFeature¶
Feature represents a named boolean feature flag supported by CEL.
funcNewFeature¶
NewFeature creates a new feature flag with a boolean enablement flag.
typeFunction¶
type Function struct {Namestring `yaml:"name"`Descriptionstring `yaml:"description,omitempty"`Overloads []*Overload `yaml:"overloads,omitempty"`}Function represents the serializable format of a function and its overloads.
funcNewFunction¶
NewFunction creates a serializable function and overload set.
funcNewFunctionWithDoc¶added inv0.25.0
NewFunctionWithDoc creates a serializable function and overload set.
func (*Function)AsCELFunction¶
AsCELFunction converts the serializable form of the Function into CEL environment declaration.
typeImport¶
type Import struct {Namestring `yaml:"name"`}Import represents a type name that will be appreviated by its simple name usingthe cel.Abbrevs() option.
typeLibrarySubset¶
type LibrarySubset struct {// Disabled indicates whether the library has been disabled, typically only used for// default-enabled libraries like stdlib.Disabledbool `yaml:"disabled,omitempty"`// DisableMacros disables macros for the given library.DisableMacrosbool `yaml:"disable_macros,omitempty"`// IncludeMacros specifies a set of macro function names to include in the subset.IncludeMacros []string `yaml:"include_macros,omitempty"`// ExcludeMacros specifies a set of macro function names to exclude from the subset.// Note: if IncludeMacros is non-empty, then ExcludeFunctions is ignored.ExcludeMacros []string `yaml:"exclude_macros,omitempty"`// IncludeFunctions specifies a set of functions to include in the subset.//// Note: the overloads specified in the subset need only specify their ID.// Note: if IncludeFunctions is non-empty, then ExcludeFunctions is ignored.IncludeFunctions []*Function `yaml:"include_functions,omitempty"`// ExcludeFunctions specifies the set of functions to exclude from the subset.//// Note: the overloads specified in the subset need only specify their ID.ExcludeFunctions []*Function `yaml:"exclude_functions,omitempty"`}LibrarySubset indicates a subset of the macros and function supported by a subsettable library.
funcNewLibrarySubset¶
func NewLibrarySubset() *LibrarySubset
NewLibrarySubset returns an empty library subsetting config which permits all library features.
func (*LibrarySubset)AddExcludedFunctions¶
func (lib *LibrarySubset) AddExcludedFunctions(funcs ...*Function) *LibrarySubset
AddExcludedFunctions deny-lists one or more functions from the subset.
func (*LibrarySubset)AddExcludedMacros¶
func (lib *LibrarySubset) AddExcludedMacros(macros ...string) *LibrarySubset
AddExcludedMacros deny-lists one or more macros by function name.
func (*LibrarySubset)AddIncludedFunctions¶
func (lib *LibrarySubset) AddIncludedFunctions(funcs ...*Function) *LibrarySubset
AddIncludedFunctions allow-lists one or more functions from the subset.
Note, this option will override any excluded functions.
func (*LibrarySubset)AddIncludedMacros¶
func (lib *LibrarySubset) AddIncludedMacros(macros ...string) *LibrarySubset
AddIncludedMacros allow-lists one or more macros by function name.
Note, this option will override any excluded macros.
func (*LibrarySubset)SetDisableMacros¶
func (lib *LibrarySubset) SetDisableMacros(valuebool) *LibrarySubset
SetDisableMacros disables the macros for the library.
func (*LibrarySubset)SetDisabled¶
func (lib *LibrarySubset) SetDisabled(valuebool) *LibrarySubset
SetDisabled disables or enables the library.
func (*LibrarySubset)SubsetFunction¶
func (lib *LibrarySubset) SubsetFunction(fn *decls.FunctionDecl) (*decls.FunctionDecl,bool)
SubsetFunction produces a function declaration which matches the supported subset, or nilif the function is not supported by the LibrarySubset.
For IncludeFunctions, if the function does not specify a set of overloads to include, thewhole function definition is included. If overloads are set, then a new function whichincludes only the specified overloads is produced.
For ExcludeFunctions, if the function does not specify a set of overloads to exclude, thewhole function definition is excluded. If overloads are set, then a new function whichincludes only the permitted overloads is produced.
func (*LibrarySubset)SubsetMacro¶
func (lib *LibrarySubset) SubsetMacro(macroFunctionstring)bool
SubsetMacro indicates whether the macro function should be included in the library subset.
func (*LibrarySubset)Validate¶
func (lib *LibrarySubset) Validate()error
Validate validates the library configuration is well-formed.
For example, setting both the IncludeMacros and ExcludeMacros together could be confusingand create a broken expectation, likewise for IncludeFunctions and ExcludeFunctions.
typeOverload¶
type Overload struct {IDstring `yaml:"id"`Examples []string `yaml:"examples,omitempty"`Target *TypeDesc `yaml:"target,omitempty"`Args []*TypeDesc `yaml:"args,omitempty"`Return *TypeDesc `yaml:"return,omitempty"`}Overload represents the serializable format of a function overload.
funcNewMemberOverload¶
func NewMemberOverload(idstring, target *TypeDesc, args []*TypeDesc, ret *TypeDesc, examples ...string) *Overload
NewMemberOverload returns a new serializable representation of a member (receiver) overload.
funcNewOverload¶
NewOverload returns a new serializable representation of a global overload.
func (*Overload)AsFunctionOption¶
AsFunctionOption converts the serializable form of the Overload into a function declaration option.
typeTypeDesc¶
type TypeDesc struct {TypeNamestring `yaml:"type_name"`Params []*TypeDesc `yaml:"params,omitempty"`IsTypeParambool `yaml:"is_type_param,omitempty"`}TypeDesc represents the serializable format of a CEL *types.Type value.
funcNewTypeDesc¶
NewTypeDesc describes a simple or complex type with parameters.
funcNewTypeParam¶
NewTypeParam describe a type-param type.
funcSerializeTypeDesc¶added inv0.25.0
SerializeTypeDesc converts a CEL native *types.Type to a serializable TypeDesc.
typeValidator¶
Validator represents a named validator with an optional map-based configuration object.
Note: the map-keys must directly correspond to the internal representation of the originalvalidator, and should only use primitive scalar types as values at this time.
funcNewValidator¶
NewValidator returns a named Validator instance.
func (*Validator)ConfigValue¶
ConfigValue retrieves the value associated with the config key name, if one exists.
typeVariable¶
type Variable struct {Namestring `yaml:"name"`Descriptionstring `yaml:"description,omitempty"`// Type represents the type declaration for the variable.//// Deprecated: use the embedded *TypeDesc fields directly.Type *TypeDesc `yaml:"type,omitempty"`// TypeDesc is an embedded set of fields allowing for the specification of the Variable type.*TypeDesc `yaml:",inline"`}Variable represents a typed variable declaration which will be published via thecel.VariableDecls() option.
funcNewVariable¶
NewVariable returns a serializable variable from a name and type definition
funcNewVariableWithDoc¶added inv0.25.0
NewVariableWithDoc returns a serializable variable from a name, type definition, and doc string.
func (*Variable)AsCELVariable¶
AsCELVariable converts the serializable form of the Variable into a CEL environment declaration.