tooladapter

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

func New(cfg Config) *Adapter

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

func (a *Adapter) CacheVersion(ctx context.Context) string

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.

func (*Adapter) Prewarm added in v0.11.0

func (a *Adapter) Prewarm(ctx context.Context) error

Prewarm warms shared tool state before a run, when the adapter was configured with a prewarm hook (implements plugin.Prewarmer). No-op otherwise.

func (*Adapter) Scan

func (a *Adapter) Scan(ctx context.Context, target plugin.Target, cfg plugin.Config) (sarif.Report, error)

Scan builds and runs the command for target, then decodes its output. The tool name is backfilled onto the report and its results when the tool omits it.

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.

Jump to

Keyboard shortcuts

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