adapters

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package adapters implements per-registry RegistryAdapter implementations.

Index

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

func NewGoAdapter(upstreams []string, opts ...Option) *GoAdapter

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) Name added in v0.3.0

func (a *GoAdapter) Name() string

func (*GoAdapter) NormalizeRequest added in v0.3.0

func (a *GoAdapter) NormalizeRequest(r *http.Request) (*gate.PackageRef, bool)

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.

func (*GoAdapter) UpstreamURLs added in v0.3.0

func (a *GoAdapter) UpstreamURLs(r *http.Request) []string

UpstreamURLs returns one candidate URL per configured upstream, in order. The client already sent case-encoded paths, so RequestURI() is forwarded verbatim.

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) Name

func (a *NPMAdapter) Name() string

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

func WithHTTPClient(client *http.Client) Option

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.

Jump to

Keyboard shortcuts

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