mirror

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

README

Mirror Package

This package provides the core mirroring functionality for copying artifacts between sources and destinations.

Components

DefaultMirror

The DefaultMirror type implements the Mirror interface and provides the main functionality for artifact mirroring.

Features
  • Concurrent artifact processing
  • Multiple source and destination support
  • Progress tracking
  • Artifact validation
  • Configurable concurrency
  • Thread-safe operations
Usage
mirror := mirror.NewDefaultMirror(logger)

// Add source and destination
err := mirror.AddSource("github", githubSource)
err = mirror.AddDestination("jfrog", jfrogDest)

// Configure mirroring options
opts := &core.MirrorOptions{
    PreserveStructure: true,
    VerifyChecksum:    true,
    Concurrent:        4,
    Context:           ctx,
}

// Start mirroring
results := mirror.Mirror(ctx, artifacts, opts)

// Process results
for result := range results {
    if result.Error != nil {
        log.Printf("Failed to mirror %s: %v", result.Artifact.Name, result.Error)
    } else {
        log.Printf("Successfully mirrored %s to %s", result.Artifact.Name, result.DestinationPath)
    }
}
Interfaces
Mirror

The Mirror interface defines the core mirroring functionality:

type Mirror interface {
    Mirror(ctx context.Context, artifacts []*core.Artifact, opts *core.MirrorOptions) <-chan MirrorResult
    AddSource(name string, source core.Source) error
    AddDestination(name string, destination core.Destination) error
    GetSource(name string) (core.Source, error)
    GetDestination(name string) (core.Destination, error)
}
ProgressTracker

The ProgressTracker interface provides progress tracking capabilities:

type ProgressTracker interface {
    Start(total int64)
    Update(current int64)
    Complete()
}
Validator

The Validator interface provides artifact validation capabilities:

type Validator interface {
    ValidateArtifact(artifact *core.Artifact) error
    ValidateChecksum(artifact *core.Artifact, content io.Reader) error
}

MirrorResult

The MirrorResult type contains the result of a mirror operation:

type MirrorResult struct {
    Artifact         *core.Artifact
    DestinationPath  string
    Error           error
}

Configuration

The mirror can be configured with:

  • Custom logger
  • Number of concurrent operations
  • Progress tracking
  • Artifact validation
  • Source and destination mappings

Error Handling

The mirror provides detailed error information through the MirrorResult channel, including:

  • Artifact identification
  • Destination path
  • Specific error messages
  • Operation status

Documentation

Overview

Package mirror provides the core interfaces and types for artifact mirroring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessMirrorResults

func ProcessMirrorResults(logger *logrus.Logger, results <-chan MirrorResult) error

ProcessMirrorResults processes the results from the mirror operation.

func SetupDestination

func SetupDestination(logger *logrus.Logger, config *config.Config) (core.Destination, error)

SetupDestination creates and configures a destination based on the provided configuration.

func SetupSource

func SetupSource(logger *logrus.Logger, config *config.Config) (core.Source, error)

SetupSource creates and configures a mirroring source based on the provided configuration. It currently supports a GitHub source when the source type is "github" and returns an error if an unsupported source type is specified or if the created source fails validation.

Types

type ChecksumValidatingReader added in v0.5.6

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

ChecksumValidatingReader wraps an io.ReadCloser and validates the SHA256 checksum of the read content against an expected value.

func NewChecksumValidatingReader added in v0.5.6

func NewChecksumValidatingReader(reader io.ReadCloser, expectedChecksum string) *ChecksumValidatingReader

NewChecksumValidatingReader creates a new ChecksumValidatingReader.

func (*ChecksumValidatingReader) Close added in v0.5.6

func (r *ChecksumValidatingReader) Close() error

Close closes the underlying reader.

func (*ChecksumValidatingReader) Read added in v0.5.6

func (r *ChecksumValidatingReader) Read(p []byte) (int, error)

Read reads from the underlying reader and updates the hash. If EOF is reached, it validates the checksum.

type DefaultMirror

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

DefaultMirror implements the Mirror interface.

func NewDefaultMirror

func NewDefaultMirror(logger *logrus.Logger) *DefaultMirror

NewDefaultMirror creates a new DefaultMirror instance.

func (*DefaultMirror) AddDestination

func (m *DefaultMirror) AddDestination(name string, destination core.Destination) error

AddDestination adds a new destination to the mirror.

func (*DefaultMirror) AddSource

func (m *DefaultMirror) AddSource(name string, source core.Source) error

AddSource adds a new source to the mirror.

func (*DefaultMirror) GetDestination

func (m *DefaultMirror) GetDestination(name string) (core.Destination, error)

GetDestination retrieves a destination by name.

func (*DefaultMirror) GetSource

func (m *DefaultMirror) GetSource(name string) (core.Source, error)

GetSource retrieves a source by name.

func (*DefaultMirror) Mirror

func (m *DefaultMirror) Mirror(
	ctx context.Context,
	artifacts []*core.Artifact,
	opts *core.MirrorOptions,
) <-chan MirrorResult

Mirror copies artifacts from sources to destinations.

func (*DefaultMirror) ProcessMirrorResults

func (m *DefaultMirror) ProcessMirrorResults(logger *logrus.Logger, results <-chan MirrorResult) error

ProcessMirrorResults processes the results from the mirror operation.

func (*DefaultMirror) SetupDestination

func (m *DefaultMirror) SetupDestination(logger *logrus.Logger, config *config.Config) (core.Destination, error)

SetupDestination creates and configures a destination based on the provided configuration.

func (*DefaultMirror) SetupSource

func (m *DefaultMirror) SetupSource(logger *logrus.Logger, config *config.Config) (core.Source, error)

SetupSource creates and configures a source based on the provided configuration.

type Mirror

type Mirror interface {
	// Mirror copies artifacts from a source to a destination
	Mirror(ctx context.Context, artifacts []*core.Artifact, opts *core.MirrorOptions) <-chan MirrorResult

	// AddSource adds a new source to the mirror
	AddSource(name string, source core.Source) error

	// AddDestination adds a new destination to the mirror
	AddDestination(name string, destination core.Destination) error

	// GetSource retrieves a source by name
	GetSource(name string) (core.Source, error)

	// GetDestination retrieves a destination by name
	GetDestination(name string) (core.Destination, error)
}

Mirror represents the core mirroring functionality.

type MirrorResult

type MirrorResult struct {
	// Artifact is the original artifact that was mirrored
	Artifact *core.Artifact

	// DestinationPath is where the artifact was mirrored to
	DestinationPath string

	// Error contains any error that occurred during mirroring
	// If nil, the operation was successful
	Error error
}

MirrorResult contains the result of a mirror operation.

type ProgressTracker

type ProgressTracker interface {
	// Start initializes the progress tracking
	Start(total int64)

	// Update updates the current progress
	Update(current int64)

	// Complete marks the operation as complete
	Complete()
}

ProgressTracker provides progress tracking for mirror operations.

type UploadWorkerParams added in v0.5.6

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

UploadWorkerParams holds parameters for the upload worker.

type Validator

type Validator interface {
	// ValidateArtifact checks if an artifact is valid
	ValidateArtifact(artifact *core.Artifact) error

	// ValidateChecksum verifies the checksum of an artifact
	ValidateChecksum(artifact *core.Artifact, content io.Reader) error
}

Validator provides validation functionality for artifacts.

Jump to

Keyboard shortcuts

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