Documentation ¶
Index ¶
- func ConvertContextToParameters(contextMap map[string]any, parameterTypes map[string]*core.CaveatTypeReference, ...) (map[string]any, error)
- func ConvertContextToStruct(contextValues map[string]any) (*structpb.Struct, error)
- func NewSource(expressionString string, name string) (common.Source, error)
- func ParameterTypeString(typeRef *core.CaveatTypeReference) string
- func StableContextStringForHashing(context *structpb.Struct) string
- type CaveatResult
- func (cr CaveatResult) ContextStruct() (*structpb.Struct, error)
- func (cr CaveatResult) ContextValues() map[string]any
- func (cr CaveatResult) ExpressionString() (string, error)
- func (cr CaveatResult) IsPartial() bool
- func (cr CaveatResult) MissingVarNames() ([]string, error)
- func (cr CaveatResult) ParentCaveat() *CompiledCaveat
- func (cr CaveatResult) PartialValue() (*CompiledCaveat, error)
- func (cr CaveatResult) Value() bool
- type CompiledCaveat
- func CompileCaveatWithName(env *Environment, exprString, name string) (*CompiledCaveat, error)
- func CompileCaveatWithSource(env *Environment, name string, source common.Source, ...) (*CompiledCaveat, error)
- func DeserializeCaveat(serialized []byte, parameterTypes map[string]types.VariableType) (*CompiledCaveat, error)
- func (cc CompiledCaveat) ExprString() (string, error)
- func (cc CompiledCaveat) Name() string
- func (cc CompiledCaveat) ReferencedParameters(parameters []string) (*mapz.Set[string], error)
- func (cc CompiledCaveat) RewriteVariable(oldName, newName string) (CompiledCaveat, error)
- func (cc CompiledCaveat) Serialize() ([]byte, error)
- type Environment
- type EvaluationConfig
- type EvaluationError
- type HashableContext
- type HasherInterface
- type MultipleCompilationError
- type ParameterConversionError
- type SourcePosition
- type UnknownParameterOption
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
ConvertContextToStruct converts the given context values into a context struct.
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
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) ParentCaveat ¶ added in v1.35.0
func (cr CaveatResult) ParentCaveat() *CompiledCaveat
ParentCaveat returns the caveat that was evaluated to produce this result.
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 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, startPosition SourcePosition) (*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
ReferencedParameters returns the names of the parameters referenced in the expression.
func (CompiledCaveat) RewriteVariable ¶ added in v1.35.0
func (cc CompiledCaveat) RewriteVariable(oldName, newName string) (CompiledCaveat, error)
RewriteVariable replaces the use of a variable with another variable in the compiled 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]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 EvaluationError ¶ added in v1.39.0
type EvaluationError struct {
// contains filtered or unexported fields
}
EvaluationError is an error in evaluation of a caveat expression.
func (EvaluationError) DetailsMetadata ¶ added in v1.39.0
func (err EvaluationError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
func (EvaluationError) MarshalZerologObject ¶ added in v1.39.0
func (err EvaluationError) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog.LogObjectMarshaler
type HashableContext ¶ added in v1.22.0
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 MultipleCompilationError ¶ added in v1.39.0
type MultipleCompilationError struct {
// contains filtered or unexported fields
}
MultipleCompilationError is a wrapping error for containing compilation errors for a Caveat.
func (MultipleCompilationError) ColumnPosition ¶ added in v1.39.0
func (err MultipleCompilationError) ColumnPosition() int
ColumnPositionis the 0-indexed column position for compilation error.
func (MultipleCompilationError) DetailsMetadata ¶ added in v1.39.0
func (err MultipleCompilationError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
func (MultipleCompilationError) LineNumber ¶ added in v1.39.0
func (err MultipleCompilationError) LineNumber() int
LineNumber is the 0-indexed line number for compilation error.
func (MultipleCompilationError) MarshalZerologObject ¶ added in v1.39.0
func (err MultipleCompilationError) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog.LogObjectMarshaler
type ParameterConversionError ¶ added in v1.39.0
type ParameterConversionError struct {
// contains filtered or unexported fields
}
ParameterConversionError is an error in type conversion of a supplied parameter.
func (ParameterConversionError) DetailsMetadata ¶ added in v1.39.0
func (err ParameterConversionError) DetailsMetadata() map[string]string
DetailsMetadata returns the metadata for details for this error.
func (ParameterConversionError) MarshalZerologObject ¶ added in v1.39.0
func (err ParameterConversionError) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog.LogObjectMarshaler
func (ParameterConversionError) ParameterName ¶ added in v1.39.0
func (err ParameterConversionError) 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 )