rules

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalComposite

func EvalComposite(local, global *Engine, ctx *fingerprint.RequestCtx) (action Action, upstream, ruleID string, rule *Rule, prefix string)

EvalComposite evaluates the request against a listener-specific engine first and then the global engine. The global engine's DefaultAction is used when no rule matches. Either engine may be nil.

Types

type Action

type Action string

Action is the result of a matching rule.

const (
	ActionAllow   Action = "allow"
	ActionDeny    Action = "deny"
	ActionRoute   Action = "route"
	ActionDeceive Action = "deceive"
)

type And

type And struct{ Kids []Expr }

func (And) Eval

func (a And) Eval(c *fingerprint.RequestCtx) bool

type Cond

type Cond struct {
	Matcher func(*fingerprint.RequestCtx) bool
}

Cond wraps a matcher function.

func (Cond) Eval

func (c Cond) Eval(ctx *fingerprint.RequestCtx) bool

type Engine

type Engine struct {
	Rules         []*Rule
	DefaultAction Action
	// contains filtered or unexported fields
}

Engine evaluates incoming requests against loaded rules.

func (*Engine) Eval

func (e *Engine) Eval(ctx *fingerprint.RequestCtx) (action Action, upstream, ruleID string)

func (*Engine) EvalRule

func (e *Engine) EvalRule(ctx *fingerprint.RequestCtx) *Rule

Eval finds the first matching rule for the request context. If no rule matches, ActionAllow and empty ruleID are returned.

func (*Engine) Load

func (e *Engine) Load(rs *RuleSet)

Load replaces the engine rule set atomically.

func (*Engine) LoadFromFile

func (e *Engine) LoadFromFile(path string) error

LoadFromFile loads rule definitions from an HCL file.

type Expr

type Expr interface {
	Eval(*fingerprint.RequestCtx) bool
}

Expr represents a boolean expression node.

type FieldGetter

type FieldGetter func(*fingerprint.RequestCtx) []string

FieldGetter returns zero or more values for a field.

type Or

type Or struct{ Kids []Expr }

func (Or) Eval

func (o Or) Eval(c *fingerprint.RequestCtx) bool

type Rule

type Rule struct {
	ID            string
	Action        Action
	DeceptionMode string
	Upstream      *url.URL
	StripPrefix   string
	Expires       *time.Time
	Expr          Expr
}

Rule is a compiled rule from the HCL file.

func (*Rule) Matches

func (r *Rule) Matches(ctx *fingerprint.RequestCtx) bool

type RuleSet

type RuleSet struct{ Rules []*Rule }

RuleSet is a set of compiled rules.

func LoadHCL

func LoadHCL(path string) (*RuleSet, error)

LoadHCL loads rules from an HCL file.

func LoadHCLBytes

func LoadHCLBytes(data []byte) (*RuleSet, error)

LoadHCLBytes loads rules from an HCL byte slice.

Jump to

Keyboard shortcuts

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