Documentation
¶
Overview ¶
Package adapters implements per-registry RegistryAdapter implementations.
Index ¶
- type GoAdapter
- type MavenAdapter
- func (a *MavenAdapter) FetchMetadata(_ context.Context, _ *gate.PackageRef) (*gate.PackageMetadata, error)
- 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, decide gate.VersionDecider) (gate.FilteredDocument, error)
- 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
- type RubyGemsAdapter
- func (a *RubyGemsAdapter) FetchMetadata(ctx context.Context, ref *gate.PackageRef) (*gate.PackageMetadata, error)
- 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) 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) 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 (treated as old), matching the previous behavior when the .pom carried no Last-Modified.
func (*MavenAdapter) Name ¶
func (a *MavenAdapter) Name() string
func (*MavenAdapter) NormalizeRequest ¶
func (a *MavenAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)
NormalizeRequest intercepts binary artifact downloads (.jar/.war/.aar). Sidecar files (.pom, .sha1, .md5, .asc) 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, decide gate.VersionDecider) (gate.FilteredDocument, error)
FilterVersions implements gate.MetadataFilterer. It rewrites an npm packument, dropping every version decide rejects along with that version's "time" entry. 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.
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 packument — the per-package document npm resolves version ranges from. Only a bare package name qualifies: registry service endpoints live under "/-/", and a single-version manifest ("/left-pad/1.3.0") carries no version list to rewrite, so both are proxied untouched and blocked at download time instead.
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) 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) 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) 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.