Documentation
¶
Overview ¶
Package enrichment provides a unified interface for fetching package metadata from external sources (ecosyste.ms API, direct registry queries, deps.dev).
Index ¶
- func IsOutdated(current, latest string) bool
- type Advisory
- type Client
- type DependentPackage
- type DepsDevClient
- type EcosystemsClient
- func (c *EcosystemsClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
- func (c *EcosystemsClient) GetDependentsByRepositoryURL(ctx context.Context, repositoryURL string, ...) ([]RepositoryDependents, error)
- func (c *EcosystemsClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
- func (c *EcosystemsClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
- type HybridClient
- type LicenseCategory
- type Maintainer
- type Option
- type PackageInfo
- type RegistriesClient
- func (c *RegistriesClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
- func (c *RegistriesClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
- func (c *RegistriesClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
- type RepositoryDependents
- type VersionInfo
- type VulnInfo
- type VulnerabilityClient
- type VulnerabilityOption
- type VulnerabilityQuery
- type VulnerabilityResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsOutdated ¶ added in v0.5.0
IsOutdated reports whether current is older than latest.
Types ¶
type Advisory ¶ added in v0.2.1
type Advisory struct {
Title string
Severity string // e.g. "critical", "high", "medium", "low"
CVSSScore float32
URL string
Identifiers []string // CVE IDs and other identifiers
}
Advisory is a security advisory affecting a package.
type Client ¶
type Client interface {
// BulkLookup fetches metadata for multiple packages by PURL.
// Returns a map of PURL to PackageInfo. Missing packages are omitted.
BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
// GetVersions fetches all versions for a package.
// The purl should be a package PURL without version (pkg:npm/lodash).
GetVersions(ctx context.Context, purl string) ([]VersionInfo, error)
// GetVersion fetches metadata for a specific version.
// The purl must include a version (pkg:npm/lodash@4.17.21).
GetVersion(ctx context.Context, purl string) (*VersionInfo, error)
}
Client fetches package metadata from external sources.
func NewClient ¶
NewClient creates an enrichment client based on configuration.
By default, uses a hybrid approach:
- PURLs with repository_url qualifier -> direct registry query
- Other PURLs -> ecosyste.ms API
To skip ecosyste.ms and query all registries directly:
- Set GIT_PKGS_DIRECT=1 environment variable, or
- Set git config: git config --global pkgs.direct true
type DependentPackage ¶ added in v0.6.0
type DependentPackage struct {
Ecosystem string
Name string
PURL string
Repository string
RegistryURL string
LatestVersion string
Downloads int
DependentReposCount int
}
DependentPackage contains metadata for one package that depends on another.
type DepsDevClient ¶
type DepsDevClient struct {
// contains filtered or unexported fields
}
DepsDevClient queries the deps.dev v3 REST API.
func NewDepsDevClient ¶
func NewDepsDevClient() *DepsDevClient
NewDepsDevClient creates a client for the deps.dev API.
func (*DepsDevClient) BulkLookup ¶
func (c *DepsDevClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
func (*DepsDevClient) GetVersion ¶
func (c *DepsDevClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
func (*DepsDevClient) GetVersions ¶
func (c *DepsDevClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
type EcosystemsClient ¶
type EcosystemsClient struct {
// contains filtered or unexported fields
}
EcosystemsClient wraps the ecosyste.ms API client.
func NewEcosystemsClient ¶
func NewEcosystemsClient() (*EcosystemsClient, error)
NewEcosystemsClient creates a client that uses the ecosyste.ms API.
func (*EcosystemsClient) BulkLookup ¶
func (c *EcosystemsClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
func (*EcosystemsClient) GetDependentsByRepositoryURL ¶ added in v0.6.0
func (c *EcosystemsClient) GetDependentsByRepositoryURL(ctx context.Context, repositoryURL string, maxPackages, maxDependentsPerPackage int) ([]RepositoryDependents, error)
GetDependentsByRepositoryURL finds packages published from repositoryURL and fetches dependent packages for each of them.
func (*EcosystemsClient) GetVersion ¶
func (c *EcosystemsClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
func (*EcosystemsClient) GetVersions ¶
func (c *EcosystemsClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
type HybridClient ¶
type HybridClient struct {
// contains filtered or unexported fields
}
HybridClient routes requests based on PURL qualifiers. PURLs with repository_url go to registries, others go to ecosyste.ms.
func NewHybridClient ¶
func NewHybridClient() (*HybridClient, error)
NewHybridClient creates a client that routes based on PURL qualifiers.
func (*HybridClient) BulkLookup ¶
func (c *HybridClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
func (*HybridClient) GetVersion ¶
func (c *HybridClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
func (*HybridClient) GetVersions ¶
func (c *HybridClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
type LicenseCategory ¶ added in v0.5.0
type LicenseCategory string
LicenseCategory describes the broad policy category for a license expression.
const ( // LicenseCategoryPermissive is used when every license in the expression is permissive. LicenseCategoryPermissive LicenseCategory = "permissive" // LicenseCategoryCopyleft is used when the expression contains a copyleft license. LicenseCategoryCopyleft LicenseCategory = "copyleft" // LicenseCategoryUnknown is used when the expression cannot be classified. LicenseCategoryUnknown LicenseCategory = "unknown" )
func CategorizeLicense ¶ added in v0.5.0
func CategorizeLicense(license string) LicenseCategory
CategorizeLicense classifies a license expression as permissive, copyleft, or unknown. This is intentionally conservative: any copyleft license in an expression makes the whole expression copyleft, including OR expressions.
type Maintainer ¶ added in v0.3.0
Maintainer is a person or account that maintains a package on its registry.
type Option ¶
type Option func(*options)
Option configures an enrichment client.
func WithAPIKey ¶ added in v0.4.0
WithAPIKey sets the bearer token sent on ecosyste.ms API requests. Ignored by the direct registries client.
func WithBatchSize ¶ added in v0.4.0
WithBatchSize sets the per-request batch size for ecosyste.ms bulk lookups. Values <= 0 or above the upstream maximum fall back to the upstream default. Ignored by the direct registries client.
func WithFrom ¶ added in v0.4.0
WithFrom sets the From header (email address) for ecosyste.ms API requests. Identifying the client moves it out of the shared rate-limit pool, which reduces stream-level rejections. Ignored by the direct registries client.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header for API requests.
type PackageInfo ¶
type PackageInfo struct {
Ecosystem string
Name string
LatestVersion string
License string
Description string
Homepage string
Repository string
RegistryURL string
ChangelogFilename string
Source string // "ecosystems", "registries", or "depsdev"
// Popularity and usage (ecosyste.ms only)
Downloads int
DownloadsPeriod string // e.g. "last-month"
DependentPackagesCount int
DependentReposCount int
// Security advisories (ecosyste.ms only)
Advisories []Advisory
// Funding and maintainers (ecosyste.ms only)
FundingLinks []string
Maintainers []Maintainer
}
PackageInfo contains metadata about a package.
type RegistriesClient ¶
type RegistriesClient struct {
// contains filtered or unexported fields
}
RegistriesClient queries package registries directly.
func NewRegistriesClient ¶
func NewRegistriesClient() *RegistriesClient
NewRegistriesClient creates a client that queries registries directly.
func (*RegistriesClient) BulkLookup ¶
func (c *RegistriesClient) BulkLookup(ctx context.Context, purls []string) (map[string]*PackageInfo, error)
func (*RegistriesClient) GetVersion ¶
func (c *RegistriesClient) GetVersion(ctx context.Context, purlStr string) (*VersionInfo, error)
func (*RegistriesClient) GetVersions ¶
func (c *RegistriesClient) GetVersions(ctx context.Context, purlStr string) ([]VersionInfo, error)
type RepositoryDependents ¶ added in v0.6.0
type RepositoryDependents struct {
PackageName string
Ecosystem string
PURL string
Dependents []DependentPackage
}
RepositoryDependents groups dependent packages by one package published from a source repository.
type VersionInfo ¶
type VersionInfo struct {
Number string
PublishedAt time.Time
Integrity string
License string
Status string // registry-defined status, such as "yanked", "deprecated", or "retracted"
Yanked bool // true when Status is "yanked"; retained for compatibility
Metadata map[string]any // registry-specific version metadata
}
VersionInfo contains metadata about a specific version.
type VulnInfo ¶ added in v0.5.0
type VulnInfo struct {
ID string
Summary string
Details string
Severity string
CVSSScore float64
CVSSVersion string
CVSSVector string
FixedVersion string
References []string
Aliases []string
Source string
}
VulnInfo contains the vulnerability fields most consumers need for display and policy checks.
type VulnerabilityClient ¶ added in v0.5.0
type VulnerabilityClient struct {
// contains filtered or unexported fields
}
VulnerabilityClient checks package vulnerabilities using a configured source.
func NewVulnerabilityClient ¶ added in v0.5.0
func NewVulnerabilityClient(opts ...VulnerabilityOption) *VulnerabilityClient
NewVulnerabilityClient creates a client backed by OSV unless another source is provided.
func (*VulnerabilityClient) Check ¶ added in v0.5.0
func (c *VulnerabilityClient) Check(ctx context.Context, ecosystem, name, version string) ([]VulnInfo, error)
Check checks one package version for known vulnerabilities.
func (*VulnerabilityClient) CheckBatch ¶ added in v0.5.0
func (c *VulnerabilityClient) CheckBatch(ctx context.Context, queries []VulnerabilityQuery) ([]VulnerabilityResult, error)
CheckBatch checks multiple package versions for known vulnerabilities.
type VulnerabilityOption ¶ added in v0.5.0
type VulnerabilityOption func(*vulnerabilityOptions)
VulnerabilityOption configures a VulnerabilityClient.
func WithVulnerabilitySource ¶ added in v0.5.0
func WithVulnerabilitySource(source vulns.Source) VulnerabilityOption
WithVulnerabilitySource sets the vulnerability data source.
func WithVulnerabilityUserAgent ¶ added in v0.5.0
func WithVulnerabilityUserAgent(userAgent string) VulnerabilityOption
WithVulnerabilityUserAgent sets the User-Agent for the default OSV source.
type VulnerabilityQuery ¶ added in v0.5.0
VulnerabilityQuery identifies a package version to check for vulnerabilities.
type VulnerabilityResult ¶ added in v0.5.0
type VulnerabilityResult struct {
Query VulnerabilityQuery
Vulnerabilities []VulnInfo
}
VulnerabilityResult contains the vulnerabilities found for a query.
func BulkCheckVulnerabilities ¶ added in v0.5.0
func BulkCheckVulnerabilities(ctx context.Context, queries []VulnerabilityQuery) ([]VulnerabilityResult, error)
BulkCheckVulnerabilities checks multiple package versions using the default OSV-backed client.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package endoflife provides a client for the endoflife.date API.
|
Package endoflife provides a client for the endoflife.date API. |
|
Package scorecard provides a client for the OpenSSF Scorecard API.
|
Package scorecard provides a client for the OpenSSF Scorecard API. |