rules

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(a, b types.Value) bool

func GreaterThan

func GreaterThan(a, b types.Value) bool

func GreaterThanOrEqualTo

func GreaterThanOrEqualTo(a, b types.Value) bool

func In

func In(a, b types.Value) bool

func LessThan

func LessThan(a, b types.Value) bool

func LessThanOrEqualTo

func LessThanOrEqualTo(a, b types.Value) bool

func NotEquals

func NotEquals(a, b types.Value) bool

func ParseExpression

func ParseExpression(expr string) (a, b string, o Operator, m CollectionOperationModifier, err error)

Types

type CollectionOperationModifier

type CollectionOperationModifier int
const (
	CollOne CollectionOperationModifier = iota
	CollAny
	CollAll
)

type EvaluationEnvironment

type EvaluationEnvironment map[string]interface{}

type Expression

type Expression struct {
	A, B      types.Value
	Operator  Operator
	Modifier  CollectionOperationModifier
	Condition LogicalOperator
}

Expression describes a single. Condition should be Undefined for the first element, but defined for each subsequent element.

func (Expression) Evaluate

func (e Expression) Evaluate(env EvaluationEnvironment) bool

type LogicalOperator

type LogicalOperator int
const (
	Undefined LogicalOperator = iota
	And
	Or
)

type Operator

type Operator func(a, b types.Value) bool

type Permission

type Permission struct {
	Name      string
	Condition LogicalOperator
}

type Rule

type Rule struct {
	Command     string
	Conditions  []Expression
	Permissions []Permission
}

func Parse

func Parse(rt RuleTokens) (Rule, error)

func TokenizeAndParse

func TokenizeAndParse(s string) (Rule, error)

TokenizeAndParse is a helper function that wraps the Tokenize and Parse functions. It accepts a raw Gort rule of the form "COMMAND [when CONDITION (and|or)]? [allow|must have PERMISSION (and|or)]", and returns a RuleTokens value. A parsing error will produce a non-nil error. The RuleTokens' Command value should always be non-empty; Conditions and Permissions can both be empty (but non-nil). Empty Conditions always match the command. Empty Permissions indicating the use of the "allow" keyword and always pass.

func (Rule) Allowed

func (r Rule) Allowed(permissions []string) bool

Allowed returns true iff the user has all required permissions (or the rule is an "allow" rule).

func (Rule) Matches

func (r Rule) Matches(env EvaluationEnvironment) bool

Matches returns true iff the Rule's stated conditions evaluate to true.

type RuleTokens

type RuleTokens struct {
	Command     string
	Conditions  []string
	Permissions []string
}

RuleTokens represents a tokenized Gort rule of the form "COMMAND [when CONDITION (and|or)]? [allow|must have PERMISSION (and|or)]".

func Tokenize

func Tokenize(s string) (RuleTokens, error)

Tokenize accepts a raw Gort rule of the form "COMMAND [when CONDITION (and|or)]? [allow|must have PERMISSION (and|or)]", and returns a RuleTokens value. A parsing error will produce a non-nil error. The RuleTokens' Command value should always be non-empty; Conditions and Permissions can both be empty (but non-nil). Empty Conditions always match the command. Empty Permissions indicating the use of the "allow" keyword and always pass.

func (RuleTokens) String

func (r RuleTokens) String() string

String is mostly used for debugging.

Jump to

Keyboard shortcuts

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