provider

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: EPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package provider defines the extension point of the permits library. A new dependency ecosystem is added by implementing Scanner (parse a lockfile into dependencies) and Fetcher (retrieve raw license artifacts for a dependency), then registering them in a Registry. The collector depends only on these interfaces and never on a concrete ecosystem, so third parties can add ecosystems without forking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectScanner

type DirectScanner interface {
	Scanner

	ScanDirect(ctx context.Context, path string) ([]model.Dependency, error)
}

DirectScanner is an optional capability: a Scanner that can also restrict results to the project's direct (top-level) dependencies, excluding transitive ones. Providers implement it when the distinction is recoverable (pnpm importers / top-level deps, go.mod non-indirect requires). The collector checks for this interface only when direct-only mode is requested.

type Fetcher

type Fetcher interface {
	Source

	// Fetch returns every license artifact found for dep. Returning an empty slice with a nil
	// error means "fetched, but no license file present".
	Fetch(ctx context.Context, dep model.Dependency) ([]model.LicenseArtifact, error)
}

Fetcher retrieves the raw license artifacts for a single dependency.

type Registry

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

Registry maps an ecosystem to its Scanner and Fetcher.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty Registry.

func (*Registry) FetcherFor

func (r *Registry) FetcherFor(eco model.Ecosystem) (Fetcher, error)

FetcherFor returns the fetcher registered for the given ecosystem.

func (*Registry) Register

func (r *Registry) Register(s Scanner, f Fetcher)

Register adds a provider's Scanner and Fetcher. Either may be nil if a provider only supplies one half, though both are required for that ecosystem to be usable end to end. A later registration for the same ecosystem replaces the previous Fetcher.

func (*Registry) ScannerFor

func (r *Registry) ScannerFor(path string) (Scanner, bool)

ScannerFor returns the first registered scanner whose [Scanner.Detect] accepts path.

type Scanner

type Scanner interface {
	Source

	// Detect reports whether this scanner handles the given file. It may inspect the filename
	// and/or peek at the file contents.
	Detect(path string) bool

	// Scan parses the file into the resolved dependency set.
	Scan(ctx context.Context, path string) ([]model.Dependency, error)
}

Scanner parses a lockfile/manifest into the set of resolved dependencies.

type Source

type Source interface {
	Ecosystem() model.Ecosystem
}

Source identifies which ecosystem a provider component serves.

Directories

Path Synopsis
Package gomod implements the permits provider for the Go module ecosystem: a Scanner for go.sum and a Fetcher that reads raw license text from the local module cache, falling back to the Go module proxy when the module is not cached.
Package gomod implements the permits provider for the Go module ecosystem: a Scanner for go.sum and a Fetcher that reads raw license text from the local module cache, falling back to the Go module proxy when the module is not cached.
Package npm implements the permits provider for the npm ecosystem: a Scanner for pnpm-lock.yaml (lockfileVersion 5, 6 and 9) and a Fetcher that resolves raw license text from the package tarball published to the npm registry.
Package npm implements the permits provider for the npm ecosystem: a Scanner for pnpm-lock.yaml (lockfileVersion 5, 6 and 9) and a Fetcher that resolves raw license text from the package tarball published to the npm registry.

Jump to

Keyboard shortcuts

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