Documentation
¶
Overview ¶
Package guard builds repository checks from data: each types.GuardRow becomes one or more interfaces.Guard probes over a codebase. The declarative kinds are match (line patterns), yaml (a path query) and expr (a CEL expression over files, documents and rendered objects); a go row runs the GoGuard the product registers under its name, with the expanded row, so one Go guard serves many rows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFromConfig ¶
NewFromConfig validates rows and returns their guards. Expansion runs when a guard runs, so building does no I/O. An unknown kind or expander, a go row with no registered guard, a bad pattern or a CEL expression that does not compile is CodeInvalidInput naming the row. Each expression compiles once, through deps.Programs when set.
Types ¶
type Deps ¶
type Deps struct {
// Expanders are the product's iteration domains, keyed by the name rows use in each.
Expanders map[string]Expander
// Go are the product's computed guards, keyed by the name a go row carries.
Go map[string]GoGuard
// Runner runs a tool row's tool; nil fails every tool row when it runs.
Runner interfaces.CommandRunner
// Root is the directory a tool row's tool runs in.
Root string
// Generators returns the generator a gen row names; an error fails the row. Nil
// rejects every gen row when building.
Generators func(ctx context.Context, name string) (interfaces.Generator, error)
// Cache remembers a go row's passes on its inputs (see GuardRow.Inputs); nil never
// hits, so every expansion runs.
Cache interfaces.StepCache
// Versions returns a tool's version for the cache key; nil keys every tool at "".
Versions func(tool string) string
// Now is the clock an expr row's `now` reads; nil is time.Now.
Now func() time.Time
// Programs caches the rows' compiled CEL expressions across NewFromConfig calls;
// nil compiles each expression once per call.
Programs *Programs
// RenderTool names the binary the codebase's renderer shells (helm), listed among
// the tools of every row that renders a chart; empty lists none.
RenderTool string
}
Deps carries what the guards need besides their rows.
type Expander ¶
Expander lists the rows a guard row with `each:` expands over: one map of placeholder values per guard to build.
type GoGuard ¶ added in v0.0.20
type GoGuard func( ctx context.Context, cb interfaces.Codebase, row *types.GuardRow, vars map[string]string, ) ([]types.Finding, error)
GoGuard is a product check the declarative kinds cannot express. It runs once per expansion of its row, with the expanded row (its selector, render spec and message) and the expansion's placeholders, and returns its findings; none is a pass.
type Programs ¶ added in v0.0.35
type Programs struct {
// contains filtered or unexported fields
}
Programs caches compiled guard expressions: one CEL environment, built on first use, and each expression's program, keyed by its source. A caller that builds guards more than once (a composite gate's phases, one gate per run) shares one through Deps.Programs, so each expression type-checks once per process; nil gives every NewFromConfig call its own. Safe for concurrent use: a CEL environment and program are.
func NewPrograms ¶ added in v0.0.35
func NewPrograms() *Programs
NewPrograms returns an empty expression cache.