Documentation
¶
Index ¶
- Constants
- Variables
- func Escape(ident string) (string, bool)
- func FieldTypeMap(path string, t *DeclType) map[string]*DeclType
- func Unescape(escaped string) (string, bool)
- type CIDR
- type CompilationError
- type DeclField
- type DeclType
- func NewListType(elem *DeclType, maxItems int64) *DeclType
- func NewMapType(key, elem *DeclType, maxProperties int64) *DeclType
- func NewObjectType(name string, fields map[string]*DeclField) *DeclType
- func NewSimpleTypeWithMinSize(name string, celType *cel.Type, zeroVal ref.Val, minSize int64) *DeclType
- func (t *DeclType) CelType() *cel.Type
- func (t *DeclType) DefaultValue() ref.Val
- func (t *DeclType) ExprType() (*exprpb.Type, error)
- func (t *DeclType) FindField(name string) (*DeclField, bool)
- func (t *DeclType) HasTrait(trait int) bool
- func (t *DeclType) IsList() bool
- func (t *DeclType) IsMap() bool
- func (t *DeclType) IsObject() bool
- func (t *DeclType) MaybeAssignTypeName(name string) *DeclType
- func (t *DeclType) String() string
- func (t *DeclType) TypeName() string
- type DeclTypeProvider
- func (rt *DeclTypeProvider) EnumValue(enumName string) ref.Val
- func (rt *DeclTypeProvider) EnvOptions(tp types.Provider) ([]cel.EnvOption, error)
- func (rt *DeclTypeProvider) FindDeclType(typeName string) (*DeclType, bool)
- func (rt *DeclTypeProvider) FindIdent(identName string) (ref.Val, bool)
- func (rt *DeclTypeProvider) FindStructFieldNames(typeName string) ([]string, bool)
- func (rt *DeclTypeProvider) FindStructFieldType(typeName, fieldName string) (*types.FieldType, bool)
- func (rt *DeclTypeProvider) FindStructType(typeName string) (*types.Type, bool)
- func (rt *DeclTypeProvider) NativeToValue(val interface{}) ref.Val
- func (rt *DeclTypeProvider) NewValue(typeName string, fields map[string]ref.Val) ref.Val
- func (rt *DeclTypeProvider) SetRecognizeKeywordAsFieldName(recognize bool)
- func (rt *DeclTypeProvider) TypeNames() []string
- func (rt *DeclTypeProvider) WithTypeProvider(tp types.Provider) (*DeclTypeProvider, error)
- type DynValue
- func (dv *DynValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (dv *DynValue) DeclType() *DeclType
- func (dv *DynValue) Equal(other ref.Val) ref.Val
- func (dv *DynValue) ExprValue() ref.Val
- func (dv *DynValue) SetValue(value interface{}) error
- func (dv *DynValue) Type() ref.Type
- func (dv *DynValue) Value() interface{}
- type EncodeStyle
- type Error
- type ErrorType
- type Field
- type Format
- type IP
- type ListValue
- func (lv *ListValue) Add(other ref.Val) ref.Val
- func (lv *ListValue) Append(entry *DynValue)
- func (lv *ListValue) Contains(val ref.Val) ref.Val
- func (lv *ListValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (lv *ListValue) ConvertToType(t ref.Type) ref.Val
- func (lv *ListValue) Equal(other ref.Val) ref.Val
- func (lv *ListValue) Get(idx ref.Val) ref.Val
- func (lv *ListValue) Iterator() traits.Iterator
- func (lv *ListValue) Size() ref.Val
- func (lv *ListValue) Type() ref.Type
- func (lv *ListValue) Value() interface{}
- type MapValue
- func (sv MapValue) AddField(field *Field)
- func (m *MapValue) Contains(key ref.Val) ref.Val
- func (sv MapValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (m *MapValue) ConvertToObject(declType *DeclType) *ObjectValue
- func (m *MapValue) ConvertToType(t ref.Type) ref.Val
- func (m *MapValue) Equal(other ref.Val) ref.Val
- func (m *MapValue) Find(name ref.Val) (ref.Val, bool)
- func (m *MapValue) Get(key ref.Val) ref.Val
- func (sv MapValue) GetField(name string) (*Field, bool)
- func (sv MapValue) IsSet(key ref.Val) ref.Val
- func (m *MapValue) Iterator() traits.Iterator
- func (m *MapValue) Size() ref.Val
- func (m *MapValue) Type() ref.Type
- func (m *MapValue) Value() interface{}
- type MultilineStringValue
- type ObjectValue
- func (sv ObjectValue) AddField(field *Field)
- func (sv ObjectValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (o *ObjectValue) ConvertToType(t ref.Type) ref.Val
- func (o *ObjectValue) Equal(other ref.Val) ref.Val
- func (o *ObjectValue) Get(name ref.Val) ref.Val
- func (sv ObjectValue) GetField(name string) (*Field, bool)
- func (sv ObjectValue) IsSet(key ref.Val) ref.Val
- func (o *ObjectValue) Type() ref.Type
- func (o *ObjectValue) Value() interface{}
- type PlainTextValue
- type Quantity
- type URL
Constants ¶
const (
// DefaultMaxRequestSizeBytes is the size of the largest request that will be accepted
DefaultMaxRequestSizeBytes = celconfig.MaxRequestSizeBytes
// MaxDurationSizeJSON
// OpenAPI duration strings follow RFC 3339, section 5.6 - see the comment on maxDatetimeSizeJSON
MaxDurationSizeJSON = 32
// MaxDatetimeSizeJSON
// OpenAPI datetime strings follow RFC 3339, section 5.6, and the longest possible
// such string is 9999-12-31T23:59:59.999999999Z, which has length 30 - we add 2
// to allow for quotation marks
MaxDatetimeSizeJSON = 32
// MinDurationSizeJSON
// Golang allows a string of 0 to be parsed as a duration, so that plus 2 to account for
// quotation marks makes 3
MinDurationSizeJSON = 3
// JSONDateSize is the size of a date serialized as part of a JSON object
// RFC 3339 dates require YYYY-MM-DD, and then we add 2 to allow for quotation marks
JSONDateSize = 12
// MinDatetimeSizeJSON is the minimal length of a datetime formatted as RFC 3339
// RFC 3339 datetimes require a full date (YYYY-MM-DD) and full time (HH:MM:SS), and we add 3 for
// quotation marks like always in addition to the capital T that separates the date and time
MinDatetimeSizeJSON = 21
// MinStringSize is the size of literal ""
MinStringSize = 2
// MinBoolSize is the length of literal true
MinBoolSize = 4
// MinNumberSize is the length of literal 0
MinNumberSize = 1
MaxNameFormatRegexSize = 128
)
Variables ¶
var (
FormatObject = decls.NewObjectType("kubernetes.NamedFormat")
FormatType = cel.ObjectType("kubernetes.NamedFormat")
)
var (
QuantityObject = decls.NewObjectType("kubernetes.Quantity")
QuantityType = cel.ObjectType("kubernetes.Quantity")
)
var (
// AnyType is equivalent to the CEL 'protobuf.Any' type in that the value may have any of the
// types supported.
AnyType = NewSimpleTypeWithMinSize("any", cel.AnyType, nil, 1)
// BoolType is equivalent to the CEL 'bool' type.
BoolType = NewSimpleTypeWithMinSize("bool", cel.BoolType, types.False, MinBoolSize)
// BytesType is equivalent to the CEL 'bytes' type.
BytesType = NewSimpleTypeWithMinSize("bytes", cel.BytesType, types.Bytes([]byte{}), MinStringSize)
// DoubleType is equivalent to the CEL 'double' type which is a 64-bit floating point value.
DoubleType = NewSimpleTypeWithMinSize("double", cel.DoubleType, types.Double(0), MinNumberSize)
// DurationType is equivalent to the CEL 'duration' type.
DurationType = NewSimpleTypeWithMinSize("duration", cel.DurationType, types.Duration{Duration: time.Duration(0)}, MinDurationSizeJSON)
// DateType is equivalent to the CEL 'date' type.
DateType = NewSimpleTypeWithMinSize("date", cel.TimestampType, types.Timestamp{Time: time.Time{}}, JSONDateSize)
// DynType is the equivalent of the CEL 'dyn' concept which indicates that the type will be
// determined at runtime rather than compile time.
DynType = NewSimpleTypeWithMinSize("dyn", cel.DynType, nil, 1)
// IntType is equivalent to the CEL 'int' type which is a 64-bit signed int.
IntType = NewSimpleTypeWithMinSize("int", cel.IntType, types.IntZero, MinNumberSize)
// NullType is equivalent to the CEL 'null_type'.
NullType = NewSimpleTypeWithMinSize("null_type", cel.NullType, types.NullValue, 4)
// StringType is equivalent to the CEL 'string' type which is expected to be a UTF-8 string.
// StringType values may either be string literals or expression strings.
StringType = NewSimpleTypeWithMinSize("string", cel.StringType, types.String(""), MinStringSize)
// TimestampType corresponds to the well-known protobuf.Timestamp type supported within CEL.
// Note that both the OpenAPI date and date-time types map onto TimestampType, so not all types
// labeled as Timestamp will necessarily have the same MinSerializedSize.
TimestampType = NewSimpleTypeWithMinSize("timestamp", cel.TimestampType, types.Timestamp{Time: time.Time{}}, JSONDateSize)
// QuantityDeclType wraps a [QuantityType] and makes it usable with functions that expect
// a [DeclType].
QuantityDeclType = NewSimpleTypeWithMinSize("quantity", QuantityType, Quantity{Quantity: resource.NewQuantity(0, resource.DecimalSI)}, 8)
// UintType is equivalent to the CEL 'uint' type.
UintType = NewSimpleTypeWithMinSize("uint", cel.UintType, types.Uint(0), 1)
// ListType is equivalent to the CEL 'list' type.
ListType = NewListType(AnyType, noMaxLength)
// MapType is equivalent to the CEL 'map' type.
MapType = NewMapType(AnyType, AnyType, noMaxLength)
)
var (
URLObject = decls.NewObjectType("kubernetes.URL")
URLType = cel.ObjectType("kubernetes.URL")
)
var (
CIDRType = cel.OpaqueType("net.CIDR")
)
var ErrCompilation = fmt.Errorf("%w: compilation error", ErrInvalid)
ErrCompilation is the basic error that occurs when the expression fails to compile. Any CompilationError wraps ErrCompilation. ErrCompilation wraps ErrInvalid
var ErrInternal = fmt.Errorf("internal")
ErrInternal the basic error that occurs when the expression fails to evaluate due to internal reasons. Any Error that has the Type of ErrorInternal is considered equal to ErrInternal
var ErrInvalid = fmt.Errorf("invalid")
ErrInvalid is the basic error that occurs when the expression fails to evaluate but not due to internal reasons. Any Error that has the Type of ErrorInvalid is considered equal to ErrInvalid.
var ErrOutOfBudget = fmt.Errorf("out of budget")
ErrOutOfBudget is the basic error that occurs when the expression fails due to exceeding budget.
var ErrRequired = fmt.Errorf("required")
ErrRequired is the basic error that occurs when the expression is required but absent. Any Error that has the Type of ErrorRequired is considered equal to ErrRequired.
var (
IPType = cel.OpaqueType("net.IP")
)
Functions ¶
func Escape ¶
func Escape(ident string) (string, bool)
Escape escapes ident and returns a CEL identifier (of the form '[a-zA-Z_][a-zA-Z0-9_]*'), or returns false if the ident does not match the supported input format of `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*`. Escaping Rules:
- '__' escapes to '__underscores__'
- '.' escapes to '__dot__'
- '-' escapes to '__dash__'
- '/' escapes to '__slash__'
- Identifiers that exactly match a CEL RESERVED keyword escape to '__{keyword}__'. The keywords are: "true", "false", "null", "in", "as", "break", "const", "continue", "else", "for", "function", "if", "import", "let", loop", "package", "namespace", "return".
func FieldTypeMap ¶
func FieldTypeMap(path string, t *DeclType) map[string]*DeclType
FieldTypeMap constructs a map of the field and object types nested within a given type.
Types ¶
type CIDR ¶ added in v0.30.0
type CIDR struct {
netip.Prefix
}
CIDR provides a CEL representation of an network address.
func (CIDR) ConvertToNative ¶ added in v0.30.0
func (d CIDR) ConvertToNative(typeDesc reflect.Type) (any, error)
ConvertToNative implements ref.Val.ConvertToNative.
func (CIDR) ConvertToType ¶ added in v0.30.0
func (d CIDR) ConvertToType(typeVal ref.Type) ref.Val
ConvertToType implements ref.Val.ConvertToType.
func (CIDR) Equal ¶ added in v0.30.0
func (d CIDR) Equal(other ref.Val) ref.Val
Equal implements ref.Val.Equal.
type CompilationError ¶ added in v0.31.0
type CompilationError struct {
Issues *cel.Issues
// contains filtered or unexported fields
}
CompilationError indicates an error during expression compilation. It wraps ErrCompilation.
func NewCompilationError ¶ added in v0.31.0
func NewCompilationError(issues *cel.Issues) *CompilationError
NewCompilationError wraps a cel.Issues to indicate a compilation failure.
type DeclField ¶
type DeclField struct {
Name string
Type *DeclType
Required bool
// contains filtered or unexported fields
}
DeclField describes the name, ordinal, and optionality of a field declaration within a type.
func NewDeclField ¶
func NewDeclField(name string, declType *DeclType, required bool, enumValues []interface{}, defaultValue interface{}) *DeclField
func (*DeclField) DefaultValue ¶
func (f *DeclField) DefaultValue() ref.Val
DefaultValue returns the zero value associated with the field.
func (*DeclField) EnumValues ¶
func (f *DeclField) EnumValues() []ref.Val
EnumValues returns the set of values that this field may take.
type DeclType ¶
type DeclType struct {
fmt.Stringer
// Fields contains a map of escaped CEL identifier field names to field declarations.
Fields map[string]*DeclField
KeyType *DeclType
ElemType *DeclType
TypeParam bool
Metadata map[string]string
MaxElements int64
// MinSerializedSize represents the smallest possible size in bytes that
// the DeclType could be serialized to in JSON.
MinSerializedSize int64
// contains filtered or unexported fields
}
DeclType represents the universal type descriptor for OpenAPIv3 types.
func NewListType ¶
func NewListType(elem *DeclType, maxItems int64) *DeclType
NewListType returns a parameterized list type with a specified element type.
func NewMapType ¶
func NewMapType(key, elem *DeclType, maxProperties int64) *DeclType
NewMapType returns a parameterized map type with the given key and element types.
func NewObjectType ¶
func NewObjectType(name string, fields map[string]*DeclField) *DeclType
NewObjectType creates an object type with a qualified name and a set of field declarations.
func NewSimpleTypeWithMinSize ¶
func NewSimpleTypeWithMinSize(name string, celType *cel.Type, zeroVal ref.Val, minSize int64) *DeclType
func (*DeclType) CelType ¶
func (t *DeclType) CelType() *cel.Type
CelType returns the CEL type of this declaration.
func (*DeclType) DefaultValue ¶
func (t *DeclType) DefaultValue() ref.Val
DefaultValue returns the CEL ref.Val representing the default value for this object type, if one exists.
func (*DeclType) ExprType ¶
func (t *DeclType) ExprType() (*exprpb.Type, error)
ExprType returns the CEL expression type of this declaration.
func (*DeclType) FindField ¶
func (t *DeclType) FindField(name string) (*DeclField, bool)
FindField returns the DeclField with the given name if present.
func (*DeclType) HasTrait ¶
func (t *DeclType) HasTrait(trait int) bool
HasTrait implements the CEL ref.Type interface making this type declaration suitable for use within the CEL evaluator.
func (*DeclType) IsList ¶
func (t *DeclType) IsList() bool
IsList returns whether the declaration is a `list` type which defines a parameterized element type, but not a parameterized key type or fields.
func (*DeclType) IsMap ¶
func (t *DeclType) IsMap() bool
IsMap returns whether the declaration is a 'map' type which defines parameterized key and element types, but not fields.
func (*DeclType) IsObject ¶
func (t *DeclType) IsObject() bool
IsObject returns whether the declartion is an 'object' type which defined a set of typed fields.
func (*DeclType) MaybeAssignTypeName ¶
func (t *DeclType) MaybeAssignTypeName(name string) *DeclType
MaybeAssignTypeName attempts to set the DeclType name to a fully qualified name, if the type is of `object` type.
The DeclType must return true for `IsObject` or this assignment will error.
type DeclTypeProvider ¶ added in v0.28.0
type DeclTypeProvider struct {
// contains filtered or unexported fields
}
DeclTypeProvider extends the CEL ref.TypeProvider interface and provides an Open API Schema-based type-system.
func NewDeclTypeProvider ¶ added in v0.28.0
func NewDeclTypeProvider(rootTypes ...*DeclType) *DeclTypeProvider
NewDeclTypeProvider returns an Open API Schema-based type-system which is CEL compatible.
func (*DeclTypeProvider) EnumValue ¶ added in v0.28.0
func (rt *DeclTypeProvider) EnumValue(enumName string) ref.Val
func (*DeclTypeProvider) EnvOptions ¶ added in v0.28.0
func (rt *DeclTypeProvider) EnvOptions(tp types.Provider) ([]cel.EnvOption, error)
EnvOptions returns a set of cel.EnvOption values which includes the declaration set as well as a custom ref.TypeProvider.
If the DeclTypeProvider value is nil, an empty []cel.EnvOption set is returned.
func (*DeclTypeProvider) FindDeclType ¶ added in v0.28.0
func (rt *DeclTypeProvider) FindDeclType(typeName string) (*DeclType, bool)
FindDeclType returns the CPT type description which can be mapped to a CEL type.
func (*DeclTypeProvider) FindIdent ¶ added in v0.28.0
func (rt *DeclTypeProvider) FindIdent(identName string) (ref.Val, bool)
func (*DeclTypeProvider) FindStructFieldNames ¶ added in v0.31.0
func (rt *DeclTypeProvider) FindStructFieldNames(typeName string) ([]string, bool)
FindStructFieldNames returns the field names associated with the type, if the type is found.
func (*DeclTypeProvider) FindStructFieldType ¶ added in v0.31.0
func (rt *DeclTypeProvider) FindStructFieldType(typeName, fieldName string) (*types.FieldType, bool)
FindStructFieldType returns a field type given a type name and field name, if found.
Note, the type name for an Open API Schema type is likely to be its qualified object path. If, in the future an object instance rather than a type name were provided, the field resolution might more accurately reflect the expected type model. However, in this case concessions were made to align with the existing CEL interfaces.
func (*DeclTypeProvider) FindStructType ¶ added in v0.31.0
func (rt *DeclTypeProvider) FindStructType(typeName string) (*types.Type, bool)
FindStructType attempts to resolve the typeName provided from the rule's rule-schema, or if not from the embedded ref.TypeProvider.
FindStructType overrides the default type-finding behavior of the embedded TypeProvider.
Note, when the type name is based on the Open API Schema, the name will reflect the object path where the type definition appears.
func (*DeclTypeProvider) NativeToValue ¶ added in v0.28.0
func (rt *DeclTypeProvider) NativeToValue(val interface{}) ref.Val
NativeToValue is an implementation of the ref.TypeAdapater interface which supports conversion of rule values to CEL ref.Val instances.
func (*DeclTypeProvider) NewValue ¶ added in v0.28.0
func (rt *DeclTypeProvider) NewValue(typeName string, fields map[string]ref.Val) ref.Val
func (*DeclTypeProvider) SetRecognizeKeywordAsFieldName ¶ added in v0.31.0
func (rt *DeclTypeProvider) SetRecognizeKeywordAsFieldName(recognize bool)
func (*DeclTypeProvider) TypeNames ¶ added in v0.28.0
func (rt *DeclTypeProvider) TypeNames() []string
TypeNames returns the list of type names declared within the DeclTypeProvider object.
func (*DeclTypeProvider) WithTypeProvider ¶ added in v0.28.0
func (rt *DeclTypeProvider) WithTypeProvider(tp types.Provider) (*DeclTypeProvider, error)
WithTypeProvider returns a new DeclTypeProvider that sets the given TypeProvider If the original DeclTypeProvider is nil, the returned DeclTypeProvider is still nil.
type DynValue ¶
type DynValue struct {
ID int64
EncodeStyle EncodeStyle
// contains filtered or unexported fields
}
DynValue is a dynamically typed value used to describe unstructured content. Whether the value has the desired type is determined by where it is used within the Instance or Template, and whether there are schemas which might enforce a more rigid type definition.
func NewDynValue ¶
func NewDynValue(id int64, val interface{}) (*DynValue, error)
NewDynValue returns a DynValue that corresponds to a parse node id and value.
func NewEmptyDynValue ¶
func NewEmptyDynValue() *DynValue
NewEmptyDynValue returns the zero-valued DynValue.
func (*DynValue) ConvertToNative ¶
func (dv *DynValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
ConvertToNative is an implementation of the CEL ref.Val method used to adapt between CEL types and Go-native types.
The default behavior of this method is to first convert to a CEL type which has a well-defined set of conversion behaviors and proxy to the CEL ConvertToNative method for the type.
func (*DynValue) DeclType ¶
func (dv *DynValue) DeclType() *DeclType
DeclType returns the policy model type of the dyn value.
func (*DynValue) Equal ¶
func (dv *DynValue) Equal(other ref.Val) ref.Val
Equal returns whether the dyn value is equal to a given CEL value.
func (*DynValue) ExprValue ¶
func (dv *DynValue) ExprValue() ref.Val
ExprValue converts the DynValue into a CEL value.
func (*DynValue) SetValue ¶
func (dv *DynValue) SetValue(value interface{}) error
SetValue updates the underlying value held by this reference.
type EncodeStyle ¶
type EncodeStyle int
EncodeStyle is a hint for string encoding of parsed values.
const (
// BlockValueStyle is the default string encoding which preserves whitespace and newlines.
BlockValueStyle EncodeStyle = iota
// FlowValueStyle indicates that the string is an inline representation of complex types.
FlowValueStyle
// FoldedValueStyle is a multiline string with whitespace and newlines trimmed to a single
// a whitespace. Repeated newlines are replaced with a single newline rather than a single
// whitespace.
FoldedValueStyle
// LiteralStyle is a multiline string that preserves newlines, but trims all other whitespace
// to a single character.
LiteralStyle
)
type Error ¶
type Error struct {
Type ErrorType
Detail string
// Cause is an optional wrapped errors that can be useful to
// programmatically retrieve detailed errors.
Cause error
}
Error is an implementation of the 'error' interface, which represents a XValidation error.
type ErrorType ¶
type ErrorType string
ErrorType is a machine-readable value providing more detail about why a XValidation is invalid.
const (
// ErrorTypeRequired is used to report withNullable values that are not
// provided (e.g. empty strings, null values, or empty arrays). See
// Required().
ErrorTypeRequired ErrorType = "RuleRequired"
// ErrorTypeInvalid is used to report malformed values
ErrorTypeInvalid ErrorType = "RuleInvalid"
// ErrorTypeInternal is used to report other errors that are not related
// to user input. See InternalError().
ErrorTypeInternal ErrorType = "InternalError"
)
type Field ¶
type Field struct {
ID int64
Name string
Ref *DynValue
}
Field specifies a field name and a reference to a dynamic value.
type Format ¶ added in v0.31.0
type Format struct {
Name string
ValidateFunc func(string) []string
// Size of the regex string or estimated equivalent regex string used
// for cost estimation
MaxRegexSize int
}
Format provdes a CEL representation of kubernetes format
func (*Format) ConvertToNative ¶ added in v0.31.0
func (d *Format) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
func (*Format) ConvertToType ¶ added in v0.31.0
func (d *Format) ConvertToType(typeVal ref.Type) ref.Val
type IP ¶ added in v0.30.0
type IP struct {
netip.Addr
}
IP provides a CEL representation of an IP address.
func (IP) ConvertToNative ¶ added in v0.30.0
func (d IP) ConvertToNative(typeDesc reflect.Type) (any, error)
ConvertToNative implements ref.Val.ConvertToNative.
func (IP) ConvertToType ¶ added in v0.30.0
func (d IP) ConvertToType(typeVal ref.Type) ref.Val
ConvertToType implements ref.Val.ConvertToType.
func (IP) Equal ¶ added in v0.30.0
func (d IP) Equal(other ref.Val) ref.Val
Equal implements ref.Val.Equal.
type ListValue ¶
type ListValue struct {
Entries []*DynValue
// contains filtered or unexported fields
}
ListValue contains a list of dynamically typed entries.
func NewListValue ¶
func NewListValue() *ListValue
NewListValue returns an empty ListValue instance.
func (*ListValue) Add ¶
func (lv *ListValue) Add(other ref.Val) ref.Val
Add concatenates two lists together to produce a new CEL list value.
func (*ListValue) Append ¶
func (lv *ListValue) Append(entry *DynValue)
Append adds another entry into the ListValue.
func (*ListValue) Contains ¶
func (lv *ListValue) Contains(val ref.Val) ref.Val
Contains returns whether the input `val` is equal to an element in the list.
If any pair-wise comparison between the input value and the list element is an error, the operation will return an error.
func (*ListValue) ConvertToNative ¶
func (lv *ListValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
ConvertToNative is an implementation of the CEL ref.Val method used to adapt between CEL types and Go-native array-like types.
func (*ListValue) ConvertToType ¶
func (lv *ListValue) ConvertToType(t ref.Type) ref.Val
ConvertToType converts the ListValue to another CEL type.
func (*ListValue) Equal ¶
func (lv *ListValue) Equal(other ref.Val) ref.Val
Equal returns true if two lists are of the same size, and the values at each index are also equal.
func (*ListValue) Get ¶
func (lv *ListValue) Get(idx ref.Val) ref.Val
Get returns the value at the given index.
If the index is negative or greater than the size of the list, an error is returned.
func (*ListValue) Iterator ¶
func (lv *ListValue) Iterator() traits.Iterator
Iterator produces a traits.Iterator suitable for use in CEL comprehension macros.
func (*ListValue) Size ¶
func (lv *ListValue) Size() ref.Val
Size returns the number of elements in the list.
type MapValue ¶
type MapValue struct {
// contains filtered or unexported fields
}
MapValue declares an object with a set of named fields whose values are dynamically typed.
func (MapValue) AddField ¶
func (sv MapValue) AddField(field *Field)
AddField appends a MapField to the MapValue and indexes the field by name.
func (*MapValue) Contains ¶
func (m *MapValue) Contains(key ref.Val) ref.Val
Contains returns whether the given key is contained in the MapValue.
func (MapValue) ConvertToNative ¶
func (sv MapValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
ConvertToNative converts the MapValue type to a native go types.
func (*MapValue) ConvertToObject ¶
func (m *MapValue) ConvertToObject(declType *DeclType) *ObjectValue
ConvertToObject produces an ObjectValue from the MapValue with the associated schema type.
The conversion is shallow and the memory shared between the Object and Map as all references to the map are expected to be replaced with the Object reference.
func (*MapValue) ConvertToType ¶
func (m *MapValue) ConvertToType(t ref.Type) ref.Val
ConvertToType converts the MapValue to another CEL type, if possible.
func (*MapValue) Equal ¶
func (m *MapValue) Equal(other ref.Val) ref.Val
Equal returns true if the maps are of the same size, have the same keys, and the key-values from each map are equal.
func (*MapValue) Find ¶
func (m *MapValue) Find(name ref.Val) (ref.Val, bool)
Find returns the value for the key in the map, if found.
func (*MapValue) Get ¶
func (m *MapValue) Get(key ref.Val) ref.Val
Get returns the value for the key in the map, or error if not found.
func (MapValue) GetField ¶
func (sv MapValue) GetField(name string) (*Field, bool)
GetField returns a MapField by name if one exists.
func (MapValue) IsSet ¶
func (sv MapValue) IsSet(key ref.Val) ref.Val
IsSet returns whether the given field, which is defined, has also been set.
func (*MapValue) Iterator ¶
func (m *MapValue) Iterator() traits.Iterator
Iterator produces a traits.Iterator which walks over the map keys.
The Iterator is frequently used within comprehensions.
func (*MapValue) Size ¶
func (m *MapValue) Size() ref.Val
Size returns the number of keys in the map.
type MultilineStringValue ¶
type MultilineStringValue struct {
Value string
Raw string
}
MultilineStringValue is a multiline string value which has been parsed in a way which omits whitespace as well as a raw form which preserves whitespace.
type ObjectValue ¶
type ObjectValue struct {
// contains filtered or unexported fields
}
ObjectValue is a struct with a custom schema type which indicates the fields and types associated with the structure.
func NewObjectValue ¶
func NewObjectValue(sType *DeclType) *ObjectValue
NewObjectValue creates a struct value with a schema type and returns the empty ObjectValue.
func (ObjectValue) AddField ¶
func (sv ObjectValue) AddField(field *Field)
AddField appends a MapField to the MapValue and indexes the field by name.
func (ObjectValue) ConvertToNative ¶
func (sv ObjectValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
ConvertToNative converts the MapValue type to a native go types.
func (*ObjectValue) ConvertToType ¶
func (o *ObjectValue) ConvertToType(t ref.Type) ref.Val
ConvertToType is an implementation of the CEL ref.Val interface method.
func (*ObjectValue) Equal ¶
func (o *ObjectValue) Equal(other ref.Val) ref.Val
Equal returns true if the two object types are equal and their field values are equal.
func (*ObjectValue) Get ¶
func (o *ObjectValue) Get(name ref.Val) ref.Val
Get returns the value of the specified field.
If the field is set, its value is returned. If the field is not set, the default value for the field is returned thus allowing for safe-traversal and preserving proto-like field traversal semantics for Open API Schema backed types.
func (ObjectValue) GetField ¶
func (sv ObjectValue) GetField(name string) (*Field, bool)
GetField returns a MapField by name if one exists.
func (ObjectValue) IsSet ¶
func (sv ObjectValue) IsSet(key ref.Val) ref.Val
IsSet returns whether the given field, which is defined, has also been set.
type PlainTextValue ¶
type PlainTextValue string
PlainTextValue is a text string literal which must not be treated as an expression.
type Quantity ¶ added in v0.28.0
type Quantity struct {
*resource.Quantity
}
Quantity provdes a CEL representation of a resource.Quantity
func (Quantity) ConvertToNative ¶ added in v0.28.0
func (d Quantity) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
func (Quantity) ConvertToType ¶ added in v0.28.0
func (d Quantity) ConvertToType(typeVal ref.Type) ref.Val
type URL ¶
type URL struct {
*url.URL
}
URL provides a CEL representation of a URL.
func (URL) ConvertToNative ¶
func (d URL) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
ConvertToNative implements ref.Val.ConvertToNative.
func (URL) ConvertToType ¶
func (d URL) ConvertToType(typeVal ref.Type) ref.Val
ConvertToType implements ref.Val.ConvertToType.