Documentation
¶
Overview ¶
Package tooladapter turns an external command-line security tool into a Draugr Scanner declaratively: describe how to build the command for a target, and the adapter runs it and parses its SARIF output. This covers the majority of scanners (many emit SARIF natively) with no bespoke code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is a Scanner backed by an external tool.
func New ¶
New builds an Adapter. If cfg.Run is nil, the command is executed and its stdout is used as SARIF.
func (*Adapter) CacheVersion ¶ added in v0.10.0
CacheVersion reports the tool/data version for the cache key, when the adapter was configured with one (implements plugin.CacheVersioner). Empty otherwise.
func (*Adapter) Info ¶
func (a *Adapter) Info() plugin.ScannerInfo
Info describes the underlying tool.
type Config ¶
type Config struct {
Name string
Binary string
Version string
Controls []string
TargetKinds []plugin.TargetKind
// Argv builds the command line (argv[0] is the executable) for a target and config.
Argv func(target plugin.Target, cfg plugin.Config) ([]string, error)
// Run executes argv and returns the tool's output. Optional; defaults to executing the
// command and capturing stdout. Draugr's built-in scanners pass a shared implementation
// that puts the tool's own first line of stderr into the error — `exit status 1` on its own
// tells a reader nothing, and that string is what reaches the terminal and the report.
Run func(ctx context.Context, argv []string) ([]byte, error)
// Parse decodes the tool's output. Optional — nil means the tool emits SARIF, which most
// do. A tool that reports in its own JSON supplies the conversion here rather than needing
// a scanner type of its own.
Parse func(out []byte, target plugin.Target, cfg plugin.Config) (sarif.Report, error)
// CacheVersion, when set, contributes a tool/data version to the cache key (see
// plugin.CacheVersioner). Optional.
CacheVersion func(ctx context.Context) string
// Prewarm, when set, warms shared tool state once before a run's fan-out (see
// plugin.Prewarmer). Optional.
Prewarm func(ctx context.Context) error
// Refine, when set, adjusts the parsed report before it is returned. Tools describe a
// finding's location in their own terms, which aren't always meaningful outside the tool;
// this is where a scanner restates them in the target's terms. Optional.
Refine func(target plugin.Target, report sarif.Report) sarif.Report
}
Config declares how to adapt a tool.