caveats

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And added in v1.15.0

And `&&`'s together two caveat expressions. If one expression is nil, the other is returned.

func BuildDebugInformation added in v1.35.0

func BuildDebugInformation(exprResult ExpressionResult) (string, *structpb.Struct, error)

BuildDebugInformation returns a human-readable string representation of the given ExpressionResult and a Struct representation of the context values used in the expression.

func CaveatAsExpr added in v1.15.0

func CaveatAsExpr(caveat *core.ContextualizedCaveat) *core.CaveatExpression

CaveatAsExpr wraps a contextualized caveat into a caveat expression.

func CaveatExprForTesting added in v1.15.0

func CaveatExprForTesting(name string) *core.CaveatExpression

CaveatExprForTesting returns a CaveatExpression referencing a caveat with the given name and empty context.

func CaveatForTesting added in v1.15.0

func CaveatForTesting(name string) *core.ContextualizedCaveat

CaveatForTesting returns a new ContextualizedCaveat for testing, with empty context.

func Invert added in v1.15.0

Invert returns the caveat expression with a `!` placed in front of it. If the expression is nil, returns nil.

func MustCaveatExprForTestingWithContext added in v1.35.0

func MustCaveatExprForTestingWithContext(name string, context map[string]any) *core.CaveatExpression

CaveatExprForTesting returns a CaveatExpression referencing a caveat with the given name and empty context.

func Or added in v1.15.0

Or `||`'s together two caveat expressions. If one expression is nil, the other is returned.

func ShortcircuitedOr added in v1.15.0

func ShortcircuitedOr(first *core.CaveatExpression, second *core.CaveatExpression) *core.CaveatExpression

ShortcircuitedOr combines two caveat expressions via an `||`. If one of the expressions is nil, then the entire expression is *short-circuited*, and a nil is returned.

func Subtract added in v1.15.0

func Subtract(caveat *core.CaveatExpression, subtracted *core.CaveatExpression) *core.CaveatExpression

Subtract returns a caveat expression representing the subtracted expression subtracted from the given expression.

Types

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 NewEvaluationError added in v1.39.0

func NewEvaluationError(caveatExpr *core.CaveatExpression, err caveats.EvaluationError) EvaluationError

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) GRPCStatus added in v1.39.0

func (err EvaluationError) GRPCStatus() *status.Status

func (EvaluationError) MarshalZerologObject added in v1.39.0

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

MarshalZerologObject implements zerolog.LogObjectMarshaler

type ExpressionResult added in v1.15.0

type ExpressionResult interface {
	// Value is the resolved value for the expression. For partially applied expressions, this value will be false.
	Value() bool

	// IsPartial returns whether the expression was only partially applied.
	IsPartial() bool

	// MissingVarNames returns the names of the parameters missing from the context.
	MissingVarNames() ([]string, error)
}

ExpressionResult is the result of a caveat expression being run.

func RunCaveatExpression added in v1.15.0

func RunCaveatExpression(
	ctx context.Context,
	expr *core.CaveatExpression,
	context map[string]any,
	reader datastore.CaveatReader,
	debugOption RunCaveatExpressionDebugOption,
) (ExpressionResult, error)

RunCaveatExpression runs a caveat expression over the given context and returns the result.

type ParameterTypeError added in v1.16.2

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

ParameterTypeError is a type error in constructing a parameter from a value.

func NewParameterTypeError added in v1.16.2

func NewParameterTypeError(caveatExpr *core.CaveatExpression, err error) ParameterTypeError

func (ParameterTypeError) DetailsMetadata added in v1.16.2

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

DetailsMetadata returns the metadata for details for this error.

func (ParameterTypeError) GRPCStatus added in v1.16.2

func (err ParameterTypeError) GRPCStatus() *status.Status

func (ParameterTypeError) MarshalZerologObject added in v1.16.2

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

MarshalZerologObject implements zerolog.LogObjectMarshaler

type RunCaveatExpressionDebugOption added in v1.15.0

type RunCaveatExpressionDebugOption int

RunCaveatExpressionDebugOption are the options for running caveat expression evaluation with debugging enabled or disabled.

const (
	// RunCaveatExpressionNoDebugging runs the evaluation without debugging enabled.
	RunCaveatExpressionNoDebugging RunCaveatExpressionDebugOption = 0

	// RunCaveatExpressionWithDebugInformation runs the evaluation with debugging enabled.
	RunCaveatExpressionWithDebugInformation RunCaveatExpressionDebugOption = 1
)

Jump to

Keyboard shortcuts

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