lockmode

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package lockmode is the repo-mode analyzer shared by the PyPI and npm plugins: inventory a checkout's lock files, then decide advisories against what they declare.

It is one package rather than two evaluators because, unlike image mode, there is nothing ecosystem-specific left to reason about. Image mode has a site-packages layout and an import graph per language; a lock file has been reduced by internal/lockfile to a list of coordinates and a development flag, and every question repo mode can answer is a question about those two things. What still differs -- how a name is normalized, how a purl is spelled, what the packages are called in prose -- is data, and lives in Config.

The three answers it can give are the whole of repo mode:

named package absent from the lock files   not_present, component_not_present
present but declared development-only      not_in_execute_path
otherwise                                  linked

The gap between that and image mode's table is the import graph, and it is not an oversight. Resolving a specifier needs an installed dependency tree, and materializing one means running the target's build -- arbitrary code from the thing being audited. Repo mode declines, and the "linked" row says out loud that no graph was resolved rather than letting the silence read as a weaker form of the same answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePURL

func ParsePURL(s string) (name, typ string, ok bool)

ParsePURL pulls the name and type out of a package URL, ignoring the version and qualifiers. The namespace is kept, because npm's scope is one: the purl for @babel/core is pkg:npm/%40babel/core, and dropping the namespace would turn it into a different package.

Types

type Analyzer

type Analyzer struct{ Config }

Analyzer implements the three phases of ecosystem.InventorySourceAnalyzer for one ecosystem.

func (Analyzer) Analyze

func (a Analyzer) Analyze(_ context.Context, _ *target.Source, items []ecosystem.WorkItem) ([]ecosystem.Finding, error)

Analyze decides each work item.

func (Analyzer) Detect

func (a Analyzer) Detect(_ context.Context, src *target.Source) (bool, error)

Detect reports whether the checkout carries a lock file of this format.

func (Analyzer) Inventory

func (a Analyzer) Inventory(_ context.Context, src *target.Source, subjects []ecosystem.Subject) ([]ecosystem.Component, error)

Inventory turns the checkout's lock files into components.

func (Analyzer) MethodDevOnly

func (a Analyzer) MethodDevOnly() string

MethodDevOnly is the method name for the development-dependency partition.

func (Analyzer) MethodLockfile

func (a Analyzer) MethodLockfile() string

MethodLockfile is the method name for a conclusion drawn from the lock file contents alone.

type Config

type Config struct {
	// Owner is the plugin this analyzer serves, used to tell whether a subject
	// was addressed to it.
	Owner ecosystem.Plugin

	// Ecosystem is the OSV ecosystem string ("PyPI", "npm").
	Ecosystem string

	// Format selects the lock file readers.
	Format lockfile.Format

	// Prefix names the methods this analyzer reports: "<prefix>-lockfile" and
	// "<prefix>-dev-only".
	Prefix string

	// PURLType is the package-URL type this ecosystem owns ("pypi", "npm"),
	// used to route a --package given as a purl.
	PURLType string

	// Normalize maps a name to the spelling OSV keys it on. PEP 503 for PyPI;
	// identity for npm, which keys on the name verbatim, scope included.
	Normalize func(string) string

	// PURL renders a package URL for one coordinate.
	PURL func(name, version string) string

	Logf func(string, ...any)
}

Config is what one ecosystem has to supply.

Jump to

Keyboard shortcuts

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