mirror

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package mirror provides selective package mirroring for pre-populating the proxy cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	ID        string    `json:"id"`
	State     JobState  `json:"state"`
	Progress  Progress  `json:"progress"`
	CreatedAt time.Time `json:"created_at"`
	Error     string    `json:"error,omitempty"`
	// contains filtered or unexported fields
}

Job represents an async mirror operation.

type JobRequest

type JobRequest struct {
	PURLs    []string `json:"purls,omitempty"`
	Registry string   `json:"registry,omitempty"`
}

JobRequest is the JSON body for starting a mirror job via the API.

type JobState

type JobState string

JobState represents the current state of a mirror job.

const (
	JobStatePending  JobState = "pending"
	JobStateRunning  JobState = "running"
	JobStateComplete JobState = "complete"
	JobStateFailed   JobState = "failed"
	JobStateCanceled JobState = "canceled"
)

type JobStore

type JobStore struct {
	// contains filtered or unexported fields
}

JobStore manages in-memory mirror jobs.

func NewJobStore

func NewJobStore(ctx context.Context, m *Mirror) *JobStore

NewJobStore creates a new job store. The parent context is used as the base for all job contexts so that jobs are canceled when the server shuts down.

func (*JobStore) Cancel

func (js *JobStore) Cancel(id string) bool

Cancel cancels a running job.

func (*JobStore) Cleanup

func (js *JobStore) Cleanup()

Cleanup removes completed/failed/canceled jobs older than jobTTL.

func (*JobStore) Create

func (js *JobStore) Create(req JobRequest) (string, error)

Create starts a new mirror job and returns its ID.

func (*JobStore) Get

func (js *JobStore) Get(id string) *Job

Get returns a snapshot of a job by ID. The returned copy is safe to serialize without holding the lock.

func (*JobStore) StartCleanup

func (js *JobStore) StartCleanup(ctx context.Context)

StartCleanup runs periodic cleanup of old jobs until the context is canceled.

type Mirror

type Mirror struct {
	// contains filtered or unexported fields
}

Mirror pre-populates the proxy cache from various input sources.

func New

func New(proxy *handler.Proxy, db *database.DB, store storage.Storage, logger *slog.Logger, workers int) *Mirror

New creates a new Mirror with the given dependencies.

func (*Mirror) Run

func (m *Mirror) Run(ctx context.Context, source Source, onProgress ...ProgressFunc) (*Progress, error)

Run mirrors all packages from the source using a bounded worker pool. It returns the final progress when complete. If onProgress is non-nil, it is called with progress snapshots as work proceeds.

func (*Mirror) RunDryRun

func (m *Mirror) RunDryRun(ctx context.Context, source Source) ([]PackageVersion, error)

RunDryRun enumerates what would be mirrored without downloading.

type MirrorError

type MirrorError struct {
	Ecosystem string `json:"ecosystem"`
	Name      string `json:"name"`
	Version   string `json:"version"`
	Error     string `json:"error"`
}

MirrorError records a single failed mirror attempt.

type PURLSource

type PURLSource struct {
	PURLs     []string
	RegClient *registries.Client
}

PURLSource yields packages from PURL strings. Versioned PURLs produce a single item. Unversioned PURLs look up all versions from the registry.

func (*PURLSource) Enumerate

func (s *PURLSource) Enumerate(ctx context.Context, fn func(PackageVersion) error) error

type PackageVersion

type PackageVersion struct {
	Ecosystem string
	Name      string
	Version   string
}

PackageVersion identifies a specific package version to mirror.

func (PackageVersion) String

func (pv PackageVersion) String() string

type Progress

type Progress struct {
	Total     int64         `json:"total"`
	Completed int64         `json:"completed"`
	Skipped   int64         `json:"skipped"`
	Failed    int64         `json:"failed"`
	Bytes     int64         `json:"bytes"`
	Errors    []MirrorError `json:"errors,omitempty"`
	StartedAt time.Time     `json:"started_at"`
	Phase     string        `json:"phase"`
}

Progress tracks the state of a mirror operation.

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc is called periodically with a snapshot of the current progress.

type RegistrySource

type RegistrySource struct {
	Ecosystem string
}

RegistrySource enumerates all packages in a registry for full mirroring. Registry enumeration is not yet implemented for any ecosystem.

func (*RegistrySource) Enumerate

func (s *RegistrySource) Enumerate(_ context.Context, _ func(PackageVersion) error) error

type SBOMSource

type SBOMSource struct {
	Path      string
	RegClient *registries.Client
}

SBOMSource extracts package versions from a CycloneDX or SPDX SBOM file.

func (*SBOMSource) Enumerate

func (s *SBOMSource) Enumerate(ctx context.Context, fn func(PackageVersion) error) error

type Source

type Source interface {
	Enumerate(ctx context.Context, fn func(PackageVersion) error) error
}

Source produces PackageVersion items for mirroring.

Jump to

Keyboard shortcuts

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