ruledef

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: 6 Imported by: 0 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 ruledef reads and writes rule DEFINITIONS (WS3-103). A rule compiles from its definition. A check.Spec, a datalog query and an interface profile are the three declarative sources, and they share this one form. See docsite/content/architecture/checks-contract.md#the-other-half-rule-definitions.

It sits ABOVE all three because core/query imports core/check and stdlib/profiles imports both, so a converter for all three cannot live in core/check without a cycle. Each source owns the wire form of its OWN body (check.SpecProto, query.QueryProto, profiles.ProfileProto). This package holds only the join, meaning which body a definition holds and how to compile it back into rules.

A type switch over the vocabulary catches a new NODE TYPE. A new FIELD is different. The converter copies a body's fields by hand, so it silently skips a new one. Profile.HostClass was dropped that way until the round-trip guard in stdlib/profiles caught it. Each body's wire form therefore needs a deep-equality round-trip test as well as a converter.

check.Rule itself is NOT serializable, because its Eval closure has no wire form. A rule with a hand-written Go Eval and no declarative twin is outside this contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(def *checkspb.RuleDef) ([]*check.Rule, error)

Compile turns one definition back into the rules it declares. It returns a SLICE because a spec and a query each yield one rule and an interface profile yields one per requirement.

Every failure mode is an error, never a panic and never a silent drop. A definition read from outside this build can name a fact, function, relation or requirement type that does not exist here, and each would otherwise produce a rule that never fires.

func CompileDeck

func CompileDeck(deck *checkspb.RuleDeck) ([]*check.Rule, error)

CompileDeck compiles every definition in a deck, in order. It stops at the first bad definition rather than skipping it, so a deck never loads with one rule quietly missing.

func Marshal

func Marshal(deck *checkspb.RuleDeck) ([]byte, error)

Marshal encodes a deck as indented protojson, since people author, review and diff rule decks.

func Parse

func Parse(b []byte) (*checkspb.RuleDeck, error)

Parse decodes a deck without compiling it, so a caller can inspect or re-emit a deck holding a definition this build cannot run.

func ProfileDef

func ProfileDef(p profiles.Profile) *checkspb.RuleDef

ProfileDef assembles a definition from an interface profile.

func QueryDef

func QueryDef(fq query.FindingQuery) *checkspb.RuleDef

QueryDef assembles a definition from a datalog rule declaration.

func Source

func Source(deck *checkspb.RuleDeck) (check.RuleSource, error)

Source compiles a deck into a check.RuleSource, so definitions read from a document join a catalog the way a Go-registered suite does. It is the data-driven counterpart to check.RegisterSource.

func SpecDef

func SpecDef(meta check.Rule, spec check.Spec) *checkspb.RuleDef

SpecDef assembles a definition from a rule's metadata and its Spec body.

Types

This section is empty.

Jump to

Keyboard shortcuts

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