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 ¶
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.
const ( ActionBlock = "block" ActionAllow = "allow" )
Actions of a rule.
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.
const ( SourceMinAge = "min_age" SourceCuration = "curation" )
Sources of a Hold.
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 ¶
var ErrInvalidRule = errors.New("invalid curation rule")
ErrInvalidRule wraps every ValidateRule failure.
Functions ¶
func NormalizePackage ¶
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 ¶
ValidAction reports whether action is ActionBlock or ActionAllow.
func ValidateRule ¶
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 ¶
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 ¶
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 ¶
AgeActive reports whether the minimum age is on, i.e. whether the publish time of a version is worth looking up.
func (Gate) Hidden ¶
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 ¶
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 ¶
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) Evaluate ¶
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.
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.