converter

package
v0.189.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package converter reads the file a converter writes for Draugr to import: the findings of a tool Draugr has no reader for, with those of Draugr's own result properties a declared converter may set.

A converter is a program a CI step runs on another tool's output. Draugr never runs it. It reads the file the step wrote, as it reads any import, held to a commit, because running a program at scan time would put arbitrary code execution inside the scan.

The file follows a versioned contract, draugr-converter.v1.schema.json, embedded here as the one description of the file's shape. Read holds a file to it key by key, so a converter's author is told which key of which result is wrong, and to a fixed list of the properties a converter may set (Properties). Each of those adds evidence about a finding or raises it. A property that sets a finding aside or lowers it (Never) is refused by name, whatever the descriptor says: a finding moves down only on evidence Draugr can check, and a converter's word is not that evidence.

Index

Constants

View Source
const ID = "draugr-converter"

ID is the contract's id, which every converter file states as its `contract`.

View Source
const SchemaFile = "draugr-converter.v1.schema.json"

SchemaFile is the name the schema is kept and published under.

View Source
const Version = 1

Version is the contract version this build reads. A file stating any other is refused, naming this one, because a reader that guessed at an older or newer shape would read some of its keys and drop the rest without a word.

Variables

View Source
var Never = []string{
	"suppression", "suppressions", "aside", "nonShipping", "acceptedBy", "origin",
	"priority", "priorityCap", "rankedAs", "unreachable",
}

Never are the result properties no converter may set, whatever a descriptor declares: each sets a finding aside, says who accepted it, or ranks it lower. A file naming one is refused by name rather than read without it, so the converter's author learns the property was never going to apply.

Properties is the allow-list, fixed here. A descriptor's converter.sets may name fewer of them and never another.

View Source
var SchemaJSON []byte

SchemaJSON is the contract's JSON Schema, embedded so the binary reads files against exactly the contract it documents.

Functions

func Allowed

func Allowed(name string) bool

Allowed reports whether name is a property a converter may set.

func Forbidden

func Forbidden(name string) bool

Forbidden reports whether name is a property no converter may set.

Types

type Converter

type Converter struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

Converter is the converter that wrote a file.

type Document

type Document struct {
	Contract   string    `json:"contract"`
	Version    int       `json:"version"`
	Converter  Converter `json:"converter"`
	Source     Source    `json:"source"`
	Commit     string    `json:"commit"`
	Repository string    `json:"repository,omitempty"`
	Written    string    `json:"written,omitempty"`
	Results    []Result  `json:"results"`
}

Document is a converter file.

func Read

func Read(data []byte, allowed []Property) (Document, error)

Read reads a converter file, held to the contract and to allowed, the properties the descriptor declares the converter sets. Anything else the file sets is an error naming it.

The checks run in the order a converter's author fixes them: whether it is a converter file at all, its version, a property no converter may set, then the contract key by key, and last a property the descriptor did not declare.

type Location

type Location struct {
	Path string `json:"path"`
	Line int    `json:"line,omitempty"`
}

Location is where a finding is, relative to the repository's root.

type Package

type Package struct {
	Name         string `json:"name"`
	Version      string `json:"version,omitempty"`
	FixedVersion string `json:"fixedVersion,omitempty"`
	PURL         string `json:"purl,omitempty"`
	Ecosystem    string `json:"ecosystem,omitempty"`
}

Package is the dependency a finding is about.

type Property

type Property string

Property is one of Draugr's result properties a converter may set.

const (
	// PropertyPackage is the dependency a finding is about, with its version, fixed version and
	// package URL.
	PropertyPackage Property = "package"
	// PropertyCWE is the CWE ids of the flaw.
	PropertyCWE Property = "cwe"
	// PropertyLabels is labels on the finding, beside the component's own.
	PropertyLabels Property = "labels"
	// PropertyReachable is a verdict that the project's code reaches the vulnerable code.
	PropertyReachable Property = "reachable"
	// PropertyRaise is a band the finding is ranked at least at.
	PropertyRaise Property = "raise"
)

The properties a converter may set. Each adds evidence about a finding or raises it.

type Raise

type Raise struct {
	Priority string `json:"priority"`
	Reason   string `json:"reason"`
}

Raise is a band a finding is ranked at least at, and why.

type Result

type Result struct {
	RuleID    string            `json:"ruleId"`
	Message   string            `json:"message"`
	Severity  string            `json:"severity"`
	Score     *float64          `json:"score,omitempty"`
	Location  *Location         `json:"location,omitempty"`
	Package   *Package          `json:"package,omitempty"`
	CWE       []string          `json:"cwe,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
	Reachable *bool             `json:"reachable,omitempty"`
	Raise     *Raise            `json:"raise,omitempty"`
}

Result is one finding.

func (Result) Sets

func (r Result) Sets() []Property

Sets are the properties the result sets, in the order Properties lists them. A key written with an empty value still sets its property, so a file cannot slip one past converter.sets by leaving it empty.

type Source

type Source struct {
	Tool    string `json:"tool"`
	Version string `json:"version,omitempty"`
	File    string `json:"file,omitempty"`
	SHA256  string `json:"sha256,omitempty"`
}

Source is the tool whose output a converter read, and the file it read.

Jump to

Keyboard shortcuts

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