classify

package
v0.44.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package classify applies an ordered list of rules to a parsed stack and returns the set of matching categories. It is pure: it does not know whether a rule originated from a preset or a custom config block.

Index

Constants

This section is empty.

Variables

View Source
var PresetNames = []string{"iam"}

PresetNames lists available built-in preset names (for error messages).

Functions

This section is empty.

Types

type Category added in v0.5.0

type Category = domain.Category

Category is one matched rule's outcome. Alias of the canonical domain type; see internal/domain for the field/JSON contract.

func Classify

func Classify(s plan.RawStack, rules []Rule, moveTargets moveset.Set) []Category

Classify returns a Category for every rule that matches enough changes, in rule order. The slice is empty when no rule fires — the caller supplies the display fallback. Rules are independent; there is no first-match-wins.

func Summarize added in v0.5.0

func Summarize(perStack [][]Category, rules []Rule) []Category

Summarize unions categories across stacks: for each rule (in rules order) that any stack matched, it returns one Category whose Attributes merge every matching stack's values (sorted-unique per key). Categories no stack matched are omitted.

type Derivation added in v0.5.6

type Derivation struct {
	Attribute     string         // emitted attribute this fills, e.g. "project"
	TypePattern   *regexp.Regexp // restrict to matching resource types; nil → any
	FromAttribute string         // source scalar attribute to read from the change
	Pattern       *regexp.Regexp // capture group (named "value", else group 1) yields the value
}

Derivation recovers an emitted attribute that a matched change does not carry directly, by reading another scalar attribute and pulling a substring from it. It is per-resource (each change derives its own value), so it works for bucket-/folder-scoped IAM in multi-project stacks where the stack-project fallback cannot disambiguate. It never overrides a value the change already carries.

type Rule

type Rule struct {
	Name           string
	Icon           string
	TypePattern    *regexp.Regexp // nil → match any resource type
	Actions        []string       // nil/empty → match any action; else all listed must be present
	MinCount       int            // minimum matching changes for the rule to fire (treated as 1 if <1)
	EmitAttributes []string       // attribute names to extract from matched changes
	Derivations    []Derivation   // per-resource recovery of an emit attribute that is absent
}

Rule is a single classification rule with a deliberately small matcher.

func PresetRule added in v0.43.0

func PresetRule(name, iconOverride string, emitAttributes []string) (Rule, bool)

PresetRule returns the built-in rule bundle for name. iconOverride replaces the preset's default glyph when non-empty; emitAttributes is carried onto the rule. ok is false for unknown names.

Jump to

Keyboard shortcuts

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