caveats

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AnyType       = VariableType{"any", cel.AnyType}
	BooleanType   = VariableType{"bool", cel.BoolType}
	StringType    = VariableType{"string", cel.StringType}
	IntType       = VariableType{"int", cel.IntType}
	UIntType      = VariableType{"uint", cel.UintType}
	BytesType     = VariableType{"bytes", cel.BytesType}
	DoubleType    = VariableType{"double", cel.DoubleType}
	DurationType  = VariableType{"duration", cel.DurationType}
	TimestampType = VariableType{"timestamp", cel.TimestampType}
)
View Source
var IPAddressType = VariableType{"ipaddress", cel.ObjectType("IPAddress")}

IPAddressType defines a specialized representation of an IPAddress.

Functions

func BasicTypeKeywords

func BasicTypeKeywords() []string

BasicTypeKeywords returns the keywords associated with basic types.

func TypeKeywords

func TypeKeywords() []string

TypeKeywords returns all keywords associated with types.

Types

type CaveatResult

type CaveatResult struct {
	// contains filtered or unexported fields
}

CaveatResult holds the result of evaluating a caveat.

func EvaluateCaveat

func EvaluateCaveat(caveat *CompiledCaveat, contextValues map[string]any) (*CaveatResult, error)

EvaluateCaveat evaluates the compiled caveat with the specified values, and returns the result or an error.

func EvaluateCaveatWithConfig

func EvaluateCaveatWithConfig(caveat *CompiledCaveat, contextValues map[string]any, config *EvaluationConfig) (*CaveatResult, error)

EvaluateCaveatWithConfig evaluates the compiled caveat with the specified values, and returns the result or an error.

func (CaveatResult) IsPartial

func (cr CaveatResult) IsPartial() bool

IsPartial returns true if the caveat was only partially evaluated.

func (CaveatResult) MissingVarNames added in v1.13.0

func (cr CaveatResult) MissingVarNames() ([]string, error)

MissingVarNames returns the name(s) of the missing variables.

func (CaveatResult) PartialValue

func (cr CaveatResult) PartialValue() (*CompiledCaveat, error)

PartialValue returns the partially evaluated caveat. Only applies if IsPartial is true.

func (CaveatResult) Value

func (cr CaveatResult) Value() bool

Value returns the computed value for the result.

type CompilationErrors

type CompilationErrors struct {
	// contains filtered or unexported fields
}

CompilationErrors is a wrapping error for containing compilation errors for a Caveat.

type CompiledCaveat

type CompiledCaveat struct {
	// contains filtered or unexported fields
}

CompiledCaveat is a compiled form of a caveat.

func CompileCaveat

func CompileCaveat(env *Environment, exprString string) (*CompiledCaveat, error)

CompileCaveat compiles a caveat string into a compiled caveat, or returns the compilation errors.

func CompileCaveatWithName added in v1.13.0

func CompileCaveatWithName(env *Environment, exprString, name string) (*CompiledCaveat, error)

CompileCaveatWithName compiles a caveat string into a compiled caveat with a given name, or returns the compilation errors.

func DeserializeCaveat

func DeserializeCaveat(serialized []byte) (*CompiledCaveat, error)

DeserializeCaveat deserializes a byte-serialized caveat back into a CompiledCaveat.

func (CompiledCaveat) ExprString

func (cc CompiledCaveat) ExprString() (string, error)

ExprString returns the string-form of the caveat.

func (CompiledCaveat) Name added in v1.13.0

func (cc CompiledCaveat) Name() string

Name represents a user-friendly reference to a caveat

func (CompiledCaveat) Serialize

func (cc CompiledCaveat) Serialize() ([]byte, error)

Serialize serializes the compiled caveat into a byte string for storage.

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment defines the evaluation environment for a caveat.

func EnvForVariables

func EnvForVariables(vars map[string]VariableType) (*Environment, error)

EnvForVariables returns a new environment constructed for the given variables.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates and returns a new environment for compiling a caveat.

func (*Environment) AddVariable

func (e *Environment) AddVariable(name string, varType VariableType) error

AddVariable adds a variable with the given type to the environment.

type EvaluationConfig

type EvaluationConfig struct {
	// MaxCost is the max cost of the caveat to be executed.
	MaxCost uint64
}

EvaluationConfig is configuration given to an EvaluateCaveatWithConfig call.

type VariableType

type VariableType struct {
	// contains filtered or unexported fields
}

VariableType defines the supported types of variables in caveats.

func ListType

func ListType(valueType VariableType) VariableType

ListType returns a new type of list over items of the given type.

func MapType

func MapType(keyType VariableType, valueType VariableType) VariableType

MapType returns a type of a map with keys and values of the given types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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