Documentation
¶
Overview ¶
Package adapters implements per-registry RegistryAdapter implementations.
Index ¶
- type GoAdapter
- func (a *GoAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
- func (a *GoAdapter) IsArtifactPath(r *http.Request) bool
- func (a *GoAdapter) Name() string
- func (a *GoAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
- func (a *GoAdapter) UpstreamURLs(r *http.Request) []string
- type MavenAdapter
- func (a *MavenAdapter) FetchMetadata(_ context.Context, _ *gate.PackageRef) (*gate.PackageMetadata, error)
- func (a *MavenAdapter) IsArtifactPath(r *http.Request) bool
- func (a *MavenAdapter) MetadataFromHeader(h http.Header) *gate.PackageMetadata
- func (a *MavenAdapter) Name() string
- func (a *MavenAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
- func (a *MavenAdapter) UpstreamURLs(r *http.Request) []string
- type NPMAdapter
- func (a *NPMAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
- func (a *NPMAdapter) FilterVersions(doc []byte, ref *gate.MetadataRef, decide gate.VersionDecider, linkBase string) (gate.FilteredDocument, error)
- func (a *NPMAdapter) IsArtifactPath(r *http.Request) bool
- func (a *NPMAdapter) Name() string
- func (a *NPMAdapter) NormalizeMetadataRequest(r *http.Request) (*gate.MetadataRef, bool)
- func (a *NPMAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
- func (a *NPMAdapter) UpstreamURLs(r *http.Request) []string
- type Option
- type PyPIAdapter
- func (a *PyPIAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
- func (a *PyPIAdapter) IsArtifactPath(r *http.Request) bool
- func (a *PyPIAdapter) IsIndexRequest(r *http.Request) bool
- func (a *PyPIAdapter) Name() string
- func (a *PyPIAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
- func (a *PyPIAdapter) RewriteIndex(doc []byte, contentType, requestPath string) (gate.IndexRewrite, error)
- func (a *PyPIAdapter) UpstreamURLs(r *http.Request) []string
- type RubyGemsAdapter
- func (a *RubyGemsAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
- func (a *RubyGemsAdapter) IsArtifactPath(r *http.Request) bool
- func (a *RubyGemsAdapter) Name() string
- func (a *RubyGemsAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
- func (a *RubyGemsAdapter) UpstreamURLs(r *http.Request) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoAdapter ¶ added in v0.3.0
type GoAdapter struct {
// contains filtered or unexported fields
}
GoAdapter implements gate.RegistryAdapter for the Go module proxy protocol (GOPROXY). It intercepts module zip downloads for gating and proxies the rest of the protocol (list/.info/.mod/@latest) transparently.
func NewGoAdapter ¶ added in v0.3.0
NewGoAdapter creates a Go module adapter over the given ordered upstream URLs.
func (*GoAdapter) FetchMetadata ¶ added in v0.3.0
func (a *GoAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
FetchMetadata fetches the module version's .info document from each upstream in order, returning the first success. The .info Time is the publish date; the Go protocol carries no license or (SHA256) checksum there, so those stay empty.
func (*GoAdapter) IsArtifactPath ¶ added in v1.0.0
IsArtifactPath implements gate.ArtifactPathMatcher: a module zip is any ".zip" under "/@v/", including one whose case-encoding NormalizeRequest rejects.
func (*GoAdapter) NormalizeRequest ¶ added in v0.3.0
NormalizeRequest intercepts module zip downloads (path contains "/@v/" and ends ".zip"). list/.info/.mod/@latest requests are proxied transparently. The case-encoded module path and version are decoded to canonical coordinates for OSV / allowlist lookups.
type MavenAdapter ¶
type MavenAdapter struct {
// contains filtered or unexported fields
}
MavenAdapter implements gate.RegistryAdapter for a Maven repository.
func NewMavenAdapter ¶
func NewMavenAdapter(upstreams []string, opts ...Option) *MavenAdapter
NewMavenAdapter creates a Maven adapter over the given ordered upstream URLs (e.g. "https://repo1.maven.org/maven2"). Upstreams are tried in order.
func (*MavenAdapter) FetchMetadata ¶
func (a *MavenAdapter) FetchMetadata(_ context.Context, _ *gate.PackageRef) (*gate.PackageMetadata, error)
FetchMetadata is a no-op for Maven: there is no separate metadata API to call. The publish-date proxy (the artifact's Last-Modified) is read from the download response instead — see MetadataFromHeader — so a pull costs one GET rather than an extra HEAD on the .pom. MavenAdapter implements gate.DownloadMetadataExtractor, so the handler never calls this; it exists to satisfy the RegistryAdapter contract.
func (*MavenAdapter) IsArtifactPath ¶ added in v1.0.0
func (a *MavenAdapter) IsArtifactPath(r *http.Request) bool
IsArtifactPath implements gate.ArtifactPathMatcher. In the Maven layout an artifact is recognised by the same rule that names it, so every artifact path NormalizeRequest sees is one it can parse.
func (*MavenAdapter) MetadataFromHeader ¶
func (a *MavenAdapter) MetadataFromHeader(h http.Header) *gate.PackageMetadata
MetadataFromHeader derives package metadata from an artifact download response. Maven Central serves artifacts as static files, so the .jar's Last-Modified is a sound proxy for the publish date used by the supply-chain age check. A missing/unparseable header yields a zero PublishedAt, which the age check treats as old.
func (*MavenAdapter) Name ¶
func (a *MavenAdapter) Name() string
func (*MavenAdapter) NormalizeRequest ¶
func (a *MavenAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
NormalizeRequest intercepts artifact downloads: any file in a version directory except the sidecars in mavenSidecarExts, which are proxied transparently.
func (*MavenAdapter) UpstreamURLs ¶
func (a *MavenAdapter) UpstreamURLs(r *http.Request) []string
UpstreamURLs returns one candidate URL per configured upstream, in order.
type NPMAdapter ¶
type NPMAdapter struct {
// contains filtered or unexported fields
}
NPMAdapter implements gate.RegistryAdapter for the npm registry.
func NewNPMAdapter ¶
func NewNPMAdapter(upstreams []string, opts ...Option) *NPMAdapter
NewNPMAdapter creates an npm adapter over the given ordered upstream URLs.
func (*NPMAdapter) FetchMetadata ¶
func (a *NPMAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
FetchMetadata walks the configured upstreams in order, returning the first success. When every upstream fails, the returned error is an upstream.Attempts carrying each mirror's own outcome.
func (*NPMAdapter) FilterVersions ¶ added in v0.5.0
func (a *NPMAdapter) FilterVersions(doc []byte, ref *gate.MetadataRef, decide gate.VersionDecider, linkBase string) (gate.FilteredDocument, error)
FilterVersions implements gate.MetadataFilterer. For a packument it drops every version decide rejects, along with that version's "time" entry, and points every remaining dist.tarball at linkBase in the canonical "<name>/-/<unscoped>-<version>.tgz" shape, whatever shape the upstream used. A version whose link cannot take that shape is dropped too: a version the client cannot see is the safe failure, one it downloads around the proxy is not. Unknown fields survive because the document is decoded one level deep, as raw JSON. dist-tags are deliberately left alone: npm tolerates a tag naming a version that is no longer listed and falls back to the highest one that is, which spares this project a semver comparator.
A single-version manifest (ref.Version set) only has its link rewritten; the artifact gate rules on the download.
func (*NPMAdapter) IsArtifactPath ¶ added in v1.0.0
func (a *NPMAdapter) IsArtifactPath(r *http.Request) bool
IsArtifactPath implements gate.ArtifactPathMatcher: a tarball is any ".tgz" under a "/-/" segment, whether or not NormalizeRequest can read the version out of its file name.
func (*NPMAdapter) Name ¶
func (a *NPMAdapter) Name() string
func (*NPMAdapter) NormalizeMetadataRequest ¶ added in v0.5.0
func (a *NPMAdapter) NormalizeMetadataRequest(r *http.Request) (*gate.MetadataRef, bool)
NormalizeMetadataRequest reports whether r asks for an npm metadata document: a packument ("/left-pad", "/@types/node"), the per-package document npm resolves version ranges from, or a single-version manifest ("/left-pad/1.3.0", "/left-pad/latest"). Both link tarballs by absolute URL, so both are rewritten. Registry service endpoints live under "/-/" and are proxied untouched.
func (*NPMAdapter) NormalizeRequest ¶
func (a *NPMAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
NormalizeRequest intercepts tarball downloads (path contains "/-/" and ends ".tgz"). Metadata documents (e.g. "/lodash") are proxied transparently.
func (*NPMAdapter) UpstreamURLs ¶
func (a *NPMAdapter) UpstreamURLs(r *http.Request) []string
UpstreamURLs returns one candidate URL per configured upstream, in order.
type Option ¶
type Option func(*adapterConfig)
Option customizes an adapter at construction. With no options an adapter uses a private http.Client with defaultAdapterTimeout.
func WithHTTPClient ¶
WithHTTPClient makes the adapter use client for all upstream requests. Sharing one client whose transport caps per-host concurrency (see internal/httpx) across every adapter and the proxy handler keeps total outbound concurrency to a single registry bounded, which is what prevents HTTP 429 throttling.
type PyPIAdapter ¶
type PyPIAdapter struct {
// contains filtered or unexported fields
}
PyPIAdapter implements gate.RegistryAdapter for PyPI.
func NewPyPIAdapter ¶
func NewPyPIAdapter(upstreams []string, opts ...Option) *PyPIAdapter
NewPyPIAdapter creates a PyPI adapter over the given ordered upstream URLs.
func (*PyPIAdapter) FetchMetadata ¶
func (a *PyPIAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
FetchMetadata walks the configured upstreams in order, returning the first success. When every upstream fails, the returned error is an upstream.Attempts carrying each mirror's own outcome.
func (*PyPIAdapter) IsArtifactPath ¶ added in v1.0.0
func (a *PyPIAdapter) IsArtifactPath(r *http.Request) bool
IsArtifactPath implements gate.ArtifactPathMatcher: everything under /packages/ is a distribution file, except a distribution's PEP 658 core metadata (<file>.metadata) — the METADATA text pip reads while resolving, which carries no code and is proxied as-is.
func (*PyPIAdapter) IsIndexRequest ¶ added in v1.0.0
func (a *PyPIAdapter) IsIndexRequest(r *http.Request) bool
IsIndexRequest implements gate.IndexRewriter: simple-index pages (PEP 503 HTML or PEP 691 JSON) and the JSON API.
func (*PyPIAdapter) Name ¶
func (a *PyPIAdapter) Name() string
func (*PyPIAdapter) NormalizeRequest ¶
func (a *PyPIAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
NormalizeRequest extracts a PackageRef from download requests. Returns false for /simple/ and /pypi/ (metadata) requests.
func (*PyPIAdapter) RewriteIndex ¶ added in v1.0.0
func (a *PyPIAdapter) RewriteIndex(doc []byte, contentType, requestPath string) (gate.IndexRewrite, error)
RewriteIndex implements gate.IndexRewriter. A link survives only if it positively resolves to a /packages/ path, and is then served as a relative link to the proxy's own /packages/ route, so the download goes through the gates. Every other link — another host, another path, or anything this proxy might parse differently from pip or uv — is removed: the safe failure is a file the client cannot see, never one it fetches around the proxy.
func (*PyPIAdapter) UpstreamURLs ¶
func (a *PyPIAdapter) UpstreamURLs(r *http.Request) []string
UpstreamURLs returns one candidate URL per configured upstream, in order.
type RubyGemsAdapter ¶
type RubyGemsAdapter struct {
// contains filtered or unexported fields
}
RubyGemsAdapter implements gate.RegistryAdapter for a RubyGems repository.
func NewRubyGemsAdapter ¶
func NewRubyGemsAdapter(upstreams []string, opts ...Option) *RubyGemsAdapter
NewRubyGemsAdapter creates a RubyGems adapter over the given ordered upstream URLs (e.g. "https://rubygems.org"). Upstreams are tried in order.
func (*RubyGemsAdapter) FetchMetadata ¶
func (a *RubyGemsAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
FetchMetadata walks the configured upstreams in order, returning the first success. When every upstream fails, the returned error is an upstream.Attempts carrying each mirror's own outcome.
func (*RubyGemsAdapter) IsArtifactPath ¶ added in v1.0.0
func (a *RubyGemsAdapter) IsArtifactPath(r *http.Request) bool
IsArtifactPath implements gate.ArtifactPathMatcher: every ".gem" file is a gem, wherever it sits and whatever its name.
func (*RubyGemsAdapter) Name ¶
func (a *RubyGemsAdapter) Name() string
func (*RubyGemsAdapter) NormalizeRequest ¶
func (a *RubyGemsAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
NormalizeRequest intercepts gem downloads: /gems/<name>-<version>[-<platform>].gem. API/index paths (/api/, /info/, /versions, /quick/, /specs*) are proxied transparently.
func (*RubyGemsAdapter) UpstreamURLs ¶
func (a *RubyGemsAdapter) UpstreamURLs(r *http.Request) []string
UpstreamURLs returns one candidate URL per configured upstream, in order.