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 ¶
- func Compile(def *checkspb.RuleDef) ([]*check.Rule, error)
- func CompileDeck(deck *checkspb.RuleDeck) ([]*check.Rule, error)
- func Marshal(deck *checkspb.RuleDeck) ([]byte, error)
- func Parse(b []byte) (*checkspb.RuleDeck, error)
- func ProfileDef(p profiles.Profile) *checkspb.RuleDef
- func QueryDef(fq query.FindingQuery) *checkspb.RuleDef
- func Source(deck *checkspb.RuleDeck) (check.RuleSource, error)
- func SpecDef(meta check.Rule, spec check.Spec) *checkspb.RuleDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
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 ¶
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 ¶
Marshal encodes a deck as indented protojson, since people author, review and diff rule decks.
func Parse ¶
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 ¶
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.
Types ¶
This section is empty.