v1

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 2 modules, 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

Index

Constants

View Source
const (
	// ContextSource is data read from a source tree and the manifests and
	// lock files in it, before anything is built.
	ContextSource = sbom.DocumentType_SOURCE

	// ContextBuild is data recorded by the build, or by the tool that
	// runs it, while it resolved what to build with.
	ContextBuild = sbom.DocumentType_BUILD

	// ContextAnalyzed is data read by taking apart something already
	// built: a binary, an image, the packages installed in one.
	ContextAnalyzed = sbom.DocumentType_ANALYZED
)

Variables

This section is empty.

Functions

func ExtractWithContext added in v0.4.1

func ExtractWithContext(ctx context.Context, d Decomposer, opts *DecomposerOptions) (*sbom.NodeList, error)

ExtractWithContext runs a decomposer with a context when it takes one, and without when it does not.

func NodeLists added in v0.4.1

func NodeLists(extractions []*Extraction) []*sbom.NodeList

NodeLists returns the graphs of a list of extractions, which is what Unpacker.Extract returns.

func RegisterUnpacker added in v0.3.0

func RegisterUnpacker(subjectType string, builder UnpackerBuilder)

RegisterUnpacker registers an unpacker builder for a subject type. Calling it more than once for the same subject type replaces the previous builder.

Types

type ContextDecomposer added in v0.4.1

type ContextDecomposer interface {
	Decomposer

	// ExtractWithContext is Extract, run with the caller's context.
	ExtractWithContext(context.Context, *DecomposerOptions) (*sbom.NodeList, error)
}

ContextDecomposer is implemented by decomposers that can be run with a context: the one their caller was given, which carries its cancellation and whatever else it put there, such as a logger. Extract takes none, so a decomposer that only implements Decomposer cannot be reached by either.

An unpacker runs its decomposers through ExtractWithContext, the function, which uses the method where there is one.

type ContextReporter added in v0.4.1

type ContextReporter interface {
	// GenerationContext returns the context the decomposer reads in.
	GenerationContext() GenerationContext
}

ContextReporter is implemented by decomposers that know in which context the data they return was read. It is the decomposer's to say: the same command can run decomposers that read source and others that read what was built from it.

type DecomposableSubject added in v0.3.0

type DecomposableSubject interface {
	// DecomposableType returns a stable identifier for the kind of subject
	// (e.g. "codebase", "sbom", "artifact"). The registry uses it to locate the
	// unpacker capable of processing the subject.
	DecomposableType() string
}

DecomposableSubject abstracts anything that can yield dependency data: a codebase, an SBOM, an artifact, a filesystem, a container image, etc. An Unpacker consumes subjects, and the registry routes a subject to the unpacker that knows how to process its type.

The interface is intentionally minimal for now. Concrete subject types carry their own access details (a path, a reader, an image reference) which the unpacker that handles them type-asserts to.

type Decomposer

type Decomposer interface {
	Extract(*DecomposerOptions) (*sbom.NodeList, error)
	Requirements(*DecomposerOptions) []Requirement
	DefaultOptions() any
}

Decomposer is an interface that abstracts the logic of dependency extraction from a codebase.

type DecomposerOptions

type DecomposerOptions struct {
	WorkDir string

	// Version is the version to use on the resulting root nodes after decomposing
	Version string

	// CommitHash captures the hash of the last commit when running in a repository
	CommitHash string

	// CommitTime is when that commit was made. Together with the tags
	// below it lets a decomposer name the code the way its ecosystem
	// does, where that is not the form Version comes in: a Go module at
	// an untagged commit is known by a pseudo-version, built from the
	// commit's time and hash and the version tagged before it.
	CommitTime time.Time

	// Tags lists the tags on the commit, and AncestorTags those on the
	// commits it descends from.
	Tags         []string
	AncestorTags []string

	// Networking controls how much network access decomposers are allowed.
	// Defaults to NetworkEssential.
	Networking NetworkLevel

	// Platform is the platform dependency data is resolved for, stated as
	// os or os/arch in Go's vocabulary ("linux/arm64"). Empty means the
	// platform unpack runs on. Ecosystems whose dependency graphs are
	// platform-conditional (Python markers, Go build constraints) read it;
	// the rest resolve the same graph everywhere and ignore it.
	Platform string

	// IncludeDev includes development/test dependencies in the output.
	// Maps to: Maven test scope, npm devDependencies, Rust dev-dependencies.
	IncludeDev bool

	// IncludeBuild includes build tool dependencies in the output.
	// Maps to: Maven build plugins, Rust build-dependencies.
	IncludeBuild bool

	// IncludeOptional includes optional dependencies in the output.
	// Maps to: Maven optional deps, npm optionalDependencies.
	IncludeOptional bool

	// IncludeFiles instructs system-package decomposers to also emit nodes for
	// the files installed by each package and relate them to the package via a
	// "contains" edge. Source decomposers ignore this flag.
	IncludeFiles bool
	// contains filtered or unexported fields
}

DecomposerOptions is the options set that goes into an Extract() run in a decomposer. They are meant to be ephimeral, for the invocation only, and derived from the Unpacker configuration whe invoked from there.

func (*DecomposerOptions) GetDriverOptions

func (so *DecomposerOptions) GetDriverOptions(dec Decomposer) any

func (*DecomposerOptions) SetDriverOptions

func (so *DecomposerOptions) SetDriverOptions(dec Decomposer, opts any)

type Extraction added in v0.4.1

type Extraction struct {
	// NodeList is the graph.
	NodeList *sbom.NodeList

	// Contexts are the contexts the graph's data was read in: those of
	// the decomposers that contributed to it, each once, in a fixed
	// order. A graph put together from several decomposers can hold
	// more than one, as an image does that carries both its system's
	// packages and an application's own record of what it was built
	// from. Empty when no decomposer behind the graph says.
	Contexts []GenerationContext
}

