cel

package
v0.23.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 20 Imported by: 13

Documentation

Index

Constants

View Source
const ScopedVarName = "self"

ScopedVarName is the variable name assigned to the locally scoped data element of a CEL valid.

Variables

This section is empty.

Functions

func NewValidationActivation

func NewValidationActivation(obj interface{}, structural *schema.Structural) *validationActivation

func UnstructuredToVal

func UnstructuredToVal(unstructured interface{}, schema *structuralschema.Structural) ref.Val

UnstructuredToVal converts a Kubernetes unstructured data element to a CEL Val. The root schema of custom resource schema is expected contain type meta and object meta schemas. If Embedded resources do not contain type meta and object meta schemas, they will be added automatically.

Types

type CompilationResult

type CompilationResult struct {
	Program cel.Program
	Error   *Error
}

CompilationResult represents the cel compilation result for one rule

func Compile

func Compile(s *schema.Structural, isResourceRoot bool) ([]CompilationResult, error)

Compile compiles all the XValidations rules (without recursing into the schema) and returns a slice containing a CompilationResult for each ValidationRule, or an error. Each CompilationResult may contain: / - non-nil Program, nil Error: The program was compiled successfully

  • nil Program, non-nil Error: Compilation resulted in an error
  • nil Program, nil Error: The provided rule was empty so compilation was not attempted

type Error

type Error struct {
	Type   ErrorType
	Detail string
}

Error is an implementation of the 'error' interface, which represents a XValidation error.

func (*Error) Error

func (v *Error) Error() string

Error implements the error interface.

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 Validator

type Validator struct {
	Items      *Validator
	Properties map[string]Validator

	AdditionalProperties *Validator
	// contains filtered or unexported fields
}

Validator parallels the structure of schema.Structural and includes the compiled CEL programs for the x-kubernetes-validations of each schema node.

func NewValidator

func NewValidator(s *schema.Structural) *Validator

NewValidator returns compiles all the CEL programs defined in x-kubernetes-validations extensions of the Structural schema and returns a custom resource validator that contains nested validators for all items, properties and additionalProperties that transitively contain validator rules. Returns nil only if there no validator rules in the Structural schema. May return a validator containing only errors.

func (*Validator) Validate

func (s *Validator) Validate(fldPath *field.Path, sts *schema.Structural, obj interface{}) field.ErrorList

Validate validates all x-kubernetes-validations rules in Validator against obj and returns any errors.

Jump to

Keyboard shortcuts

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