engine

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package engine evaluates a ruleset against collected facts using CEL and produces findings. It is pure and deterministic: same facts + same rules + same config always yield the same findings. No network, no model.

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 evaluates a single scope's rules. Build one per scope via New.

func New

func New(scope rules.Scope, rs []rules.Rule, varNames []string) (*Engine, error)

New compiles the given rules against a CEL environment whose top-level variables are `varNames` (the union of fact-field names for the scope) plus `cfg`. A compile error in any expression is returned — this is the lint that catches a typo'd field name or a non-boolean rule before evaluation.

func (*Engine) Evaluate

func (e *Engine) Evaluate(targets []Target, cfg *rules.Config, enterprise string) []Finding

Evaluate runs every compiled rule against every target, resolving per-target config via cfg layered enterprise→org→repo. The org and repo keys are derived from each target: for org scope the org is the target's own name; for repo scope (Name "owner/repo") the org is the owner. This lets one Evaluate span multiple orgs, each resolving its own overrides. Disabled rules and not-applicable targets emit no finding.

type Finding

type Finding struct {
	ID       string `json:"id"`
	Scope    string `json:"scope"`
	Severity string `json:"severity"`
	Title    string `json:"title"`
	Target   string `json:"target"`
	Status   Status `json:"status"`
	Notes    string `json:"notes,omitempty"`
	FixHint  string `json:"fix_hint,omitempty"`
}

Finding is the result of one rule against one target.

type Status

type Status string

Status is the outcome of evaluating one rule against one target.

const (
	StatusPass    Status = "pass"    // compliant
	StatusFail    Status = "fail"    // confirmed violation
	StatusUnknown Status = "unknown" // could not score (missing fact / scope) — never a pass
)

type Target

type Target struct {
	Name  string         // display id (org name, enterprise slug, owner/repo)
	Facts map[string]any // fully-normalized facts; fields bind as top-level CEL vars
}

Target is one fact-bearing entity to evaluate rules against.

Jump to

Keyboard shortcuts

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