Extraction is one graph read from a subject, with what is known of how it was read. A node list holds components and how they relate; what an unpacker learns beyond that, which is a document's to state and not a component's, travels beside it here.

func Extractions added in v0.4.1

func Extractions(ctx context.Context, u Unpacker, subject DecomposableSubject) ([]*Extraction, error)

Extractions reads a subject with an unpacker and returns its graphs with what the unpacker can say of them. One that does not implement ExtractionUnpacker has its node lists returned with nothing said.

Like Unpacker.Extract, it may return graphs together with an error, when part of a subject could be read and part could not.

func NewExtraction added in v0.4.1

func NewExtraction(nl *sbom.NodeList, contexts ...GenerationContext) *Extraction

NewExtraction returns the extraction of a graph read in the given contexts.

func (*Extraction) AddContextOf added in v0.4.1

func (e *Extraction) AddContextOf(d Decomposer)

AddContextOf records the context a decomposer reads in, when it says.

func (*Extraction) AddContexts added in v0.4.1

func (e *Extraction) AddContexts(contexts ...GenerationContext)

AddContexts records contexts the graph's data was read in. One already recorded is not recorded again, and they are kept sorted, so that the order decomposers happened to run in does not show.

type ExtractionUnpacker added in v0.4.1

type ExtractionUnpacker interface {
	// Extractions reads dependency data from the given subject and
	// returns the resulting graphs, each with its contexts.
	Extractions(context.Context, DecomposableSubject) ([]*Extraction, error)
}

ExtractionUnpacker is implemented by unpackers that can say, with each graph they return, in what context it was read. It is Unpacker.Extract with more to tell: the node lists are the same ones.

type GenerationContext added in v0.4.1

type GenerationContext = sbom.DocumentType_SBOMType

GenerationContext is the point of a software's life at which the data of an SBOM was read, and so what there was to read: a source tree before any build, the build itself, or something already built. The values are the SBOM types CISA defines, as protobom names them, so a document can state them as they are.

func GenerationContextOf added in v0.4.1

func GenerationContextOf(d Decomposer) (GenerationContext, bool)

GenerationContextOf returns the context a decomposer reads in, and false when it does not say.

func MergedContexts added in v0.4.1

func MergedContexts(extractions []*Extraction) []GenerationContext

MergedContexts returns every context of a list of extractions, each once, sorted: what a graph assembled from all of them was read in.

type NetworkLevel added in v0.2.1

type NetworkLevel int

NetworkLevel controls how much network access the decomposers are allowed to use.

const (
	// NetworkEssential is the default (zero value). Enables network calls
	// that are essential for building the dependency tree plus lightweight
	// metadata requests (e.g., deps.dev, checksum files, crates.io API).
	NetworkEssential NetworkLevel = iota

	// NetworkFull enables all network calls including downloading full
	// artifacts for hash computation and zip archives for license
	// classification. Prioritizes data completeness over bandwidth.
	NetworkFull

	// NetworkDisabled disables all network calls. Only local data is used.
	// Some decomposers may produce incomplete results or fail entirely.
	NetworkDisabled NetworkLevel = -1
)

type Requirement

type Requirement interface {
	Description() string
	Check(context.Context) bool
}

Requirement

type SourceDecomposer

type SourceDecomposer interface {
	// FindCodeBases reads a path index and locates any directories that
	// contain a codebase that a decomposer understands. Typically this
	// will be the root directory, but there may be cases where a directory
	// contains many, for example in a monorepo structure.
	FindCodeBases(*code.PathIndex) ([]string, error)
}

SourceDecomposer is a decomposer that reads data from a codebase.

type SubjectDefaults added in v0.3.3

type SubjectDefaults interface {
	// DefaultSubjects returns the subject types (see
	// DecomposableSubject.DecomposableType) the decomposer runs on by
	// default. Empty means it never runs unless enabled explicitly.
	DefaultSubjects() []string
}

SubjectDefaults is implemented by decomposers that know which kinds of parent subject they should run under when nothing says otherwise. An unpacker that is handed a child subject by a parent (an image routing its filesystem, say) reads the trait to build its default option set; the options, not the trait, decide what actually runs.

type Unpacker added in v0.3.0

type Unpacker interface {
	// Extract reads dependency data from the given subject and returns the
	// resulting nodelists.
	Extract(context.Context, DecomposableSubject) ([]*sbom.NodeList, error)

	// RegisterDecomposer adds a decomposer to the unpacker.
	RegisterDecomposer(Decomposer)

	// UnregisterDecomposer removes a decomposer from the unpacker.
	UnregisterDecomposer(Decomposer)
}

Unpacker is the entry point for dependency extraction. An unpacker knows about one kind of subject matter (codebases, SBOMs, artifacts, ...) and uses Decomposers to crack open the different flavors of that subject.

While processing its subject, an unpacker may discover child subjects that contain further dependency data (e.g. a filesystem that contains codebases, or a container image that contains an OS package database). It dispatches those child subjects to the unpacker that handles them by looking them up in the registry (see UnpackerFor), so extraction composes recursively.

func UnpackerFor added in v0.3.0

func UnpackerFor(subject DecomposableSubject) (Unpacker, error)

UnpackerFor returns a new unpacker capable of processing the given subject, or an error if no unpacker is registered for the subject's type. This is the routing mechanism unpackers use to dispatch child subjects they discover.

type UnpackerBuilder added in v0.3.0

type UnpackerBuilder func() Unpacker

UnpackerBuilder returns a new, ready-to-use Unpacker instance.

Jump to

Keyboard shortcuts

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