retention

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package retention holds the per-ecosystem rules for evicting cached artifacts that have not been accessed for a configured time.

An ecosystem takes part only once its handler registers a Spec with Default, usually from an init function in the handler's own file. Until then configuring retention for it is a validation error, and the global default does not apply to it.

Index

Constants

This section is empty.

Variables

View Source
var Default = NewRegistry()

Default is the registry the handlers register with.

View Source
var KnownKeys = []string{
	"alpine", "cargo", "composer", "conan", "conda", "cran", "deb", "freebsd", "gem",
	"generic", "golang", "helm", "hex", "julia", "maven", "npm", "nuget", "oci", "pub",
	"pypi", "rpm", "swift",
}

KnownKeys lists the ecosystem keys storage.retention.ecosystems accepts. They are the literals the handlers pass when they fetch an artifact. A key outside this list is a typo; a key in it whose handler has not registered yet is not supported by this version.

Functions

func DefaultCanonical

func DefaultCanonical(key string) func(p *purl.PURL) (string, bool)

DefaultCanonical returns a CanonicalPackage for ecosystems that store the package PURL exactly as purl.MakePURLString builds it from the PURL's full name. It accepts a PURL only when building it back that way gives the same package, so for an ecosystem that stores a different form, such as one with a default namespace, it refuses the key instead of producing one that never matches. Such ecosystems need their own CanonicalPackage.

func IsKnown

func IsKnown(key string) bool

IsKnown reports whether key is one of KnownKeys.

Types

type Registry

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

Registry maps ecosystem keys to their specs.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Canonical

func (r *Registry) Canonical(p *purl.PURL) (string, bool)

Canonical returns the policy key for a configured package PURL.

func (*Registry) KeyForDBEcosystem

func (r *Registry) KeyForDBEcosystem(ecosystem string) (string, bool)

KeyForDBEcosystem returns the registered key a packages.ecosystem value belongs to.

func (*Registry) Keys

func (r *Registry) Keys() []string

Keys returns the registered keys in sorted order.

func (*Registry) Lookup

func (r *Registry) Lookup(key string) (Spec, bool)

Lookup returns the spec registered for key.

func (*Registry) Register

func (r *Registry) Register(s Spec)

Register adds s. It panics when the key is not one of KnownKeys, is already registered, or claims a packages.ecosystem value another spec claims, since each of those is a programming error.

func (*Registry) Source added in v0.11.0

func (r *Registry) Source(p *purl.PURL) (string, bool)

Source returns the ecosystem key whose SourcePackage claims p.

type Rules

type Rules struct {
	// Default applies to registered ecosystems without their own rule,
	// except generic, which requires an explicit rule.
	Default time.Duration
	// Ecosystems holds rules keyed by registered ecosystem key.
	Ecosystems map[string]time.Duration
	// Packages holds rules keyed by package PURL, with Go keys lowercased.
	Packages map[string]time.Duration
	// Sources holds package rules not resolved to a stored package PURL
	// yet, by ecosystem key and then by the configured PURL (see
	// Spec.SourcePackage). An ecosystem with any is not swept, since one of
	// them may keep an artifact the sweep would otherwise clear.
	Sources map[string]map[string]time.Duration
}

Rules are resolved retention durations. A duration of zero means an artifact is never evicted by age.

func (Rules) For

func (r Rules) For(key, packagePURL string) time.Duration

For returns the retention for an artifact of the given ecosystem key and stored package PURL: the package rule, else the ecosystem rule, else the default. Generic artifacts require an explicit package or ecosystem rule.

func (Rules) MinPositive

func (r Rules) MinPositive() time.Duration

MinPositive returns the shortest non-zero duration among all rules, or zero when every rule is zero.

func (Rules) Pending added in v0.11.0

func (r Rules) Pending(key string) bool

Pending reports whether the ecosystem key has package rules still to be resolved, and must not be swept.

func (Rules) Resolve added in v0.11.0

func (r Rules) Resolve(key, source string, canonical []string) error

Resolve moves the rule for source in ecosystem key to every stored package PURL it resolved to. A different rule already set for any of them is a conflict, and the source stays pending with none of them set.

type Spec

type Spec struct {
	// Key is the ecosystem's config key, one of KnownKeys.
	Key string

	// ExtraDBEcosystems lists packages.ecosystem values besides the ones
	// derived from Key that belong to this ecosystem.
	ExtraDBEcosystems []string

	// CanonicalPackage turns a package PURL from the config into a
	// policy key, reporting false when the
	// PURL does not belong to this ecosystem. Nil means the ecosystem accepts
	// no package overrides.
	CanonicalPackage func(p *purl.PURL) (string, bool)

	// SourcePackage reports a package PURL that names the package by where
	// its source lives, such as a Swift package by its repository. It has to
	// be resolved through the upstream before it can be compared, so the
	// config keeps it in Rules.Sources until then. Nil means the ecosystem
	// has no such form.
	SourcePackage func(p *purl.PURL) bool
}

Spec describes how one ecosystem takes part in retention.

Jump to

Keyboard shortcuts

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