Documentation
¶
Index ¶
- Variables
- func CanonicalCodebasePath(relativePath string) (string, error)
- func GenerateCodebaseID(language, relativePath string) (string, error)
- func ParseCodebaseID(id string) (language, path string, err error)
- type Codebase
- type CodebaseInfo
- type DriverConfig
- type Options
- type Sources
- type Unpacker
- func (unpacker *Unpacker) CodebaseExtraction(ctx context.Context, path string) (*api.Extraction, error)
- func (unpacker *Unpacker) Extract(ctx context.Context, subject api.DecomposableSubject) ([]*sbom.NodeList, error)
- func (unpacker *Unpacker) ExtractCodebase(path string) (*sbom.NodeList, error)
- func (unpacker *Unpacker) ExtractCodebaseWithContext(ctx context.Context, path string) (*sbom.NodeList, error)
- func (unpacker *Unpacker) Extractions(ctx context.Context, subject api.DecomposableSubject) ([]*api.Extraction, error)
- func (unpacker *Unpacker) ListCodebases(ctx context.Context, path string) ([]CodebaseInfo, error)
- func (unpacker *Unpacker) RegisterDecomposer(d api.Decomposer)
- func (unpacker *Unpacker) RegisterDecomposerAs(language string, d api.Decomposer)
- func (unpacker *Unpacker) UnregisterDecomposer(d api.Decomposer)
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = Options{ FailOnSingleMulti: true, ReadGitVersion: true, UseGitIgnore: true, IndexFiles: false, // contains filtered or unexported fields }
var ErrMultipleCodebases = errors.New("multiple codebases found")
Functions ¶
func CanonicalCodebasePath ¶ added in v0.3.4
CanonicalCodebasePath is core's canonical form of a path relative to the scanned directory, so a path unpack computed compares equal to a parsed id.
func GenerateCodebaseID ¶
GenerateCodebaseID creates a codebase ID from language and relative path in the platform's canonical form (core.CodebaseSourceID): forward slashes, no leading "./", no trailing slash, "." for the root. The same codebase gets the same id here and on the platform, which keys its record by it.
func ParseCodebaseID ¶
ParseCodebaseID parses a codebase ID into its language and canonical path, accepting the forms unpack used to write ("golang:./backend") as well as the canonical one.
Types ¶
type Codebase ¶ added in v0.3.0
type Codebase struct {
Path string
}
Codebase is the DecomposableSubject consumed by the dependencies unpacker. It points at a filesystem path that may contain one or more codebases; the unpacker scans it and runs the matching decomposers.
func (*Codebase) DecomposableType ¶ added in v0.3.0
DecomposableType identifies this subject as a codebase, routing it to the dependencies unpacker through the registry.
type CodebaseInfo ¶
type CodebaseInfo struct {
ID string // canonical, e.g. "golang:services/api" ("golang:." at the root)
Language string // e.g., "golang", "rust"
Path string // canonical path relative to the input directory ("." for the root)
AbsPath string // Absolute filesystem path
}
CodebaseInfo contains information about a discovered codebase.
type DriverConfig ¶ added in v0.3.2
type DriverConfig struct {
Decomposer api.Decomposer
Options any
}
DriverConfig pairs a decomposer with the options to hand it. The decomposer is only a key: any instance of the right type addresses the one the unpacker runs.
type Options ¶
type Options struct {
// FailOnSingleMulti makes Unpacker return an error on calls that return a
// single nodelist but obtain more than one from the configured decomposers.
// This can happen when a directory contains code for more than one language
// or multiple projects in the same directory.
//
// By default this is on as turning it off causes unpacker to behave in a
// non-deterministic way as it can return different data depending on the
// order of the configured decomposers
FailOnSingleMulti bool
// IndexFiles instructs the unpacker to add all files to the resulting
// nodelist after running source decomposers in a directory. This runs
// the file decomposer indexer which will hash all files in the source
// directory.
IndexFiles bool
// ReadGitVersion instructs the unpacker to read the current version from
// the git history and pass it to the decomposers to use as the version
// for the root nodes.
ReadGitVersion bool
// IgnorePatterns are additional paths to ignore, as gitignore-style
// patterns. They apply both when detecting codebases and when
// cataloging files into the SBOM.
IgnorePatterns []string
// UseGitIgnore instructs the unpacker to honor the project's .gitignore
// when cataloging files into the SBOM (see IndexFiles). It does not
// affect codebase detection: a codebase is found even when its lock or
// manifest is gitignored, as Composer libraries routinely do.
UseGitIgnore bool
// CodebaseFilter filters to a specific codebase by ID (e.g., "golang:services/api";
// the older "golang:./services/api" is accepted too).
// If empty, all codebases are included.
CodebaseFilter string
// Networking controls how much network access decomposers are allowed.
// Defaults to NetworkEssential.
Networking api.NetworkLevel
// IncludeDev includes development/test dependencies.
IncludeDev bool
// IncludeBuild includes build tool dependencies.
IncludeBuild bool
// IncludeOptional includes optional dependencies.
IncludeOptional bool
// Platform is the platform dependency data is resolved for, as
// os[/arch] in Go's vocabulary. Empty means the platform unpack runs
// on. See api.DecomposerOptions.Platform.
Platform string
// Drivers carries decomposer-specific options to the decomposers that
// take them. Every extraction receives all of them; a decomposer only
// ever reads its own.
Drivers []DriverConfig
// contains filtered or unexported fields
}
type Unpacker ¶
type Unpacker struct {
Options Options
// contains filtered or unexported fields
}
Unpacker is the main tool to extract dependency data
func NewUnpacker ¶
func NewUnpacker() *Unpacker
func (*Unpacker) CodebaseExtraction ¶ added in v0.4.1
func (unpacker *Unpacker) CodebaseExtraction(ctx context.Context, path string) (*api.Extraction, error)
CodebaseExtraction is ExtractCodebaseWithContext, returning with the nodelist the context its decomposer reads in. It returns nil when the directory holds no codebase.
func (*Unpacker) Extract ¶
func (unpacker *Unpacker) Extract(ctx context.Context, subject api.DecomposableSubject) ([]*sbom.NodeList, error)
Extract reads dependency data from a subject. The dependencies unpacker handles codebase subjects: it scans the subject's path for codebases and runs the configured decomposers over them, returning the resulting nodelists.
func (*Unpacker) ExtractCodebase ¶
ExtractFromCodeBaseWithContext
func (*Unpacker) ExtractCodebaseWithContext ¶
func (unpacker *Unpacker) ExtractCodebaseWithContext(ctx context.Context, path string) (*sbom.NodeList, error)
ExtractCodeBaseWithContext extracts data from a single directory.
func (*Unpacker) Extractions ¶ added in v0.4.1
func (unpacker *Unpacker) Extractions(ctx context.Context, subject api.DecomposableSubject) ([]*api.Extraction, error)
Extractions is Extract, returning with each nodelist the context its decomposer reads in.
func (*Unpacker) ListCodebases ¶
ListCodebases discovers and lists all codebases found in the given path.
func (*Unpacker) RegisterDecomposer ¶
func (unpacker *Unpacker) RegisterDecomposer(d api.Decomposer)
func (*Unpacker) RegisterDecomposerAs ¶ added in v0.3.3
func (unpacker *Unpacker) RegisterDecomposerAs(language string, d api.Decomposer)
RegisterDecomposerAs registers a decomposer under a language name, the one codebase IDs carry (sbt:.), for decomposers that only run when the caller enables them.
func (*Unpacker) UnregisterDecomposer ¶
func (unpacker *Unpacker) UnregisterDecomposer(d api.Decomposer)