caveats

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 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

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

func BuildDebugInformation added in v0.0.3

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

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

CaveatAsExpr wraps a contextualized caveat into a caveat expression.

func CaveatExprForTesting

func CaveatExprForTesting(name string) *core.CaveatExpression

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

func CaveatForTesting

func CaveatForTesting(name string) *core.ContextualizedCaveat

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

func Invert

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

func MustCaveatExprForTestingWithContext added in v0.0.3

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

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

func ShortcircuitedOr

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

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 EvaluationErr

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

EvaluationErr is an error in evaluation of a caveat expression.

func NewEvaluationErr

func NewEvaluationErr(caveatExpr *core.CaveatExpression, err caveats.EvaluationErr) EvaluationErr

func (EvaluationErr) DetailsMetadata

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

DetailsMetadata returns the metadata for details for this error.

func (EvaluationErr) GRPCStatus

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

func (EvaluationErr) MarshalZerologObject

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

MarshalZerologObject implements zerolog.LogObjectMarshaler

type ExpressionResult

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

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

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

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

func NewParameterTypeError

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

func (ParameterTypeError) DetailsMetadata

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

DetailsMetadata returns the metadata for details for this error.

func (ParameterTypeError) GRPCStatus

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

func (ParameterTypeError) MarshalZerologObject

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

MarshalZerologObject implements zerolog.LogObjectMarshaler

type RunCaveatExpressionDebugOption

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