plugin

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 26 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 plugin is the one place a package format is plugged into the server. A format is a Format value: its name, the constructor of its hosted protocol handler, the analysis hooks (dependency parsing, licences, vulnerability scanning, SBOM), its client setup snippets, its proxy and group behaviour and its metadata lifecycle. Register records the value in every library registry (internal/proxy, internal/group, internal/pkgdeps, ...) and in this package's own, which the server iterates to mount routes and wire the workers. internal/formats holds one registration per format.

The static, data-only policy of a format (which repositories it supports, where it is mounted, how it is signed, its package URL type) stays in internal/repotype.Spec; the plugin holds the behaviour. A test in internal/formats checks that the two agree.

Libraries never import this package: it imports them and pushes hooks into their registries, so there is no cycle and no init-time registration. Nothing is registered until internal/formats.Register runs.

Index

Constants

This section is empty.

Variables

View Source
var ErrManyCatchAlls = errors.New("more than one format claims the shared PUT catch-all")

ErrManyCatchAlls is returned when more than one format claims every path of the shared PUT route.

View Source
var ErrNoHostedHandler = errors.New("plugin: format has no hosted handler constructor")

ErrNoHostedHandler is returned by a Definition that has no NewHosted.

View Source
var FirstHitGroup = Group{Enabled: true} //nolint:gochecknoglobals // immutable value, named so a registration states the choice

FirstHitGroup is a group of the format that answers with the first member that has the file and merges nothing (docker, raw).

View Source
var NoAnalysis = Analysis{} //nolint:gochecknoglobals // immutable zero value, named so a registration states the choice

NoAnalysis is the analysis of a format that has none.

View Source
var NoGroup = Group{} //nolint:gochecknoglobals // immutable zero value, named so a registration states the choice

NoGroup is the group behaviour of a format that has no group repositories.

View Source
var NoProxy = Proxy{} //nolint:gochecknoglobals // immutable zero value, named so a registration states the choice

NoProxy is the proxy behaviour of a format that has no proxy repositories.

View Source
var NoStorage = storage.Storage{} //nolint:gochecknoglobals // immutable zero value, named so a registration states the choice

NoStorage is the storage of a format with no descriptor: the generic package engines reject it. Only docker has it, because it keeps dedicated tables that the engines handle explicitly.

Functions

func BuildHosted

func BuildHosted(d *Deps) (map[string]Hosted, error)

BuildHosted builds the hosted handler of every registered format.

func MountIsolated

func MountIsolated(authed chi.Router, hosted map[string]Hosted, dispatch func(http.Handler) http.Handler)

MountIsolated registers the formats whose wildcard routes would shadow others on /repos/{name}, each on a prefix of its own, /repos/<format>/{name}.

func MountOCI

func MountOCI(authed chi.Router, hosted map[string]Hosted, dispatch func(http.Handler) http.Handler)

MountOCI registers the registry protocol (/v2/...) behind its dispatcher middleware: proxy and group repositories are served there, hosted ones by the format's handler.

func MountShared

func MountShared(authed chi.Router, hosted map[string]Hosted, dispatch func(http.Handler) http.Handler) error

MountShared registers the formats served under /repos/{name} on the single subrouter, behind the dispatcher middleware, and dispatches the shared PUT catch-all among the formats that claim it.

func REST

func REST[T any](d *Deps, format string) (T, bool)

REST returns the REST upload handler of format as the narrow interface T the format's registration needs. It reports false when the server built none or it does not implement T.

func ReadRouters

func ReadRouters(hosted map[string]Hosted) map[string]http.Handler

ReadRouters returns an in-memory router per format with the hosted handler's read routes registered. Proxy and group repositories are served by the dispatcher in front of the per-format routes; hosted repositories fall through to them, and groups read their hosted members through these routers.

func Register

func Register(f Format)

Register records f in every registry. It panics when f is invalid or its name is already registered: both are programming errors that must fail at startup.

func RegisterAPIRoutes

func RegisterAPIRoutes(authed chi.Router, hosted map[string]Hosted)

RegisterAPIRoutes registers the REST upload endpoints of the formats that have them on the authenticated API router. Call it after MountIsolated: a route registered on a path an isolated mount also serves would otherwise be overridden by it.

func RegisterPublicRoutes

func RegisterPublicRoutes(router chi.Router, hosted map[string]Hosted)

RegisterPublicRoutes registers the routes that need no authentication.

func SetPublisher

func SetPublisher(hosted map[string]Hosted, p webhook.Publisher)

