Documentation
¶
Index ¶
- Variables
- func FieldTypeMap(path string, t *DeclType) map[string]*DeclType
- type Comment
- type CommentStyle
- type DeclField
- type DeclType
- func NewListType(elem *DeclType) *DeclType
- func NewMapType(key, elem *DeclType) *DeclType
- func NewObjectType(name string, fields map[string]*DeclField) *DeclType
- func NewObjectTypeRef(name string) *DeclType
- func NewTypeParam(name string) *DeclType
- func SchemaDeclType(s *spec.Schema) *DeclType
- func SchemaDeclTypes(s *spec.Schema, maybeRootType string) (*DeclType, map[string]*DeclType)
- func (t *DeclType) DefaultValue() ref.Val
- func (t *DeclType) ExprType() *exprpb.Type
- 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 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 Env
- type Field
- type Function
- 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 Overload
- type ParsedValue
- type PlainTextValue
- type Registry
- func (r *Registry) FindEnv(name string) (*Env, bool)
- func (r *Registry) FindExprEnv(name string) (*cel.Env, bool)
- func (r *Registry) FindSchema(name string) (*spec.Schema, bool)
- func (r *Registry) FindType(name string) (*DeclType, bool)
- func (r *Registry) SetEnv(name string, env *Env) error
- func (r *Registry) SetSchema(name string, schema *spec.Schema) error
- func (r *Registry) SetType(name string, declType *DeclType) error
- type RelativeSource
- type Resolver
- type RuleTypes
- func (rt *RuleTypes) EnvOptions(tp ref.TypeProvider) ([]cel.EnvOption, error)
- func (rt *RuleTypes) FindDeclType(typeName string) (*DeclType, bool)
- func (rt *RuleTypes) FindFieldType(typeName, fieldName string) (*ref.FieldType, bool)
- func (rt *RuleTypes) FindType(typeName string) (*exprpb.Type, bool)
- func (rt *RuleTypes) NativeToValue(val interface{}) ref.Val
- func (rt *RuleTypes) TypeNames() []string
- type Source
- type SourceInfo
- type SourceMetadata
- type Var
Constants ¶
This section is empty.
Variables ¶
var ( // AnyType is equivalent to the CEL 'protobuf.Any' type in that the value may have any of the // types supported by CEL Policy Templates. AnyType = newSimpleType("any", decls.Any, nil) // BoolType is equivalent to the CEL 'bool' type. BoolType = newSimpleType("bool", decls.Bool, types.False) // BytesType is equivalent to the CEL 'bytes' type. BytesType = newSimpleType("bytes", decls.Bytes, types.Bytes([]byte{})) // DoubleType is equivalent to the CEL 'double' type which is a 64-bit floating point value. DoubleType = newSimpleType("double", decls.Double, types.Double(0)) // DurationType is equivalent to the CEL 'duration' type. DurationType = newSimpleType("duration", decls.Duration, types.Duration{Duration: time.Duration(0)}) // DynType is the equivalent of the CEL 'dyn' concept which indicates that the type will be // determined at runtime rather than compile time. DynType = newSimpleType("dyn", decls.Dyn, nil) // IntType is equivalent to the CEL 'int' type which is a 64-bit signed int. IntType = newSimpleType("int", decls.Int, types.IntZero) // NullType is equivalent to the CEL 'null_type'. NullType = newSimpleType("null_type", decls.Null, types.NullValue) // 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 = newSimpleType("string", decls.String, types.String("")) // PlainTextType is equivalent to the CEL 'string' type, but which has been specifically // designated as a string literal. PlainTextType = newSimpleType("string_lit", decls.String, types.String("")) // TimestampType corresponds to the well-known protobuf.Timestamp type supported within CEL. TimestampType = newSimpleType("timestamp", decls.Timestamp, types.Timestamp{Time: time.Time{}}) // UintType is equivalent to the CEL 'uint' type. UintType = newSimpleType("uint", decls.Uint, types.Uint(0)) // ListType is equivalent to the CEL 'list' type. ListType = NewListType(AnyType) // MapType is equivalent to the CEL 'map' type. MapType = NewMapType(AnyType, AnyType) )
var ( // AnySchema indicates that the value may be of any type. AnySchema *spec.Schema )
Functions ¶
Types ¶
type Comment ¶
type Comment struct { // Text contains the comment text. Text string // Style indicates where the comment appears relative to a source element. Style CommentStyle }
Comment represents a comment within source.
func NewFootComment ¶
NewFootComment creates a new FootComment from the text.
func NewHeadComment ¶
NewHeadComment creates a new HeadComment from the text.
func NewLineComment ¶
NewLineComment creates a new LineComment from the text.
type CommentStyle ¶
type CommentStyle int
CommentStyle type used to indicate where a comment occurs.
const ( // HeadComment indicates that the comment is defined in the lines preceding the source element. HeadComment CommentStyle = iota + 1 // LineComment indicates that the comment occurs on the same line after the source element. LineComment // FootComment indicates that the comment occurs after the source element with at least one // blank line before the next source element. FootComment )
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 (*DeclField) DefaultValue ¶
DefaultValue returns the zero value associated with the field.
func (*DeclField) EnumValues ¶
EnumValues returns the set of values that this field may take.
type DeclType ¶
type DeclType struct { fmt.Stringer Fields map[string]*DeclField KeyType *DeclType ElemType *DeclType TypeParam bool Metadata map[string]string // contains filtered or unexported fields }
DeclType represents the universal type descriptor for Policy Templates.
func NewListType ¶
NewListType returns a parameterized list type with a specified element type.
func NewMapType ¶
NewMapType returns a parameterized map type with the given key and element types.
func NewObjectType ¶
NewObjectType creates an object type with a qualified name and a set of field declarations.
func NewObjectTypeRef ¶
NewObjectTypeRef returns a reference to an object type by name
func NewTypeParam ¶
NewTypeParam creates a type parameter type with a simple name.
Type parameters are resolved at compilation time to concrete types, or CEL 'dyn' type if no type assignment can be inferred.
func SchemaDeclType ¶
SchemaDeclType returns the CEL Policy Templates type name associated with the schema element.
func SchemaDeclTypes ¶
SchemaDeclTypes constructs a top-down set of DeclType instances whose name is derived from the root type name provided on the call, if not set to a custom type.
func (*DeclType) DefaultValue ¶
DefaultValue returns the CEL ref.Val representing the default value for this object type, if one exists.
func (*DeclType) HasTrait ¶
HasTrait implements the CEL ref.Type interface making this type declaration suitable for use within the CEL evaluator.
func (*DeclType) IsList ¶
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 ¶
IsMap returns whether the declaration is a 'map' type which defines parameterized key and element types, but not fields.
func (*DeclType) IsObject ¶
IsObject returns whether the declartion is an 'object' type which defined a set of typed fields.
func (*DeclType) MaybeAssignTypeName ¶
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 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 ¶
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 ¶
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.
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 Env ¶
type Env struct { Name string Container string Functions []*Function Vars []*Var Types map[string]*DeclType }
Env declares a set of variables, functions, and types available to a given set of CEL expressions.
The Env name must be fully qualified as it will be referenced within template evaluators, validators, and possibly within the metadata of the instance rule schema.
Note, the Types values currently only holds type definitions associated with a variable declaration. Any type mentioned in the environment which does not have a definition is treated as a reference to a type which must be supplied in the base CEL environment provided by the policy engine.
func NewEnv ¶
NewEnv creates an empty Env instance with a fully qualified name that may be referenced within templates.
func (*Env) ExprEnvOptions ¶
ExprEnvOptions returns a set of CEL environment options to be used when extending the base policy engine CEL environment.
type Function ¶
Function represents a simple name and a set of overload signatures.
func NewFunction ¶
NewFunction creates a Function instance with a simple function name and a set of overload signatures.
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) Contains ¶
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 ¶
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 ¶
ConvertToType converts the ListValue to another CEL type.
func (*ListValue) Equal ¶
Equal returns true if two lists are of the same size, and the values at each index are also equal.
func (*ListValue) Get ¶
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 ¶
Iterator produces a traits.Iterator suitable for use in CEL comprehension macros.
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) ConvertToNative ¶
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 ¶
ConvertToType converts the MapValue to another CEL type, if possible.
func (*MapValue) Equal ¶
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) Iterator ¶
Iterator produces a traits.Iterator which walks over the map keys.
The Iterator is frequently used within comprehensions.
type MultilineStringValue ¶
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 ¶
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) IsSet ¶
IsSet returns whether the given field, which is defined, has also been set.
func (*ObjectValue) Type ¶
func (o *ObjectValue) Type() ref.Type
Type returns the CEL type value of the object.
func (*ObjectValue) Value ¶
func (o *ObjectValue) Value() interface{}
Value returns the Go-native representation of the object.
type Overload ¶
Overload represents a single function overload signature.
func NewFreeFunctionOverload ¶
NewFreeFunctionOverload returns a free function overload for a given function name.
The overload name must follow the conventions laid out within the CEL overloads.go file:
// Free function style overload name: <func>_<arg_type0>_<arg_typeN>
When the function name is global, <func> will refer to the simple function name. When the function has a qualified name, replace the '.' characters in the fully-qualified name with underscores.
Within this function, the last type supplied is used as the return type. At least one type must be specified for a zero-arity free function.
func NewOverload ¶
NewOverload returns a receiver-style overload declaration for a given function.
The overload name must follow the conventions laid out within the CEL overloads.go file.
// Receiver-style overload name: <receiver_type>_<func>_<arg_type0>_<arg_typeN>
Within this function, the first type supplied is the receiver type, and the last type supplied is used as the return type. At least two types must be specified for a zero-arity receiver function.
type ParsedValue ¶
type ParsedValue struct { ID int64 Value *MapValue Meta SourceMetadata }
ParsedValue represents a top-level object representing either a template or instance value.
type PlainTextValue ¶
type PlainTextValue string
PlainTextValue is a text string literal which must not be treated as an expression.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry defines a repository of environment, schema, template, and type definitions.
Registry instances are concurrency-safe.
func NewRegistry ¶
NewRegistry create a registry for keeping track of environments, schemas, templates, and more from a base cel.Env expression environment.
func (*Registry) FindExprEnv ¶
FindExprEnv implements the Resolver interface method.
func (*Registry) FindSchema ¶
FindSchema implements the Resolver interface method.
type RelativeSource ¶
RelativeSource represents an embedded source element within a larger source.
func (*RelativeSource) AbsoluteLocation ¶
func (rel *RelativeSource) AbsoluteLocation() common.Location
AbsoluteLocation returns the location within the parent Source where the RelativeSource starts.
func (*RelativeSource) Content ¶
func (rel *RelativeSource) Content() string
Content returns the embedded source snippet.
func (*RelativeSource) NewLocation ¶
func (rel *RelativeSource) NewLocation(line, col int) common.Location
NewLocation creates an absolute common.Location based on a local line, column position from a relative source.
func (*RelativeSource) OffsetLocation ¶
func (rel *RelativeSource) OffsetLocation(offset int32) (common.Location, bool)
OffsetLocation returns the absolute location given the relative offset, if found.
type Resolver ¶
type Resolver interface { // FindEnv returns an Env object by its fully-qualified name, if present. FindEnv(name string) (*Env, bool) // FindExprEnv returns a CEL expression environment by its fully-qualified name, if present. // // Note, the CEL expression environment name corresponds with the model Environment name; // however, the expression environment may inherit configuration via the CEL env.Extend method. FindExprEnv(name string) (*cel.Env, bool) // FindSchema returns an Open API Schema instance by name, if present. // // Schema names start with a `#` sign as this method is only used to resolve references to // relative schema elements within `$ref` schema nodes. FindSchema(name string) (*spec.Schema, bool) // FindType returns a DeclType instance corresponding to the given fully-qualified name, if // present. FindType(name string) (*DeclType, bool) }
Resolver declares methods to find policy templates and related configuration objects.
type RuleTypes ¶
type RuleTypes struct { ref.TypeProvider Schema *spec.Schema // contains filtered or unexported fields }
RuleTypes extends the CEL ref.TypeProvider interface and provides an Open API Schema-based type-system.
func NewRuleTypes ¶
NewRuleTypes returns an Open API Schema-based type-system which is CEL compatible.
func (*RuleTypes) EnvOptions ¶
EnvOptions returns a set of cel.EnvOption values which includes the Template's declaration set as well as a custom ref.TypeProvider.
Note, the standard declaration set includes 'rule' which is defined as the top-level rule-schema type if one is configured.
If the RuleTypes value is nil, an empty []cel.EnvOption set is returned.
func (*RuleTypes) FindDeclType ¶
FindDeclType returns the CPT type description which can be mapped to a CEL type.
func (*RuleTypes) FindFieldType ¶
FindFieldType 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 (*RuleTypes) FindType ¶
FindType attempts to resolve the typeName provided from the template's rule-schema, or if not from the embedded ref.TypeProvider.
FindType 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 (*RuleTypes) NativeToValue ¶
NativeToValue is an implementation of the ref.TypeAdapater interface which supports conversion of policy template values to CEL ref.Val instances.
type Source ¶
Source represents the contents of a single source file.
func ByteSource ¶
ByteSource converts a byte sequence and location description to a model.Source.
func StringSource ¶
StringSource converts a string and location description to a model.Source.
type SourceInfo ¶
type SourceInfo struct { // Comments mapped by source element id to a comment set. Comments map[int64][]*Comment // LineOffsets contains the list of character offsets where newlines occur in the source. LineOffsets []int32 // Description indicates something about the source, such as its file name. Description string // Offsets map from source element id to the character offset where the source element starts. Offsets map[int64]int32 }
SourceInfo contains metadata about the Source such as comments, line positions, and source element offsets.
func NewSourceInfo ¶
func NewSourceInfo(src common.Source) *SourceInfo
NewSourceInfo creates SourceInfo metadata from a Source object.
func (*SourceInfo) CommentsByID ¶
func (info *SourceInfo) CommentsByID(id int64) ([]*Comment, bool)
CommentsByID returns the set of comments by expression id, if present.
func (*SourceInfo) LocationByID ¶
func (info *SourceInfo) LocationByID(id int64) (common.Location, bool)
LocationByID returns the line and column location of source node by its id.
type SourceMetadata ¶
type SourceMetadata interface { // CommentsByID returns the set of comments associated with the expression id, if present. CommentsByID(int64) ([]*Comment, bool) // LocationByID returns the CEL common.Location of the expression id, if present. LocationByID(int64) (common.Location, bool) }
SourceMetadata enables the lookup for expression source metadata by expression id.