Documentation ¶
Overview ¶
Package model contains abstract representations of policy template and instance config objects.
Index ¶
- Variables
- func FieldTypeMap(path string, t *DeclType) map[string]*DeclType
- type BoolDecisionValue
- func (dv *BoolDecisionValue) And(other ref.Val) *BoolDecisionValue
- func (dv *BoolDecisionValue) Details() *cel.EvalDetails
- func (dv *BoolDecisionValue) Finalize(details *cel.EvalDetails, rule Rule) DecisionValue
- func (dv *BoolDecisionValue) IsFinal() bool
- func (dv *BoolDecisionValue) Name() string
- func (dv *BoolDecisionValue) Or(other ref.Val) *BoolDecisionValue
- func (dv *BoolDecisionValue) RuleID() int64
- func (dv *BoolDecisionValue) String() string
- func (dv *BoolDecisionValue) Value() ref.Val
- type Comment
- type CommentStyle
- type CustomRule
- type Decision
- type DecisionSelector
- type DecisionValue
- type DeclField
- type 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 Evaluator
- type ExpressionSelector
- type Field
- type Function
- type Instance
- type InstanceMetadata
- type LabelSelector
- type ListDecisionValue
- func (dv *ListDecisionValue) Append(val ref.Val, det *cel.EvalDetails, rule Rule)
- func (dv *ListDecisionValue) Details() []*cel.EvalDetails
- func (dv *ListDecisionValue) Finalize() DecisionValue
- func (dv *ListDecisionValue) IsFinal() bool
- func (dv *ListDecisionValue) Name() string
- func (dv *ListDecisionValue) RuleIDs() []int64
- func (dv *ListDecisionValue) String() string
- func (dv *ListDecisionValue) Values() []ref.Val
- 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 MultiDecisionValue
- 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 OpenAPISchema
- type Overload
- type ParsedValue
- type PlainTextValue
- type Production
- type Range
- 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) (*OpenAPISchema, bool)
- func (r *Registry) FindTemplate(name string) (*Template, 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 *OpenAPISchema) error
- func (r *Registry) SetTemplate(name string, tmpl *Template) error
- func (r *Registry) SetType(name string, declType *DeclType) error
- type RelativeSource
- type Resolver
- type Rule
- type RuleTypes
- func (rt *RuleTypes) ConvertToRule(dyn *DynValue) Rule
- 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 Selector
- type SingleDecisionValue
- type Source
- type SourceInfo
- type SourceMetadata
- type Template
- type TemplateMetadata
- type Term
- 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) )
Functions ¶
Types ¶
type BoolDecisionValue ¶
type BoolDecisionValue struct {
// contains filtered or unexported fields
}
BoolDecisionValue represents the decision value type associated with a decision.
func NewBoolDecisionValue ¶
func NewBoolDecisionValue(name string, value types.Bool) *BoolDecisionValue
NewBoolDecisionValue returns a boolean decision with an initial value.
func (*BoolDecisionValue) And ¶
func (dv *BoolDecisionValue) And(other ref.Val) *BoolDecisionValue
And logically ANDs the current decision value with the incoming CEL value.
And follows CEL semantics with respect to errors and unknown values where errors may be absorbed or short-circuited away by subsequent 'false' values. When unkonwns are encountered the unknown values combine and aggregate within the decision. Unknowns may also be absorbed per CEL semantics.
func (*BoolDecisionValue) Details ¶
func (dv *BoolDecisionValue) Details() *cel.EvalDetails
Details implements the SingleDecisionValue interface method.
func (*BoolDecisionValue) Finalize ¶
func (dv *BoolDecisionValue) Finalize(details *cel.EvalDetails, rule Rule) DecisionValue
Finalize marks the decision as immutable with additional input and indicates the rule and evaluation details which triggered the finalization.
func (*BoolDecisionValue) IsFinal ¶
func (dv *BoolDecisionValue) IsFinal() bool
IsFinal returns whether the decision is final.
func (*BoolDecisionValue) Name ¶
func (dv *BoolDecisionValue) Name() string
Name implements the DecisionValue interface method.
func (*BoolDecisionValue) Or ¶
func (dv *BoolDecisionValue) Or(other ref.Val) *BoolDecisionValue
Or logically ORs the decision value with the incoming CEL value.
The ORing logic follows CEL semantics with respect to errors and unknown values. Errors may be absorbed or short-circuited away by subsequent 'true' values. When unkonwns are encountered the unknown values combine and aggregate within the decision. Unknowns may also be absorbed per CEL semantics.
func (*BoolDecisionValue) RuleID ¶
func (dv *BoolDecisionValue) RuleID() int64
RuleID implements the SingleDecisionValue interface method.
func (*BoolDecisionValue) String ¶
func (dv *BoolDecisionValue) String() string
String renders the decision value to a string for debug purposes.
func (*BoolDecisionValue) Value ¶
func (dv *BoolDecisionValue) Value() ref.Val
Value implements the SingleDecisionValue interface method.
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 CustomRule ¶
type CustomRule struct {
*DynValue
}
CustomRule embeds the DynValue and represents rules whose type definition is provided in the policy template.
func (*CustomRule) GetFieldID ¶
func (c *CustomRule) GetFieldID(field string) int64
GetFieldID returns the parse-time generated ID pointing to the rule field. If field is not specified or is not found, falls back to the ID of the rule node.
func (*CustomRule) GetID ¶
func (c *CustomRule) GetID() int64
GetID returns the parse-time generated ID of the rule node.
type Decision ¶
Decision contains a decision name, or reference to a decision name, and an output expression.
type DecisionSelector ¶
DecisionSelector determines whether the given decision is the decision set requested by the caller.
type DecisionValue ¶
type DecisionValue interface { fmt.Stringer // Name returns the decision name. Name() string // IsFinal returns whether the decision value will change with additional rule evaluations. // // When a decision is final, additional productions and rules which may also trigger the same // decision may be skipped. IsFinal() bool }
DecisionValue represents a named decision and value.
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 (*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.
func (*DynValue) SetValue ¶ added in v0.1.1
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 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 Evaluator ¶
type Evaluator struct { Environment string Ranges []*Range Terms []*Term Productions []*Production }
Evaluator contains a set of production rules used to validate policy templates or evaluate template instances.
The evaluator may optionally specify a named and versioned Environment as the basis for the variables and functions exposed to the CEL expressions within the Evaluator, and an optional set of terms.
Terms are like template-local variables. Terms may rely on other terms which precede them. Term order matters, and no cycles are permitted among terms by design and convention.
func NewEvaluator ¶
func NewEvaluator() *Evaluator
NewEvaluator returns an empty instance of a Template Evaluator.
func (*Evaluator) DecisionCount ¶
DecisionCount returns the number of possible decisions which could be emitted by this evaluator.
type ExpressionSelector ¶
type ExpressionSelector struct { // Label name being matched. Label string // Operator determines the evaluation behavior. Must be one of Exists, NotExists, In, or NotIn. Operator string // Values set, optional, to be used in the NotIn, In set membership tests. Values []interface{} }
ExpressionSelector matches a label against an existence condition.
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 Instance ¶
type Instance struct { APIVersion string Kind string Metadata *InstanceMetadata Description string // Selectors determine whether the instance applies to the current evaluation context. // All Selector values must return true for the policy instance to be included in policy // evaluation step. Selectors []Selector // Rules represent reference data to be used in evaluation policy decisions. // Depending on the nature of the decisions being emitted, some or all Rules may be evaluated // and the results aggregated according to the decision types being emitted. Rules []Rule // Meta represents the source metadata from the input instance. Meta SourceMetadata }
Instance represents the compiled, type-checked, and validated policy instance.
func NewInstance ¶
func NewInstance(info SourceMetadata) *Instance
NewInstance returns an empty policy instance.
func (*Instance) MetadataMap ¶
MetadataMap returns the metadata name to value map, which can be used in evaluation. Only "name" field is supported for now.
type InstanceMetadata ¶
InstanceMetadata contains standard metadata which may be associated with an instance.
type LabelSelector ¶
type LabelSelector struct { // LabelValues provides a map of the string keys and values expected. LabelValues map[string]string }
LabelSelector matches key, value pairs of labels associated with the evaluation context.
In Kubernetes, the such labels are provided as 'resource.labels'.
type ListDecisionValue ¶
type ListDecisionValue struct {
// contains filtered or unexported fields
}
ListDecisionValue represents a named decision which collects into a list of values.
func NewListDecisionValue ¶
func NewListDecisionValue(name string) *ListDecisionValue
NewListDecisionValue returns a named decision value which contains a list of CEL values produced by one or more policy instances and / or production rules.
func (*ListDecisionValue) Append ¶
func (dv *ListDecisionValue) Append(val ref.Val, det *cel.EvalDetails, rule Rule)
Append accumulates the incoming CEL value into the decision's value list.
func (*ListDecisionValue) Details ¶
func (dv *ListDecisionValue) Details() []*cel.EvalDetails
Details returns the list of evaluation details observed in computing the values in the decision. The details indices correlate 1:1 with the value indices.
func (*ListDecisionValue) Finalize ¶
func (dv *ListDecisionValue) Finalize() DecisionValue
Finalize marks the list decision complete.
func (*ListDecisionValue) IsFinal ¶
func (dv *ListDecisionValue) IsFinal() bool
IsFinal implements the DecisionValue interface method.
func (*ListDecisionValue) Name ¶
func (dv *ListDecisionValue) Name() string
Name implements the DecisionValue interface method.
func (*ListDecisionValue) RuleIDs ¶
func (dv *ListDecisionValue) RuleIDs() []int64
RuleIDs returns the list of rule ids which produced the evaluation results. The indices of the ruleIDs correlate 1:1 with the value indices.
func (*ListDecisionValue) String ¶
func (dv *ListDecisionValue) String() string
func (*ListDecisionValue) Values ¶
func (dv *ListDecisionValue) Values() []ref.Val
Values implements the MultiDecisionValue interface method.
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 MultiDecisionValue ¶
type MultiDecisionValue interface { DecisionValue // Values returns the collection of values produced for the decision. Values() []ref.Val // Details returns the evaluation details for each value in the decision. // The value index correponds to the details index. The details may be nil. Details() []*cel.EvalDetails // RulesIDs returns the rule id within an instance which produce the decision values. // The value index corresponds to the rule id index. RuleIDs() []int64 }
MultiDecisionValue extends the DecisionValue which contains a set of decision values as well as the corresponding metadata about how each value was produced.
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 OpenAPISchema ¶
type OpenAPISchema struct { Title string `yaml:"title,omitempty"` Description string `yaml:"description,omitempty"` Type string `yaml:"type,omitempty"` TypeParam string `yaml:"type_param,omitempty"` TypeRef string `yaml:"$ref,omitempty"` DefaultValue interface{} `yaml:"default,omitempty"` Enum []interface{} `yaml:"enum,omitempty"` Format string `yaml:"format,omitempty"` Items *OpenAPISchema `yaml:"items,omitempty"` Metadata map[string]string `yaml:"metadata,omitempty"` Required []string `yaml:"required,omitempty"` Properties map[string]*OpenAPISchema `yaml:"properties,omitempty"` AdditionalProperties *OpenAPISchema `yaml:"additionalProperties,omitempty"` }
OpenAPISchema declares a struct capable of representing a subset of Open API Schemas supported by Kubernetes which can also be specified within Protocol Buffers.
There are a handful of notable differences:
- The validating constructs `allOf`, `anyOf`, `oneOf`, `not`, and type-related restrictsion are not supported as they can be better validated in the template 'validator' block.
- The $ref field supports references to other schema definitions, but such aliases should be removed before being serialized.
- The `additionalProperties` and `properties` fields are not currently mutually exclusive as is the case for Kubernetes.
var ( // AnySchema indicates that the value may be of any type. AnySchema *OpenAPISchema )
func NewOpenAPISchema ¶
func NewOpenAPISchema() *OpenAPISchema
NewOpenAPISchema returns an empty instance of an OpenAPISchema object.
func (*OpenAPISchema) DeclType ¶
func (s *OpenAPISchema) DeclType() *DeclType
DeclType returns the CEL Policy Templates type name associated with the schema element.
func (*OpenAPISchema) DeclTypes ¶
func (s *OpenAPISchema) DeclTypes(maybeRootType string) (*DeclType, map[string]*DeclType)
DeclTypes 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 (*OpenAPISchema) FindProperty ¶
func (s *OpenAPISchema) FindProperty(name string) (*OpenAPISchema, bool)
FindProperty returns the Open API Schema type for the given property name.
A property may either be explicitly defined in a `properties` map or implicitly defined in an `additionalProperties` block.
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 Production ¶
Production describes an match-decision pair where the match, if set, indicates whether the Decision is applicable, and the decision indicates its name and output value.
func NewProduction ¶
func NewProduction(id int64, match *cel.Ast) *Production
NewProduction returns an empty instance of a Production rule which minimally contains a single Decision.
type Range ¶
Range expresses a looping condition where the key (or index) and value can be extracted from the range CEL 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 ¶
func (r *Registry) FindSchema(name string) (*OpenAPISchema, bool)
FindSchema implements the Resolver interface method.
func (*Registry) FindTemplate ¶
FindTemplate implements the Resolver interface method.
func (*Registry) SetSchema ¶
func (r *Registry) SetSchema(name string, schema *OpenAPISchema) error
SetSchema registers an OpenAPISchema fragment by its relative name so that it may be referenced as a reusable schema unit within other OpenAPISchema instances.
Name format: '#<simpleName>'.
func (*Registry) SetTemplate ¶
SetTemplate registers a template by its fully qualified name.
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) (*OpenAPISchema, bool) // FindTemplate returns a Template by its fully-qualified name, if present. FindTemplate(name string) (*Template, 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 Rule ¶
type Rule interface { GetID() int64 GetFieldID(field string) int64 // contains filtered or unexported methods }
Rule interface indicates the value types that may be used as Rule instances.
Note, the code within the main repo deals exclusively with custom, yaml-based rules, but it is entirely possible to use a protobuf message as the rule container.
type RuleTypes ¶
type RuleTypes struct { ref.TypeProvider Schema *OpenAPISchema // contains filtered or unexported fields }
RuleTypes extends the CEL ref.TypeProvider interface and provides an Open API Schema-based type-system.
func NewRuleTypes ¶
func NewRuleTypes(kind string, schema *OpenAPISchema, res Resolver) (*RuleTypes, error)
NewRuleTypes returns an Open API Schema-based type-system which is CEL compatible.
func (*RuleTypes) ConvertToRule ¶
ConvertToRule transforms an untyped DynValue into a typed object.
Conversion is done deeply and will traverse the object graph represented by the dyn value.
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 Selector ¶
type Selector interface {
// contains filtered or unexported methods
}
Selector interface indicates a pre-formatted instance selection condition.
The implementations of such conditions are expected to be platform specific.
Note, if there is a clear need to tailor selection more heavily, then the schema definition for a selector should be moved into the Template schema.
type SingleDecisionValue ¶
type SingleDecisionValue interface { DecisionValue // Value returns the single value for the decision. Value() ref.Val // Details returns the evaluation details, if present, that produced the value. Details() *cel.EvalDetails // RuleID indicate which policy rule id within an instance that produced the decision. RuleID() int64 }
SingleDecisionValue extends the DecisionValue which contains a single decision value as well as some metadata about the evaluation details and the rule that spawned the value.
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.
type Template ¶
type Template struct { APIVersion string Kind string Metadata *TemplateMetadata Description string RuleTypes *RuleTypes Validator *Evaluator Evaluator *Evaluator Meta SourceMetadata }
Template represents the compiled and type-checked policy template.
func NewTemplate ¶
func NewTemplate(info SourceMetadata) *Template
NewTemplate produces an empty policy Template instance.
func (*Template) EvaluatorDecisionCount ¶
EvaluatorDecisionCount returns the number of decisions which can be produced by the template evaluator production rules.
func (*Template) MetadataMap ¶
MetadataMap returns the metadata name to value map, which can be used in evaluation. Only "name" field is supported for now.
type TemplateMetadata ¶
type TemplateMetadata struct { UID string Name string Namespace string // PluralMame is the plural form of the template name to use when managing a collection of // template instances. PluralName string // Properties contains an optional set of key-value information which external applications // might find useful. Properties map[string]string }
TemplateMetadata contains the top-level information about the Template, including its name and namespace.
func NewTemplateMetadata ¶
func NewTemplateMetadata() *TemplateMetadata
NewTemplateMetadata returns an empty *TemplateMetadata instance.
type Term ¶
Term is a template-local variable whose name may shadow names in the Template environment and which may depend on preceding terms as input.