caveats

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 22 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertContextToParameters added in v1.14.0

func ConvertContextToParameters(
	contextMap map[string]any,
	parameterTypes map[string]*core.CaveatTypeReference,
	unknownParametersOption UnknownParameterOption,
) (map[string]any, error)

ConvertContextToParameters converts the given context into parameters of the types specified. Returns a type error if type conversion failed.

func ConvertContextToStruct added in v1.16.2

func ConvertContextToStruct(contextValues map[string]any) (*structpb.Struct, error)

ConvertContextToStruct converts the given context values into a context struct.

func NewSource added in v1.14.0

func NewSource(expressionString string, startPosition SourcePosition, name string) (common.Source, error)

NewSource creates a new source for compilation into a caveat.

func ParameterTypeString added in v1.31.0

func ParameterTypeString(typeRef *core.CaveatTypeReference) string

ParameterTypeString returns the string form of the type reference.

func StableContextStringForHashing added in v1.22.0

func StableContextStringForHashing(context *structpb.Struct) string

StableContextStringForHashing returns a stable string version of the context, for use in hashing.

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) ContextStruct added in v1.16.2

func (cr CaveatResult) ContextStruct() (*structpb.Struct, error)

ContextStruct returns the context values used when computing this result as a structpb.

func (CaveatResult) ContextValues added in v1.15.0

func (cr CaveatResult) ContextValues() map[string]any

ContextValues returns the context values used when computing this result.

func (CaveatResult) ExpressionString added in v1.15.0

func (cr CaveatResult) ExpressionString() (string, error)

ExpressionString returns the human-readable expression string for the evaluated expression.

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.

func (CompilationErrors) ColumnPosition added in v1.14.0

func (err CompilationErrors) ColumnPosition() int

ColumnPositionis the 0-indexed column position for compilation error.

func (CompilationErrors) DetailsMetadata added in v1.14.0

func (err CompilationErrors) DetailsMetadata() map[string]string

DetailsMetadata returns the metadata for details for this error.

func (CompilationErrors) LineNumber added in v1.14.0

func (err CompilationErrors) LineNumber() int

LineNumber is the 0-indexed line number for compilation error.

func (CompilationErrors) MarshalZerologObject added in v1.14.0

func (err CompilationErrors) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler

type CompiledCaveat

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

CompiledCaveat is a compiled form of a caveat.

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 CompileCaveatWithSource added in v1.14.0

func CompileCaveatWithSource(env *Environment, name string, source common.Source) (*CompiledCaveat, error)

CompileCaveatWithSource compiles a caveat source into a compiled caveat, or returns the compilation errors.

func DeserializeCaveat

func DeserializeCaveat(serialized []byte, parameterTypes map[string]types.VariableType) (*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) ReferencedParameters added in v1.14.0

func (cc CompiledCaveat) ReferencedParameters(parameters []string) *mapz.Set[string]

ReferencedParameters returns the names of the parameters referenced in the expression.

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]types.VariableType) (*Environment, error)

EnvForVariables returns a new environment constructed for the given variables.

func MustEnvForVariables added in v1.14.0

func MustEnvForVariables(vars map[string]types.VariableType) *Environment

MustEnvForVariables returns a new environment constructed for the given variables or panics.

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 types.VariableType) error

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

func (*Environment) EncodedParametersTypes added in v1.14.0

func (e *Environment) EncodedParametersTypes() map[string]*core.CaveatTypeReference

EncodedParametersTypes returns the map of encoded parameters for 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 EvaluationErr added in v1.16.2

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

EvaluationErr is an error in evaluation of a caveat expression.

func (EvaluationErr) DetailsMetadata added in v1.16.2

func (err EvaluationErr) DetailsMetadata() map[string]string

DetailsMetadata returns the metadata for details for this error.

func (EvaluationErr) MarshalZerologObject added in v1.16.2

func (err EvaluationErr) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler

type HashableContext added in v1.22.0

type HashableContext struct{ *structpb.Struct }

HashableContext is a wrapper around a context Struct that provides hashing.

func (HashableContext) AppendToHash added in v1.22.0

func (hc HashableContext) AppendToHash(hasher HasherInterface)

type HasherInterface added in v1.22.0

type HasherInterface interface {
	WriteString(value string)
}

HasherInterface is an interface for writing context to be hashed.

type ParameterConversionErr added in v1.14.0

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

ParameterConversionErr is an error in type conversion of a supplied parameter.

func (ParameterConversionErr) DetailsMetadata added in v1.14.0

func (err ParameterConversionErr) DetailsMetadata() map[string]string

DetailsMetadata returns the metadata for details for this error.

func (ParameterConversionErr) MarshalZerologObject added in v1.14.0

func (err ParameterConversionErr) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements zerolog.LogObjectMarshaler

func (ParameterConversionErr) ParameterName added in v1.16.2

func (err ParameterConversionErr) ParameterName() string

ParameterName is the name of the parameter.

type SourcePosition added in v1.14.0

type SourcePosition interface {
	// LineAndColumn returns the 0-indexed line number and column position in the source file.
	LineAndColumn() (int, int, error)

	// RunePosition returns the 0-indexed rune position in the source file.
	RunePosition() (int, error)
}

SourcePosition is an incoming source position.

type UnknownParameterOption added in v1.14.0

type UnknownParameterOption int

UnknownParameterOption is the option to ConvertContextToParameters around handling of unknown parameters.

const (
	// SkipUnknownParameters indicates that unknown parameters should be skipped in conversion.
	SkipUnknownParameters UnknownParameterOption = 0

	// ErrorForUnknownParameters indicates that unknown parameters should return an error.
	ErrorForUnknownParameters UnknownParameterOption = 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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