retention

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 6 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", "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 stored package PURL a configured package PURL stands for, asking the registered specs in key order.

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.

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 the package PURL stored in the cache.
	Packages 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.

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 the
	// package PURL the handler stores in the cache, 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)
}

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