Documentation
¶
Overview ¶
Package source defines the Source contract (architecture.md section 3.3) and a Registry of Source implementations by kind. Implementations live in subpackages, one per kind (internal/source/pypi, ...).
Sources are dumb: they list the raw upstream versions and an opaque fetch state. Diffing, version parsing and policy belong to the core.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTarget is wrapped by Validate errors. ErrInvalidTarget = errors.New("source: invalid target") // ErrUnknownKind is returned when no source is registered for a kind. ErrUnknownKind = errors.New("source: unknown kind") // ErrDuplicateKind is returned when a kind is registered twice. ErrDuplicateKind = errors.New("source: kind already registered") )
Functions ¶
This section is empty.
Types ¶
type Canonicalizer ¶
Canonicalizer is an optional interface a Source implements when one upstream object can be spelled several ways in its coordinates ("Requests" and "requests" on PyPI). Canonical returns the one spelling the core stores and uses as the coalescing key, so that every spelling shares one target and one fetch. See ADR 0021, which amends ADR 0006.
Canonical is called only on a target that Validate accepted. It does no I/O, keeps the Kind, is idempotent (Canonical of its result returns the result unchanged) and its result passes Validate. It must not mutate t. A Source whose coordinates are already canonical as written does not implement it.
type FetchState ¶
type FetchState struct {
ETag string `json:"etag,omitempty"`
LastModified string `json:"last_modified,omitempty"`
Cursor string `json:"cursor,omitempty"`
}
FetchState is the conditional-request state kept per target (target.fetch_state_json). Its content is opaque to the core: only the source that produced it interprets it. The zero value means "no state".
func (FetchState) IsZero ¶
func (s FetchState) IsZero() bool
IsZero reports whether s carries no state.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps a name to its Source. The name of a built-in is its kind; a named instance (RegisterAs) has its own name and a Source of another kind, so that one instance can watch the same kind of registry at several URLs. It is an explicit value, not a package global: the composition root builds one and passes it down.
func (*Registry) Get ¶
Get returns the Source registered under name (a kind, or the name of an instance), or an error wrapping ErrUnknownKind.
func (*Registry) KindOf ¶
KindOf returns the base kind of the source registered under name (the kind events, purls, schemes and policy use), or name when none is.
func (*Registry) Kinds ¶
Kinds returns the distinct kinds of the registered sources, sorted: the values of an event's data.source, whatever the instances are called.
func (*Registry) Names ¶
Names returns every registered name, kinds and instances, sorted. A watch names one of them in its source.
func (*Registry) Register ¶
Register adds src under src.Kind(). It fails with ErrDuplicateKind if the kind is taken, and rejects a nil source or an empty kind.
func (*Registry) RegisterAs ¶
RegisterAs adds src under name, a named instance of src.Kind(): its targets are stored with name as their kind, and src still receives and reports the base kind. It fails with ErrDuplicateKind if the name is taken, and rejects a nil source, an empty name or an empty kind.
type Result ¶
type Result struct {
// Versions are the raw upstream versions, newest first if known.
Versions []Version
// State is the state to pass to the next List call for the same target.
State FetchState
// NotModified is true when the upstream confirmed nothing changed.
NotModified bool
}
Result is the outcome of a List call.
type Source ¶
type Source interface {
// Kind is the registry key: "pypi", "npm", "github-release", "oci", ...
Kind() string
// Validate checks the target's coordinates at create time. It does no
// network I/O and returns an error wrapping ErrInvalidTarget.
Validate(target Target) error
// List fetches the upstream versions. When s lets the source prove that
// nothing changed (ETag, Last-Modified, cursor) it returns a Result with
// NotModified set and no Versions.
List(ctx context.Context, t Target, s FetchState) (Result, error)
}
Source detects releases on one kind of upstream.
Implementations that do HTTP receive their *http.Client through their constructor (injection) and never use http.DefaultClient, so the netguard client or a test guard can be substituted. List wraps context errors with %w. See ADR 0006.
type Target ¶
Target identifies one upstream object (target.kind and target.coordinates_json in architecture.md section 5). Coordinates are source specific, for example {"name": "requests"} for pypi.
type Version ¶
type Version struct {
Raw string // "v2.3.0-rc.1"
PublishedAt time.Time // zero if upstream does not say
Prerelease *bool // upstream flag if available; nil if unknown
Yanked bool // yanked, unpublished or withdrawn upstream; deprecation goes in Metadata
URL string // release page
NotesURL string // release notes
Metadata map[string]any // digest, tarball url, dist-tags, ...
}
Version is one raw upstream version.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package crates is the Source for crates.io.
|
Package crates is the Source for crates.io. |
|
Package githubrelease is the "github-release" Source: it lists the releases of a GitHub (or GitHub Enterprise) repository.
|
Package githubrelease is the "github-release" Source: it lists the releases of a GitHub (or GitHub Enterprise) repository. |
|
Package githubtag is the "github-tag" Source: it lists the git tags of a GitHub (or GitHub Enterprise) repository that does not publish releases.
|
Package githubtag is the "github-tag" Source: it lists the git tags of a GitHub (or GitHub Enterprise) repository that does not publish releases. |
|
Package gitlabrelease is the "gitlab-release" Source: it lists the releases of a project on gitlab.com or on a self-managed GitLab instance.
|
Package gitlabrelease is the "gitlab-release" Source: it lists the releases of a project on gitlab.com or on a self-managed GitLab instance. |
|
internal
|
|
|
apiclient
Package apiclient holds the token and redirect plumbing shared by the sources that call an authenticated HTTP API (github-release, github-tag, gitlab-release): the redacting token type, token providers, the test for where credentials may travel, the redirect guard that never carries credentials to another host or to plain http, and the fetch helper that adds the 404 and 401 hints.
|
Package apiclient holds the token and redirect plumbing shared by the sources that call an authenticated HTTP API (github-release, github-tag, gitlab-release): the redacting token type, token providers, the test for where credentials may travel, the redirect guard that never carries credentials to another host or to plain http, and the fetch helper that adds the 404 and 401 hints. |
|
ghapi
Package ghapi holds the GitHub-specific plumbing shared by the GitHub-API based sources (github-release, github-tag): the default base URL, the "owner/name" coordinate parser and the authenticated GET helper.
|
Package ghapi holds the GitHub-specific plumbing shared by the GitHub-API based sources (github-release, github-tag): the default base URL, the "owner/name" coordinate parser and the authenticated GET helper. |
|
Package npm is the Source for the npm registry.
|
Package npm is the Source for the npm registry. |
|
Package pypi is the Source for PyPI releases (architecture.md section 3.3).
|
Package pypi is the Source for PyPI releases (architecture.md section 3.3). |
|
Package registryauth adds the credential of a private registry or mirror (PRD F16) to every request of a source's HTTP client, so the sources themselves stay credential-free.
|
Package registryauth adds the credential of a private registry or mirror (PRD F16) to every request of a source's HTTP client, so the sources themselves stay credential-free. |
|
Package sourcetest is the contract test suite every source.Source must pass.
|
Package sourcetest is the contract test suite every source.Source must pass. |