ecosystem

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ecosystem encapsulates all language-specific behavior needed to detect and apply dependency-vulnerability bumps for a melange package. Exactly one Ecosystem is selected per package (see internal/gobump's language-detection logic); every ecosystem implementation renders melange bump/go-bump pipeline entries in its own grammar, but the pipeline reconciliation logic in internal/gobump treats those entries as opaque strings and is itself language-agnostic.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = choamgithub.ErrNotFound

ErrNotFound reports a confirmed 404 for a manifest file at the ref (see github.ErrNotFound); every other fetch failure is a plain error.

View Source
var ErrUnsupportedRepository = errors.New("unsupported repository URL (only https://github.com/<owner>/<repo> is supported)")

ErrUnsupportedRepository marks a repository URL manifests cannot be fetched from (anything but https://github.com/owner/repo: GitLab, other hosts, the ssh form) - the package is skipped, never reported clean.

Functions

func CheckRepository added in v0.4.0

func CheckRepository(repoURL string) error

CheckRepository reports whether manifests can be fetched from repoURL (ErrUnsupportedRepository otherwise).

func Names

func Names() []string

Names returns every registered language token, sorted, so callers can enumerate known languages (e.g. to check for a per-language annotation) without hardcoding the list themselves.

func Register

func Register(language string, factory func() Ecosystem)

Register registers a factory for the named ecosystem language token.

func WriteTempFiles

func WriteTempFiles(_ context.Context, files map[string][]byte) (dir string, cleanup func(), err error)

WriteTempFiles materializes files into a fresh temporary directory, preserving their relative paths, for ecosystems whose underlying tooling requires a real directory rather than in-memory content (see the Rust ecosystem, whose omnibump analyzer has no checkout-free AnalyzeRemote). The caller must call the returned cleanup func when done. ctx is accepted for consistency with the rest of the per-file path (and so a future cancellation check has somewhere to go); the writes themselves are local disk I/O and not currently cancellable.

Types

type Dep

type Dep struct {
	// Coord is the ecosystem-natural coordinate: Go "module/path", Rust
	// "crate", Java "groupId:artifactId".
	Coord string
	// Name is the OSV query name for this dependency (often equal to Coord).
	Name       string
	Version    string
	GroupID    string // Java only
	ArtifactID string // Java only
	Indirect   bool
}

Dep is a single dependency in a modroot's normalized view.

type Ecosystem

type Ecosystem interface {
	// Name is the melange with.language: token ("go", "rust", "java").
	Name() string

	// ManifestFiles are the modroot-relative filenames to fetch for a
	// modroot: a required file that cannot be fetched fails the file, an
	// optional one may be absent (a confirmed 404 only - any other fetch
	// failure still fails the file).
	ManifestFiles() (required, optional []string)

	// Analyze turns fetched manifest content into a normalized per-modroot
	// dependency view. files is keyed by the basenames from ManifestFiles().
	// Implementations that can't analyze in-memory content (because the
	// underlying tooling requires a real directory) are responsible for
	// materializing files to a temporary directory internally.
	Analyze(ctx context.Context, files map[string][]byte) (*ModuleDeps, error)

	// ScanPackages maps the modroot's dependencies into OSV query inputs. ctx
	// carries this modroot's logger (see internal/logging); current
	// implementations are pure and don't otherwise need it.
	ScanPackages(ctx context.Context, deps *ModuleDeps) []scan.Package

	// FilterBumps merges a modroot's existing declared melange deps with
	// fresh OSV security bumps and returns the desired melange deps for
	// that modroot, rendered in this language's grammar, deduplicated and
	// with no-ops/downgrades/missing entries removed. Fixes it refuses to
	// apply (e.g. a semver-incompatible jump) are returned as held bumps,
	// reported as residuals. ctx bounds any network access an
	// implementation may need and carries this modroot's logger (see
	// internal/logging); current implementations are offline and use ctx
	// only for logging.
	FilterBumps(ctx context.Context, existing []string, bumps []scan.SecurityBump, deps *ModuleDeps) ([]string, []HeldBump)

	// BumpCoords maps each OSV security bump to the coordinate this
	// ecosystem's rendered dep grammar uses for it - the segment before the
	// LAST "@" of a rendered entry. OSV's own package names don't always
	// match: Maven's are "groupId:artifactId" (colon) while the rendered
	// grammar is "groupId@artifactId@version", and OSV names v2+ Go modules
	// without the /vN path suffix go.mod requires. Callers use the keys to
	// recognize which rendered deps fix a flagged vulnerability, and the
	// values to attribute advisory IDs / prior versions to them. ctx
	// carries this modroot's logger; current implementations are pure and
	// don't otherwise need it.
	BumpCoords(ctx context.Context, bumps []scan.SecurityBump, deps *ModuleDeps) map[string]scan.SecurityBump
}

Ecosystem encapsulates all language-specific behavior for dependency vulnerability bumping.

func New

func New(language string) (Ecosystem, error)

New returns the Ecosystem implementation for a melange with.language: token ("go", "rust", "java"). The corresponding language package must have been blank-imported for its factory to be registered.

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher fetches manifest/lockfile content from GitHub repositories without a local checkout, via omnibump's remote fetcher (raw content first, falling back to the authenticated Contents API for private repositories). It is shared across all ecosystems - the transport is language-agnostic.

func NewFetcher

func NewFetcher(httpClient *http.Client) *Fetcher

NewFetcher creates a new fetcher with the provided HTTP client. The httpClient parameter is required and should be obtained from httpclient.NewHTTPClientWithTimeout()

func (*Fetcher) FetchFile

func (f *Fetcher) FetchFile(ctx context.Context, repoURL, ref, path string) ([]byte, error)

FetchFile fetches a single file's content from a git repository at the given ref (a commit or tag) and repository-relative path.

type HeldBump added in v0.4.0

type HeldBump struct {
	Bump   scan.SecurityBump
	Reason string
}

ModuleDeps is a normalized dependency view for one modroot. HeldBump is an advisory fix FilterBumps refused to write, and why.

type ModuleDeps

type ModuleDeps struct {
	// Deps lists every dependency this ecosystem found for the modroot.
	Deps []Dep

	// Raw carries the ecosystem's own internal representation (e.g. a
	// *golang.GoModInfo), opaque to callers outside that ecosystem's package.
	// FilterBumps type-asserts it back; nothing else should depend on its shape.
	Raw any
}

Directories

Path Synopsis
Package golang implements the Go ecosystem.Ecosystem: go.mod/go.sum parsing, v2+ module path normalization, replace-directive resolution, and bump decisioning.
Package golang implements the Go ecosystem.Ecosystem: go.mod/go.sum parsing, v2+ module path normalization, replace-directive resolution, and bump decisioning.
Package java implements the Maven-based Java ecosystem.Ecosystem, backed by omnibump's MavenAnalyzer.
Package java implements the Maven-based Java ecosystem.Ecosystem, backed by omnibump's MavenAnalyzer.
Package rust implements the Rust/Cargo ecosystem.Ecosystem, backed by omnibump's RustAnalyzer.
Package rust implements the Rust/Cargo ecosystem.Ecosystem, backed by omnibump's RustAnalyzer.

Jump to

Keyboard shortcuts

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