rules

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package rules provides a CEL-based rule engine for custom audit checks.

Rules are defined in YAML files and compiled once into efficient CEL programs. Each rule specifies a boolean condition that is evaluated against a crawled page; when the condition is true, the engine produces an model.Issue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine holds pre-compiled CEL rules ready for evaluation.

func NewEngine

func NewEngine(rules []Rule, l logger.Logger) (*Engine, error)

NewEngine compiles the given rules into CEL programs and returns an Engine. An error is returned if any rule has an invalid CEL expression or glob pattern.

func (*Engine) Evaluate

func (e *Engine) Evaluate(_ context.Context, page *model.Page) []model.Issue

Evaluate runs all compiled rules against the given page and returns any issues.

func (*Engine) RuleCount

func (e *Engine) RuleCount() int

RuleCount returns the number of compiled rules in the engine.

type Rule

type Rule struct {
	Name      string `yaml:"name"`
	Severity  string `yaml:"severity"`  // critical, warning, info
	Match     string `yaml:"match"`     // URL glob pattern; empty or "*" matches everything
	Condition string `yaml:"condition"` // CEL boolean expression
	Message   string `yaml:"message"`   // human-readable issue message
}

Rule describes a single user-defined audit rule.

type RuleChecker

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

RuleChecker adapts a rules Engine to the [audit.Checker] interface.

func NewRuleChecker

func NewRuleChecker(engine *Engine) *RuleChecker

NewRuleChecker wraps an Engine as an audit.Checker.

func (*RuleChecker) Check

func (c *RuleChecker) Check(ctx context.Context, page *model.Page) []model.Issue

Check evaluates all CEL rules against the given page.

func (*RuleChecker) Name

func (c *RuleChecker) Name() string

Name returns the checker identifier.

type RuleFile

type RuleFile struct {
	Rules []Rule `yaml:"rules"`
}

RuleFile is the top-level YAML structure for a rules file.

func LoadRuleFile

func LoadRuleFile(path string) (*RuleFile, error)

LoadRuleFile reads and parses a YAML rule file from disk.

Jump to

Keyboard shortcuts

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