Documentation
¶
Overview ¶
Package stitch enriches dependency graphs with supplemental bills of materials. A catalog indexes the components the supplements describe by hash and purl; the stitcher matches every node of an extraction against it and grafts each describing supplement onto the node, merged into it or hung below it, using protobom's graft, absorb and dedupe operations.
Index ¶
- Constants
- type Catalog
- func (c *Catalog) Add(source string, doc *protosbom.Document) *Supplement
- func (c *Catalog) Entries() []*Entry
- func (c *Catalog) Load(paths ...string) error
- func (c *Catalog) LoadFile(path string) error
- func (c *Catalog) LoadFileWithContext(ctx context.Context, path string) error
- func (c *Catalog) LoadWithContext(ctx context.Context, paths ...string) error
- func (c *Catalog) Match(n *protosbom.Node) []*Entry
- func (c *Catalog) Supplements() []*Supplement
- func (c *Catalog) Unparsed() []string
- func (c *Catalog) Unused() []*Entry
- type Entry
- type Options
- type Report
- type Stitched
- type Stitcher
- type Supplement
- type Unpacker
Constants ¶
const PropertyStitchedFrom = "unpack:stitched-from"
PropertyStitchedFrom is set on every node a supplement was stitched onto, naming the source the supplement was loaded from.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog holds supplements and finds the entries describing a node by its hashes or purl.
func (*Catalog) Add ¶
func (c *Catalog) Add(source string, doc *protosbom.Document) *Supplement
Add registers a parsed document as a supplement, indexing the components it describes. A document that describes nothing is kept but can never match.
func (*Catalog) Load ¶
Load reads supplements from the given paths. A path naming a file must parse as a bill of materials, bare or enveloped. A path naming a directory is walked, and every regular file in it that parses is added; the rest are skipped and listed by Unparsed, since a directory of documents may hold a README next to them.
func (*Catalog) LoadFileWithContext ¶ added in v0.4.1
LoadFileWithContext is LoadFile, run with the caller's context.
func (*Catalog) LoadWithContext ¶ added in v0.4.1
LoadWithContext is Load, run with the caller's context, whose logger it reports to.
func (*Catalog) Match ¶
Match returns the entries describing the node, in catalog order. An entry describes a node under sbom.SameComponent's rule, minus the node type: they share a hash under some algorithm and disagree under none, or, when they share no hash algorithm, they carry the same purl. A package in a document may well describe a file found on disk, and the stitcher decides what that means.
func (*Catalog) Supplements ¶
func (c *Catalog) Supplements() []*Supplement
Supplements returns the loaded supplements in load order.
type Entry ¶
type Entry struct {
Supplement *Supplement
// Node is the described component as the supplement states it.
Node *protosbom.Node
// Used records that the entry matched something during stitching, so
// supplements nobody asked for can be reported.
Used bool
}
Entry is one component a supplement describes: a root element of its document, which the catalog matches against nodes found in an extraction. The graph below it is what gets stitched under the match.
type Options ¶
type Options struct {
// Identity decides which nodes the dedupe pass collapses. Nil means
// sbom.SameComponent.
Identity sbom.NodeIdentity
// NoDedupe leaves duplicate nodes in place after stitching. By
// default, nodes that two supplements, or a supplement and the
// extraction, both describe are collapsed into one.
NoDedupe bool
}
Options configures a Stitcher.
type Report ¶
type Report struct {
// Stitched lists every entry applied, in the order it was applied.
Stitched []Stitched
// Dropped maps the ids of nodes the dedupe pass removed to the
// nodes that survived in their place.
Dropped map[string]string
}
Report says what a Stitch call did.
type Stitched ¶
type Stitched struct {
// NodeID is the node in the enriched list the entry was applied to.
NodeID string
// Entry is the supplement entry that described it.
Entry *Entry
// Merged reports whether the entry was folded into the node (same
// node type) rather than hung below it.
Merged bool
}
Stitched records one supplement entry applied to one node.
type Stitcher ¶
Stitcher enriches node lists with the supplements of a catalog.
func (*Stitcher) Stitch ¶
Stitch enriches nl in place. Every node is matched against the catalog, and each entry describing it is stitched onto it: an entry of the same node type is merged into the node, keeping what the node states and adding what the supplement knows, with the supplement's graph below; a package entry describing a file node is hung under the file with a generatedFrom edge, the way a decomposed binary relates to the package it was built from; a file entry describing a package node is hung under it with a contains edge. Stitched-in nodes are matched in turn, so supplements chain, except that a supplement never applies within the graph it brought in itself. Every node stitched onto gets a BOM reference to the supplement's document and a property naming its source. Unless disabled, a dedupe pass then collapses the nodes that now describe the same component.
type Supplement ¶
type Supplement struct {
// Source is the path the document was read from.
Source string
// Document is the parsed bill of materials. Its node list is what gets
// stitched; its metadata identifies it for provenance.
Document *protosbom.Document
// Entries are the components the document describes, one per root
// element, in document order.
Entries []*Entry
}
Supplement is a bill of materials loaded to enrich an extraction: the document and where it came from.
type Unpacker ¶
type Unpacker struct {
Inner api.Unpacker
Stitcher *Stitcher
// Reports collects the report of every list stitched, in order.
Reports []*Report
}
Unpacker wraps another unpacker and stitches the catalog's supplements into everything it extracts. It satisfies api.Unpacker, so it stands in for the inner unpacker wherever one is used.
func Wrap ¶
Wrap returns an unpacker that runs inner and stitches its results with the catalog's supplements.
func (*Unpacker) Extract ¶
func (u *Unpacker) Extract(ctx context.Context, subject api.DecomposableSubject) ([]*sbom.NodeList, error)
Extract runs the inner unpacker and stitches every list it returns. Lists returned alongside an error are stitched too, since the inner unpacker chose to return them.
func (*Unpacker) RegisterDecomposer ¶
func (u *Unpacker) RegisterDecomposer(d api.Decomposer)
RegisterDecomposer registers with the inner unpacker.
func (*Unpacker) UnregisterDecomposer ¶
func (u *Unpacker) UnregisterDecomposer(d api.Decomposer)
UnregisterDecomposer unregisters from the inner unpacker.