Documentation
¶
Overview ¶
Package group serves group repositories: a read-only view over an ordered list of hosted and proxy member repositories of the same format. A request is answered by the first member that has the file; Maven metadata is merged across all members.
Index ¶
- Variables
- func Register(format string, h Hooks)
- type Backend
- type Handler
- func (h *Handler) Serve(w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, ...)
- func (h *Handler) ServeOCI(w http.ResponseWriter, r *http.Request, grp *models.Repository, ...)
- func (h *Handler) SetBaseURL(baseURL string)
- func (h *Handler) WithApkKeys(keys formatapk.KeyProvider) *Handler
- func (h *Handler) WithMetadata(blobs storage.BlobStore, gen MetadataGenerator) *Handler
- func (h *Handler) WithNixKeys(keys formatnix.KeyProvider) *Handler
- type HandlerStore
- type Hooks
- type MetadataGenerator
- type PkgRef
Constants ¶
This section is empty.
Variables ¶
var AnsibleHooks = Hooks{ ServeMerged: (*Handler).serveAnsible, PackageRef: ansibleRef, }
AnsibleHooks is the ansible group: merged Galaxy API documents, collection downloads first-hit.
var ApkHooks = Hooks{ ServeMerged: func( h *Handler, w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, readable []*models.Repository, be Backend, ) bool { h.serveApk(w, r, grp, readable, relPath, be) return true }, }
ApkHooks is the apk group: merged signed indexes from the group's own generated rows, files from the member the index lists them for. No hosted-wins: the index is resolved member by member.
var CRANHooks = Hooks{ ServeMerged: (*Handler).serveCRAN, PackageRef: cranRef, }
CRANHooks is the cran group: merged PACKAGES indexes, package files first-hit.
var CargoHooks = Hooks{ ServeMerged: (*Handler).serveCargo, PackageRef: cargoRef, }
CargoHooks is the cargo group: merged sparse index entries, crate downloads first-hit.
var ComposerHooks = Hooks{ ServeMerged: (*Handler).serveComposer, PackageRef: composerRef, }
ComposerHooks is the composer group: merged p2 documents, dists first-hit.
var ConanHooks = Hooks{ ServeMerged: (*Handler).serveConan, PackageRef: conanRef, }
ConanHooks is the conan group: merged search and version lists, files first-hit.
var CondaHooks = Hooks{ ServeMerged: func( h *Handler, w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, readable []*models.Repository, be Backend, ) bool { return h.serveConda(w, r, grp, readable, relPath, be) }, PackageRef: condaRef, }
CondaHooks is the conda group: merged repodata, package files first-hit.
var DebHooks = debFormat.hooks() //nolint:gochecknoglobals // immutable format hook value
DebHooks is the deb group: merged Release and Packages, files from the member the merged index lists them for.
var ErrDistNotFound = errors.New("group: distribution not found in any member")
ErrDistNotFound is returned by MetadataGenerator.Generate when no member of a Debian group has the requested distribution, or of a pacman group the requested architecture.
var ErrNoRepodata = errors.New("no merged repodata")
ErrNoRepodata is returned by MetadataGenerator.Generate for an rpm group whose proxy members have no repodata/repomd.xml at their upstream root and which has nothing else to list, typically because the upstream is a tree of repositories rather than one repository. The error message names the members.
var GoHooks = Hooks{ ServeMerged: (*Handler).serveGo, PackageRef: goRef, }
GoHooks is the go group: merged version lists, everything else first-hit.
var HelmHooks = Hooks{ ServeMerged: (*Handler).serveHelm, PackageRef: helmRef, }
HelmHooks is the helm group: merged index.yaml, charts first-hit.
var IvyHooks = Hooks{PackageRef: ivyRef} //nolint:gochecknoglobals // immutable format hook value
IvyHooks is the ivy group: first hit, with module ownership for hosted wins.
var MavenHooks = Hooks{ ServeMerged: func( h *Handler, w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, readable []*models.Repository, be Backend, ) bool { base, suffix, ok := mavenMetadataPath(relPath) if ok { h.serveMavenMetadata(w, r, grp, readable, base, suffix, be) } return ok }, PackageRef: mavenRef, }
MavenHooks is the maven group: merged maven-metadata.xml, everything else first-hit.
var NPMHooks = Hooks{ ServeMerged: (*Handler).serveNPM, PackageRef: npmRef, }
NPMHooks is the npm group: merged packuments, tarballs first-hit.
var NixHooks = Hooks{ ServeMerged: func( h *Handler, w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, readable []*models.Repository, be Backend, ) bool { h.serveNix(w, r, grp, readable, relPath, be) return true }, }
NixHooks is the nix group: answers the cache documents and narinfo itself, the first member that has a package answers. No hosted-wins: hosted members are asked before proxy ones and there are no package names to hide.
var NuGetHooks = Hooks{ ServeMerged: (*Handler).serveNuGet, PackageRef: nugetRef, }
NuGetHooks is the nuget group: merged registrations and version lists, packages first-hit.
var PacmanHooks = pacmanFormat.hooks() //nolint:gochecknoglobals // immutable format hook value
PacmanHooks is the pacman group: merged databases per architecture, files (and their signatures) from the member that owns the package.
var PubHooks = Hooks{ ServeMerged: (*Handler).servePub, PackageRef: pubRef, }
PubHooks is the pub group: merged package documents, archive downloads first-hit.
var PyPIHooks = Hooks{ ServeMerged: func( h *Handler, w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, readable []*models.Repository, be Backend, ) bool { return h.servePyPI(w, r, grp, readable, relPath, be) }, PackageRef: pypiRef, AuthPath: pypiAuthPath, }
PyPIHooks is the pypi group: merged project pages, files first-hit. A file is authorized with the path its member serves it under.
var RPMHooks = rpmFormat.hooks() //nolint:gochecknoglobals // immutable format hook value
RPMHooks is the rpm group: merged repodata, files from the member the merged index lists them for.
var RubyGemsHooks = Hooks{ ServeMerged: (*Handler).serveRubyGems, PackageRef: rubygemsRef, }
RubyGemsHooks is the rubygems group: merged compact index, gems first-hit.
var SBTHooks = Hooks{PackageRef: sbtRef} //nolint:gochecknoglobals // immutable format hook value
SBTHooks is the sbt group: first hit, with module ownership for hosted wins.
var SwiftHooks = Hooks{ ServeMerged: (*Handler).serveSwift, PackageRef: swiftRef, MethodNotAllowed: swiftReadOnly, }
SwiftHooks is the swift group: merged release lists and identifiers, release documents and manifests of the first member that has them, archives first-hit. Every error answer is problem+json, like the swift repositories'.
var TerraformHooks = Hooks{ ServeMerged: (*Handler).serveTerraform, PackageRef: terraformRef, }
TerraformHooks is the terraform group: merged version lists and discovery, downloads first-hit.
Functions ¶
Types ¶
type Backend ¶ added in v0.4.0
type Backend struct {
// Authorize reports whether the caller may read relPath of member. A
// member the caller cannot read behaves exactly like a member without the
// file, so a public group never exposes a private member.
Authorize func(r *http.Request, member *models.Repository, relPath string) bool
// ServeMember serves a GET/HEAD for relPath from member into w, the way a
// direct request to that member would (404 when it has no such file).
ServeMember func(w http.ResponseWriter, r *http.Request, member *models.Repository, relPath string)
}
Backend is what a group needs from the rest of the server to resolve a request against one member.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler resolves requests for group repositories.
func NewHandler ¶
func NewHandler(log *logger.Logger, db HandlerStore) *Handler
NewHandler creates the group handler.
func (*Handler) Serve ¶ added in v0.4.0
func (h *Handler) Serve(w http.ResponseWriter, r *http.Request, grp *models.Repository, relPath string, be Backend)
Serve answers a request for relPath (below the repository root) of group grp. Groups are read-only: anything but GET/HEAD is refused, and a blocked group answers 403 whatever its members hold.
Hosted wins (dependency confusion): unless grp.MergeProxyVersions is set, a package name that any readable hosted member holds is served from the hosted members only — proxy members' versions, metadata entries and files of that name are hidden (see applyHostedWins and hostedwins.go for how each format recognizes a name and for the fail-closed rules). Names no readable hosted member holds are served by the proxies as before. A hosted member the caller cannot read counts as absent. Raw groups merge nothing: the first member in order wins.
func (*Handler) ServeOCI ¶ added in v0.6.0
func (h *Handler) ServeOCI( w http.ResponseWriter, r *http.Request, grp *models.Repository, req ocipath.Request, relPath string, be Backend, )
ServeOCI answers a /v2/ request addressed to the docker group grp. req is the parsed path and relPath the part below the group's name ("<image>/manifests/ <ref>"): the group is a read-only view, so only pulls are served. A manifest or blob comes from the first member that has it (members the caller cannot read behave as if they did not); a tag listing is the union of every readable member's tags. A blocked group answers 403 DENIED.
Hosted wins (unless grp.MergeProxyVersions): an image that a readable hosted member holds (it answers <image>/tags/list with 200) is served from the hosted members only — its tag list is theirs alone and a manifest or blob they lack is unknown, never a proxy's. Images no hosted member holds are served by the proxies; if a hosted member could not say, the request is refused with UNAVAILABLE rather than risk serving the proxy's image.
func (*Handler) SetBaseURL ¶ added in v0.6.0
SetBaseURL sets BASE_URL, the explicit override of the origin the merged packuments' tarball URLs point at ("" derives it from each request).
func (*Handler) WithApkKeys ¶ added in v0.13.0
func (h *Handler) WithApkKeys(keys formatapk.KeyProvider) *Handler
WithApkKeys enables the public key downloads of apk groups: keys resolves the key of the group itself (*apkkeys.Service), the one its merged indexes are signed with.
func (*Handler) WithMetadata ¶ added in v0.8.0
func (h *Handler) WithMetadata(blobs storage.BlobStore, gen MetadataGenerator) *Handler
WithMetadata enables deb, pacman and rpm groups: their merged metadata is read from the blob store (blobs) and generated by gen.
func (*Handler) WithNixKeys ¶ added in v0.14.0
func (h *Handler) WithNixKeys(keys formatnix.KeyProvider) *Handler
WithNixKeys enables the signing of nix groups: keys resolves the key of the group itself (*nixkeys.Service), the one it signs the narinfo of its hosted members with and publishes at /public.key.
type HandlerStore ¶ added in v0.15.0
type HandlerStore interface {
GetGroupMetadataState(ctx context.Context, groupID string) (*models.GroupMetadataState, error)
GetGroupPackageOwner(ctx context.Context, groupID string, path string) (string, bool, error)
GetRepoMetadataByPath(ctx context.Context, repositoryID string, path string) (*models.RepoMetadata, error)
HasCondaPackageName(ctx context.Context, repoID string, name string) (bool, error)
IvyModuleExists(ctx context.Context, repoID string, organisation string, module string) (bool, error)
ListCondaPackageNames(ctx context.Context, repoID string) ([]string, error)
ListGroupMemberRepositories(ctx context.Context, groupRepoID string) ([]*models.Repository, error)
SBTModuleExists(ctx context.Context, repoID string, groupID string, artifactID string) (bool, error)
}
HandlerStore is the part of the database Handler needs.
type Hooks ¶ added in v0.15.0
type Hooks struct {
// MethodNotAllowed answers a request that is neither GET nor HEAD (the
// Allow header is already set), for the formats whose clients expect an
// error body of their own (swift: problem+json). Nil answers a plain-text
// 405.
MethodNotAllowed func(w http.ResponseWriter)
// ServeMerged answers the requests the group of this format merges over its
// readable members, or answers itself; false means the request is a plain
// first-hit one. Nil is a plain first-hit group.
ServeMerged func(
h *Handler,
w http.ResponseWriter,
r *http.Request,
grp *models.Repository,
relPath string,
readable []*models.Repository,
be Backend,
) bool
// PackageRef extracts the package a request names for the hosted-wins rule
// (dependency confusion, see hostedwins.go); ok is false for requests that
// name none (indexes, config documents). Nil is a format with no versions to
// hide, or whose generated indexes are resolved member by member: no
// hosted-wins.
PackageRef func(relPath string) (ref PkgRef, ok bool)
// AuthPath is the path the caller is authorized against for member m: the
// one a direct request to m would be authorized with, so a path-scoped
// grant on the member means the same thing inside and outside the group.
// Nil is relPath unchanged.
AuthPath func(m *models.Repository, relPath string) string
}
Hooks is everything the group handler decides per format. A format's value (ansible.go's AnsibleHooks, npm.go's NPMHooks, ...) is registered once with Register; a format without a registered value, or with a nil field, gets the default documented on the field, which is what the formats that never needed the hook always had.
Intentionally without a value: docker (its requests go through ServeOCI, which has its own hosted-wins reference) and raw (merges nothing, no versions to hide). Both are plain first-hit groups. ivy and sbt only differ in the hosted-wins reference.
type MetadataGenerator ¶ added in v0.8.0
type MetadataGenerator interface {
// Generate synchronously (re)generates the metadata of the group. dist, for
// a Debian group, is a distribution the request asked for, for a pacman
// group an architecture: it is added to the group's served set when some
// member has it, ErrDistNotFound otherwise.
//
// readable are the IDs of the members the caller may read: the metadata a
// caller gets lists only their packages.
Generate(ctx context.Context, groupID, dist string, readable []string) error
// Scope names where the metadata for a caller who can read the members
// with these IDs is stored: "" when that is every member of the group (one
// index shared by all such callers), a path prefix of its own otherwise. ok
// is false when none of them is a live member.
Scope(ctx context.Context, groupID string, readable []string) (scope string, ok bool, err error)
// Refresh schedules a coalesced regeneration; it is a no-op while one is
// already pending or running.
Refresh(groupID string)
}
MetadataGenerator produces and invalidates the merged metadata of deb, pacman and rpm groups (the worker.GroupMetadataWorker).
type PkgRef ¶ added in v0.15.0
type PkgRef struct {
// contains filtered or unexported fields
}
PkgRef is the package a request names and how to find out whether a hosted member holds it. A format's Hooks.PackageRef returns it; the zero value of owner (probing the document named by probe and altProbes) is what most formats use.