checkdef

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package checkdef parses declarative check metadata (ID, name, description, dependencies, ...) out of an embedded definition file, so a reusable check package can keep that metadata in YAML/TOML/JSON instead of hand-assembling it in Go. It's a separate package from the root harnessx module so the core engine keeps its zero-dependency guarantee — only importers that actually parse definition files pull in a YAML/TOML parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCheck

func NewCheck(def CheckDef, run harnessx.CheckFunc, opts ...Option) harnessx.Check

NewCheck builds a ScopeGlobal harnessx.Check from a CheckDef's metadata plus a run function, so individual checks only need to supply what makes them different.

func NewResourceCheck

func NewResourceCheck(def CheckDef, run harnessx.ResourceCheckFunc, opts ...Option) harnessx.Check

NewResourceCheck builds a ScopePerResource harnessx.Check from a CheckDef's metadata plus a resource run function.

func NewVariantCheck

func NewVariantCheck(def CheckDef, run harnessx.VariantCheckFunc, opts ...Option) harnessx.Check

NewVariantCheck builds a ScopeGlobal harnessx.Check whose run function is invoked once per entry in WithVariants — the same check definition probed with different attempt variants (see VariantMode).

func NewVariantResourceCheck

func NewVariantResourceCheck(def CheckDef, run harnessx.VariantResourceCheckFunc, opts ...Option) harnessx.Check

NewVariantResourceCheck builds a ScopePerResource harnessx.Check whose resource run function is invoked once per entry in WithVariants, for each discovered resource.

Types

type CheckDef

type CheckDef struct {
	ID          string   `yaml:"id" toml:"id" json:"id"`
	Name        string   `yaml:"name" toml:"name" json:"name"`
	Description string   `yaml:"description" toml:"description" json:"description"`
	Link        string   `yaml:"link" toml:"link" json:"link"`
	Tags        []string `yaml:"tags" toml:"tags" json:"tags"`
	DependsOn   []string `yaml:"depends_on" toml:"depends_on" json:"depends_on"`
	CVSSVector  string   `yaml:"cvss_vector" toml:"cvss_vector" json:"cvss_vector"`
	CVSSScore   float64  `yaml:"cvss_score" toml:"cvss_score" json:"cvss_score"`
	CWEID       string   `yaml:"cwe_id" toml:"cwe_id" json:"cwe_id"`
	CAPECID     string   `yaml:"capec_id" toml:"capec_id" json:"capec_id"`
	OWASP       string   `yaml:"owasp" toml:"owasp" json:"owasp"`

	// Extra holds def-specific fields this package doesn't know about yet,
	// nested under an "extra" key so it parses the same way across
	// YAML/TOML/JSON (none of the three parsers support catch-all/inline
	// remainder maps consistently).
	Extra map[string]any `yaml:"extra" toml:"extra" json:"extra"`
}

CheckDef mirrors the descriptive fields of harnessx.Check (everything except behavior — Skip, Run, RunResource, Scope, Timeout, Concurrency).

func MustParseCheckDefJSON

func MustParseCheckDefJSON(pkg string, data []byte) CheckDef

MustParseCheckDefJSON unmarshals a JSON-encoded check definition into a CheckDef. It panics (with pkg-prefixed context) on malformed input — check registries are typically built at init time from an embedded file, so a bad definition is a build-time bug, not something to recover from at runtime.

func MustParseCheckDefTOML

func MustParseCheckDefTOML(pkg string, data []byte) CheckDef

MustParseCheckDefTOML unmarshals a TOML-encoded check definition into a CheckDef. It panics (with pkg-prefixed context) on malformed input — check registries are typically built at init time from an embedded file, so a bad definition is a build-time bug, not something to recover from at runtime.

func MustParseCheckDefYAML

func MustParseCheckDefYAML(pkg string, data []byte) CheckDef

MustParseCheckDefYAML unmarshals a YAML-encoded check definition into a CheckDef. It panics (with pkg-prefixed context) on malformed input — check registries are typically built at init time from an embedded file, so a bad definition is a build-time bug, not something to recover from at runtime.

func (CheckDef) DependsOnIDs

func (d CheckDef) DependsOnIDs() []harnessx.CheckID

DependsOnIDs converts DependsOn to []harnessx.CheckID for direct use in Check.DependsOn.

func (CheckDef) WithCAPECID added in v0.4.0

func (d CheckDef) WithCAPECID(id string) CheckDef

WithCAPECID returns a copy of d with CAPECID set.

func (CheckDef) WithCVSSScore added in v0.4.0

func (d CheckDef) WithCVSSScore(score float64) CheckDef

WithCVSSScore returns a copy of d with CVSSScore set.

func (CheckDef) WithCVSSVector added in v0.4.0

func (d CheckDef) WithCVSSVector(vector string) CheckDef

WithCVSSVector returns a copy of d with CVSSVector set.

func (CheckDef) WithCWEID added in v0.4.0

func (d CheckDef) WithCWEID(id string) CheckDef

WithCWEID returns a copy of d with CWEID set.

func (CheckDef) WithDependsOn added in v0.4.0

func (d CheckDef) WithDependsOn(ids ...string) CheckDef

WithDependsOn returns a copy of d with DependsOn set.

func (CheckDef) WithDescription added in v0.4.0

func (d CheckDef) WithDescription(description string) CheckDef

WithDescription returns a copy of d with Description set.

func (CheckDef) WithExtra added in v0.4.0

func (d CheckDef) WithExtra(extra map[string]any) CheckDef

WithExtra returns a copy of d with Extra set.

func (d CheckDef) WithLink(link string) CheckDef

WithLink returns a copy of d with Link set, e.g. to point at a deployment-specific advisory page.

func (CheckDef) WithName added in v0.4.0

func (d CheckDef) WithName(name string) CheckDef

WithName returns a copy of d with Name set, e.g. to relabel a check loaded from a shared definition file.

func (CheckDef) WithOWASP added in v0.4.0

func (d CheckDef) WithOWASP(owasp string) CheckDef

WithOWASP returns a copy of d with OWASP set.

func (CheckDef) WithTags added in v0.4.0

func (d CheckDef) WithTags(tags ...string) CheckDef

WithTags returns a copy of d with Tags set.

type Option

type Option func(*checkConfig)

Option configures the optional fields of a Check built by NewCheck or NewResourceCheck — everything on harnessx.Check that isn't already carried by CheckDef or the required Run/RunResource function.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets the check's per-resource Concurrency. Only meaningful on a NewResourceCheck.

func WithConditions

func WithConditions(conditions ...harnessx.Condition) Option

WithConditions sets the check's Conditions (AND-evaluated).

func WithSkip

func WithSkip(skip harnessx.SkipDecision) Option

WithSkip sets the check's SkipDecision.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the check's Timeout.

func WithVariantMode

func WithVariantMode(mode harnessx.VariantMode) Option

WithVariantMode sets how Variants are executed: VariantsSequential (default) or VariantsParallel.

func WithVariants

func WithVariants(variants ...string) Option

WithVariants sets the check's Variants — same check definition, run once per variant (e.g. the different casings of a JWT "alg: none" attack).

Jump to

Keyboard shortcuts

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