SetPublisher gives every hosted handler the publisher it announces uploads and deletions through.

Types

type APIRouted

type APIRouted interface {
	RegisterAPIRoutes(r chi.Router)
}

APIRouted formats register routes on the authenticated API router (REST upload endpoints under /api/v1/repositories/{name}).

type Analysis

type Analysis struct {
	// Manifest says which files of a package archive hold its manifest.
	Manifest *manifest.Rule
	// Deps parses a package's dependencies from those files.
	Deps *pkgdeps.Hooks
	// License looks a package's licence up in its manifest.
	License *licensemeta.Hooks
	// Vuln is the Package URL and the lockfile the vulnerability scanner uses.
	Vuln *vuln.Hooks
	// SBOM describes how the package is named in a generated SBOM.
	SBOM *sbom.Hooks
}

Analysis lists the supply-chain hooks of a format; a nil field is a stage the format has no support for (its packages are libraries with no parsed dependencies, no licence lookup, and so on).

type Definition

type Definition struct {
	// ID is the format name (Format.Name).
	ID string
	// NewHosted builds the hosted handler (Format.Hosted).
	NewHosted func(*Deps) (Hosted, error)
	// Supply is the supply-chain analysis (Format.Analysis).
	Supply Analysis
	// Snippets is the client setup builder (Format.ClientSetup).
	Snippets clientsetup.Builder
	// Mirror is the proxy behaviour (Format.Proxy).
	Mirror Proxy
	// Merge is the group behaviour (Format.Group).
	Merge Group
	// Meta is the metadata lifecycle (Format.Lifecycle).
	Meta lifecycle.Hooks
	// Store is the storage descriptor (Format.Storage).
	Store storage.Storage
}

Definition is the table form of a Format: the registration of a format that needs no behaviour of its own beyond the values below. Every field is required; a behaviour the format does not have is its explicit zero value (NoProxy, NoGroup, NoAnalysis, lifecycle.None).

func (Definition) Analysis

func (d Definition) Analysis() Analysis

Analysis implements Format.

func (Definition) ClientSetup

func (d Definition) ClientSetup() clientsetup.Builder

ClientSetup implements Format.

func (Definition) Group

func (d Definition) Group() Group

Group implements Format.

func (Definition) Hosted

func (d Definition) Hosted(deps *Deps) (Hosted, error)

Hosted implements Format.

func (Definition) Lifecycle

func (d Definition) Lifecycle() lifecycle.Hooks

Lifecycle implements Format.

func (Definition) Name

func (d Definition) Name() string

Name implements Format.

func (Definition) Proxy

func (d Definition) Proxy() Proxy

Proxy implements Format.

func (Definition) Storage

func (d Definition) Storage() storage.Storage

Storage implements Format.

type Deps

type Deps struct {
	Log *logger.Logger
	DB  *database.PostgresDB

	// Served is the blob store downloads are read from (with presigned
	// redirects); Blobs is the one writers use.
	Served storage.BlobStore
	Blobs  storage.BlobStore

	// BaseURL is the BASE_URL override of the origin of the URLs the handlers
	// hand to clients; empty derives it from each request.
	BaseURL string
	Metrics *metrics.Registry
	// HMACKey signs the Terraform download tickets.
	HMACKey []byte

	// DockerUploadDir is the host directory docker upload chunks are kept in when
	// Blobs cannot hold them itself (the oci backend).
	DockerUploadDir string
	// DockerAuthorizer checks read access to a cross-repository mount source.
	DockerAuthorizer formatdocker.Authorizer

	// APKKeys and NixKeys provide the signing keys of apk and nix repositories.
	APKKeys formatapk.KeyProvider
	NixKeys formatnix.KeyProvider
	// GPG resolves the signer of Terraform repositories; nil when none.
	GPG gpg.Resolver
	// Proxy serves the Terraform tickets of proxy repositories; nil when the
	// process has no proxy service.
	Proxy *proxy.Service

	// Workers are the metadata workers this process runs. Handlers that notify
	// one on upload take it from here.
	Workers *lifecycle.Workers

	// REST are the REST upload handlers of internal/api, by format name. They
	// live in api, which a format registration cannot import, so the server
	// builds them and a format takes its own with REST.
	REST map[string]any

	// CountUploads wraps a handler that serves one format on a route shared with
	// others, counting its uploads in openartifact_uploads_total.
	CountUploads func(format string, next http.HandlerFunc) http.HandlerFunc
}

