rulefiles

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rulefiles reads a project's own check rules, each one written in Datalog in a YAML file, and compiles them into a catalog source (agni issue 1713). A project lists the files under `rules:` in its project.yaml, and `agni check` runs them beside the built-in rules.

One file holds one rule. The match goal yields the subjects that fail, the optional domain goal yields every subject the rule examined, and the subjects in the domain and not in the match pass. So a rule with a domain states its considered set, as a built-in Datalog rule does. A rule without one reports failures only. docsite/content/build/check-rule.md#a-projects-own-rules is the authoring guide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(d Def, reg *facts.Registry) (*check.Rule, error)

Compile turns d into a check.Rule over reg. The catalog shows it under its source, as `<source>/<name>`. reg is the run's vocabulary, so the rule can call the project's library. A relation the vocabulary lacks, a subject the goal does not project or a domain that does not key like the match is an error naming the file.

func Source

func Source(defs []Def, reg *facts.Registry, source string) (check.RuleSource, error)

Source compiles every def into one catalog source named source. It stops at the first rule that does not compile, so a run never goes ahead with one of a project's rules quietly missing.

Types

type Context

type Context struct {
	Var  string `yaml:"var"`
	Kind string `yaml:"kind"`
	Role string `yaml:"role"`
}

Context binds a projected variable to a context entity on every finding.

type Def

type Def struct {
	// Name is the rule's name within the project. The catalog shows it as `<project>/<name>`.
	Name     string `yaml:"name"`
	Severity string `yaml:"severity"` // error, warning or info; warning when empty
	Summary  string `yaml:"summary"`
	Impact   string `yaml:"impact,omitempty"`
	Remedy   string `yaml:"remedy,omitempty"`
	// Kind is what the subject is: net, component or pin.
	Kind string `yaml:"kind"`
	// Match is a Datalog query whose rows are the failing subjects. Clauses written ahead of its goal
	// are visible to Domain too.
	Match string `yaml:"match"`
	// Subject names the projected variable that binds the subject, and Pin the one that binds its pin
	// on a pin-kind rule. Neither carries a leading "?".
	Subject string `yaml:"subject"`
	Pin     string `yaml:"pin,omitempty"`
	// Message is the finding's text, with {var} replaced by that variable's value in the row.
	Message string `yaml:"message"`
	// Domain is a Datalog query whose rows are every subject the rule examined. It must project
	// Subject, and Pin when set. Empty means the rule reports failures only.
	Domain string `yaml:"domain,omitempty"`
	// Witness is a passing subject's statement, interpolated from its domain row. It is required
	// with Domain.
	Witness string `yaml:"witness,omitempty"`
	// Context names further projected variables, each shown on the finding as a context entity.
	Context []Context `yaml:"context,omitempty"`

	// File is where the rule came from, for an error message. It is not read from the YAML.
	File string `yaml:"-"`
}

Def is one rule as its file declares it, before compiling. It is a value, so a host can carry the rules it read to the place that knows the run's vocabulary.

func Parse

func Parse(b []byte, file string) (Def, error)

Parse reads one rule file. An unknown key is an error, so a misspelt `domian:` cannot leave a rule reporting failures only without anyone noticing.

func Read

func Read(fsys fs.FS) ([]Def, error)

Read parses every `.yaml` and `.yml` file at the top of fsys, in name order. Two files naming one rule are an error.

Jump to

Keyboard shortcuts

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