curation

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package curation decides which upstream packages and versions a proxy repository may serve. A repository has a mode (off, denylist, allowlist) and a list of rules, each a block or an allow of a package pattern and an optional version pattern. The package pattern is matched against the name the format normalizes to (see NormalizePackage), the version pattern against the version string the format shows clients.

The package is a leaf: the proxy builds its per-request gate from it, the REST API validates rules and explains availability with it.

Index

Constants

View Source
const (
	// ModeOff serves everything the upstream offers (the default); rules are
	// kept but not applied.
	ModeOff = "off"
	// ModeDenylist serves everything except versions a block rule matches.
	ModeDenylist = "denylist"
	// ModeAllowlist serves only versions an allow rule matches (and no block
	// rule blocks).
	ModeAllowlist = "allowlist"
)

Modes of a repository's curation.

View Source
const (
	ActionBlock = "block"
	ActionAllow = "allow"
)

Actions of a rule.

View Source
const (
	MaxPackagePattern = 255
	MaxVersionPattern = 128
	MaxReason         = 500
	// MaxRules bounds the rules of one repository: every request of the
	// repository evaluates them.
	MaxRules = 1000
)

Limits of a rule's fields, in bytes.

View Source
const (
	SourceMinAge   = "min_age"
	SourceCuration = "curation"
)

Sources of a Hold.

View Source
const StampBucket = 5 * time.Minute

StampBucket is the granularity of Gate.Stamp: a version that ages past the minimum age shows up in a gated document at most this late.

Variables

View Source
var ErrInvalidRule = errors.New("invalid curation rule")

ErrInvalidRule wraps every ValidateRule failure.

Functions

func NormalizePackage

func NormalizePackage(format, name string) string

NormalizePackage returns the form of a package name curation rules are matched in: PEP 503 for pypi (lower case, runs of "-", "_" and "." become one "-"), lower case for the registries that compare names case-insensitively (npm, composer, nuget, conda, ansible, conan, swift), lower case with "_" read as "-" for cargo, and the name as the format shows it otherwise (go module path, maven "group:artifact", helm, rubygems, deb, rpm, ...). Rule patterns are put through the same function, so "Django-*" and "django_*" both match "django-rest".

func ValidAction

func ValidAction(action string) bool

ValidAction reports whether action is ActionBlock or ActionAllow.

func ValidMode

func ValidMode(mode string) bool

ValidMode reports whether mode is one of the three modes.

func ValidateRule

func ValidateRule(r *Rule) error

ValidateRule checks the fields a client supplies: the action, a non-empty package pattern, and the length and content of the patterns and the reason.

Types

type Gate

type Gate struct {
	// Set is the repository's curation rules; nil or off decides nothing.
	Set *Set
	// MinAge is the repository's minimum age; 0 turns the age check off.
	MinAge time.Duration
	// Now is the time the minimum age is measured at.
	Now time.Time
	// contains filtered or unexported fields
}

Gate is everything that can keep a version of an upstream package from the clients of a proxy repository: the curation rules and the minimum age. A proxy builds one per request and every format asks it the same question. The zero Gate holds nothing back.

func NewGate

func NewGate(format, mode string, rules []Rule, minAgeHours int, now time.Time) Gate

NewGate builds the gate of a repository of the given format. mode and rules are the repository's curation (rules are ignored when mode is off).

func (Gate) Active

func (g Gate) Active() bool

Active reports whether the gate can hold anything back. A format that has nothing to filter or check when it is inactive keeps its plain path.

func (Gate) AgeActive

func (g Gate) AgeActive() bool

AgeActive reports whether the minimum age is on, i.e. whether the publish time of a version is worth looking up.

func (Gate) Hidden

func (g Gate) Hidden(pkg, version string, published time.Time) (bool, Hold)

Hidden reports whether version of pkg is unavailable and why. published is the publish time the upstream states, zero when it does not: such a version passes the minimum age (the gate only holds back what it can date). The curation rules are asked first; a matching allow rule exempts the version from the minimum age.

func (Gate) Stamp

func (g Gate) Stamp() string

Stamp is the part of a rendered document's validator that stands for the gate: the minimum age with the bucket of Now, and a digest of the curation mode and rules. What a gated document lists changes as versions age and as rules change, with no change in the cached upstream blob, so the validator of the blob alone would revalidate a stale rendering as fresh. "" when the gate is inactive: the validator stays what it was.

type Hold

type Hold struct {
	// Source is SourceMinAge or SourceCuration.
	Source string
	// Detail is the sentence clients and the explain endpoint show.
	Detail string
	// Until is when a minimum-age hold ends (zero otherwise).
	Until time.Time
	// Rule is the curation rule that blocks the version; nil for a minimum-age
	// hold and for a version the allowlist does not list.
	Rule *Rule
}

Hold is the reason a version is unavailable.

type Rule

type Rule struct {
	ID           string
	RepositoryID string
	// Action is ActionBlock or ActionAllow.
	Action string
	// Package is a glob ("*" any run of characters, "?" one character) over the
	// normalized package name.
	Package string
	// Version is a glob over the version string; "" matches every version.
	Version   string
	Reason    string
	CreatedBy string
	CreatedAt time.Time
}

Rule is one curation rule of a repository.

type Set

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

Set is the rules of one repository in one mode, ready to evaluate. The zero value and a Set in ModeOff decide nothing.

func NewSet

func NewSet(format, mode string, rules []Rule) *Set

NewSet builds the Set of a repository of the given format. Rules keep their order: when several rules of one action match, the first is the one reported.

func (*Set) Active

func (s *Set) Active() bool

Active reports whether the Set decides anything (mode is not off).

func (*Set) Evaluate

func (s *Set) Evaluate(pkg, version string) Verdict

Evaluate decides pkg (any form: it is normalized here) at version. In denylist mode a block rule hides the version; in allowlist mode a block rule hides it too, and so does the absence of a matching allow rule. A block rule beats an allow rule. A matching allow rule exempts the version from the minimum-age gate in both modes.

func (*Set) Mode

func (s *Set) Mode() string

Mode is the mode the Set was built for.

type Verdict

type Verdict struct {
	// Hidden: the version is unavailable. Rule is the matching block rule, nil
	// when the allowlist simply does not list the version.
	Hidden bool
	Rule   *Rule
	// ExemptMinAge: an allow rule matched, so the minimum-age gate does not
	// apply to the version.
	ExemptMinAge bool
	// AllowRule is the allow rule that exempted the version.
	AllowRule *Rule
}

Verdict is what a Set decides for one package version.

Jump to

Keyboard shortcuts

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