Deps are the server services a format's hosted handler is built from. The server (cmd/server) fills them once at startup; a format takes what it needs and ignores the rest. A field the process has no service for is left zero: a nil interface or pointer means the service is absent, and the format skips the option that needs it.

type Format

type Format interface {
	// Name is the format's name: the repotype.Spec name, the repository
	// format column and the key of every registry.
	Name() string

	// Hosted builds the protocol handler of the format's hosted repositories
	// from the server's services.
	Hosted(*Deps) (Hosted, error)

	// Analysis is what the format contributes to the supply-chain analysis.
	Analysis() Analysis

	// ClientSetup is the format's snippet builder (the "Use this repository"
	// commands of the UI).
	ClientSetup() clientsetup.Builder

	// Proxy is the format's proxy-repository behaviour; NoProxy when the
	// format has no proxy repositories.
	Proxy() Proxy

	// Group is the format's group-repository behaviour; NoGroup when the
	// format has no group repositories.
	Group() Group

	// Lifecycle is what happens to the format's generated metadata when rows
	// change outside the handler.
	Lifecycle() lifecycle.Hooks

	// Storage is how the generic package engines (trash, cleanup, federation,
	// promotion, backup, recovery, artifact detail) treat the format's rows in
	// the generic package tables. Register records it in internal/format/storage;
	// NoStorage (docker, which keeps dedicated tables) records nothing.
	Storage() storage.Storage
}

Format is one package format. Every method is required: a format states what it does not have with an explicit zero value (NoProxy, NoGroup, NoAnalysis, lifecycle.None), never with nil, so a missing behaviour is a decision visible in its registration and not an omission.

func All

func All() []Format

All returns the registered formats in registration order. The order is meaningful: formats on the shared /repos/{name} subrouter register their routes in it, and where two of them register a route of the same shape the later one serves it (see internal/formats).

type Group

type Group struct {
	// Enabled is true when the format has group repositories; it must equal
	// repotype.Spec.Group.
	Enabled bool
	// Hooks are the format's merge hooks; nil is a plain first-hit group.
	Hooks *group.Hooks
}

Group is a format's group-repository behaviour.

func GroupOf

func GroupOf(h *group.Hooks) Group

GroupOf is the group behaviour with the given merge hooks.

type Guarded

type Guarded interface {
	Guard(next http.Handler) http.Handler
}

Guarded formats claim requests of the shared /repos/{name} subrouter before the routes: paths that would clash with the routes of other formats are answered for repositories of the format only and passed on otherwise.

type Hosted

type Hosted interface {
	// RegisterRepoRoutes registers the format's routes below a repository:
	// relative to /repos/{name}, /repos/<format>/{name}, or the root of the
	// in-memory router groups read hosted members through.
	RegisterRepoRoutes(r chi.Router)
	// SetPublisher sets the webhook publisher the handler announces
	// artifact.uploaded and artifact.deleted through.
	SetPublisher(p webhook.Publisher)
}

Hosted is the protocol handler of a format's hosted repositories.

type Proxy

type Proxy struct {
	// Enabled is true when the format has proxy repositories; it must equal
	// repotype.Spec.Proxy.
	Enabled bool
	// Hooks are the proxy pipeline hooks of the format.
	Hooks proxy.Hooks
}

Proxy is a format's proxy-repository behaviour.

func ProxyOf

func ProxyOf(h proxy.Hooks) Proxy

ProxyOf is the proxy behaviour with the given hooks.

type PublicRouted

type PublicRouted interface {
	RegisterPublicRoutes(r chi.Router)
}

PublicRouted formats register routes on the bare router, outside authentication (a signed URL is the credential).

type PutClaim

type PutClaim struct {
	// Claims reports whether the PUT of tail (the path below the repository) is
	// this format's upload. nil claims every path no other claim took; at most
	// one claim may be the catch-all.
	Claims func(tail string) bool
	// Serve handles the upload.
	Serve http.HandlerFunc
}

PutClaim is a format's claim on the shared PUT /repos/{name}/* route.

type PutRouted

type PutRouted interface {
	PutClaim() PutClaim
}

PutRouted formats take part in the shared PUT /repos/{name}/* dispatch: several formats upload with a PUT to a path no route can tell apart.

type WriteRouted

type WriteRouted interface {
	RegisterWriteRoutes(r chi.Router)
}

WriteRouted formats register write routes on the live shared mount only, not on the read-only view groups read hosted members through (npm publish).

Jump to

Keyboard shortcuts

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