Documentation
¶
Overview ¶
Package garf provides a high-level API for mirroring artifacts from sources like GitHub to destinations like JFrog Artifactory.
This package offers a simple, stable API for Go programs that want to mirror artifacts programmatically. It handles authentication, URL processing, and artifact uploading automatically.
Basic usage:
client, err := garf.NewClient(garf.Config{
JFrogURL: "https://mycompany.jfrog.io/artifactory",
JFrogUser: "username",
JFrogPassword: "password",
})
if err != nil {
log.Fatal(err)
}
result, err := client.Mirror(ctx, garf.MirrorRequest{
Source: "https://github.com/owner/repo/releases/download/v1.0.0/artifact.zip",
Destination: "my-generic-repo",
Properties: map[string]string{"type": "binary", "platform": "linux"},
Unzip: true, // Extract single files from zip archives
})
if err != nil {
log.Fatal(err)
}
For JFrog-to-JFrog mirroring with source path stripping:
result, err := client.Mirror(ctx, garf.MirrorRequest{
Source: "https://artifactory.corp.net/staging/github.com/owner/repo/releases/download/v1.0.0/artifact.zip",
Destination: "prod-repo",
SourcePathStrip: "artifactory.corp.net/staging/", // Strip staging prefix
Properties: map[string]string{"type": "binary"},
})
if err != nil {
log.Fatal(err)
}
Index ¶
- Constants
- func ExtractArtifactName(urlStr string) string
- func ValidateConfig(config Config) error
- type Client
- func (c *Client) DetectSourceType(sourceURL, sourcePathStrip string) string
- func (c *Client) EnsureSourceAvailable(sourceType string) error
- func (c *Client) GetCachedDestinationsCount() int
- func (c *Client) IsCachedDestination(key string) bool
- func (c *Client) Mirror(ctx context.Context, request MirrorRequest) (*MirrorResult, error)
- func (c *Client) ValidateRequest(request MirrorRequest) error
- type Config
- type MirrorRequest
- type MirrorResult
Constants ¶
const ( // DefaultTimeout is the default timeout for mirror operations. DefaultTimeout = 30 * time.Minute // DefaultConcurrent is the default number of concurrent operations. DefaultConcurrent = 4 // UnknownArtifactName is returned when artifact name cannot be determined. UnknownArtifactName = "unknown" )
Variables ¶
This section is empty.
Functions ¶
func ExtractArtifactName ¶
ExtractArtifactName extracts the artifact name from a URL.
func ValidateConfig ¶
ValidateConfig validates the client configuration.
Types ¶
type Client ¶
type Client struct {
Config Config
// contains filtered or unexported fields
}
Client provides the main interface for mirroring artifacts.
func (*Client) DetectSourceType ¶ added in v0.5.0
DetectSourceType determines the source type based on the URL. When SourcePathStrip is provided, it strips the prefix first to determine the actual source.
func (*Client) EnsureSourceAvailable ¶ added in v0.5.0
EnsureSourceAvailable ensures that the appropriate source is available in the mirror.
func (*Client) GetCachedDestinationsCount ¶
GetCachedDestinationsCount returns the number of cached destinations (for testing).
func (*Client) IsCachedDestination ¶
IsCachedDestination checks if a destination is cached (for testing).
func (*Client) Mirror ¶
func (c *Client) Mirror(ctx context.Context, request MirrorRequest) (*MirrorResult, error)
Mirror performs a single mirror operation.
func (*Client) ValidateRequest ¶
func (c *Client) ValidateRequest(request MirrorRequest) error
ValidateRequest validates a mirror request.
type Config ¶
type Config struct {
// Generic registry credentials (PREFERRED - supports both JFrog and Cloudsmith)
RegistryURL string // Replaces JFrogURL but supports both
RegistryUser string // Replaces JFrogUser but supports both
RegistryPassword string // Replaces JFrogPassword but supports both
// Registry type (defaults to "jfrog" for backward compatibility)
RegistryType string
// Deprecated: JFrog-specific fields (kept for backward compatibility)
// These will be mapped to Registry* fields if Registry* fields are empty
JFrogURL string
JFrogUser string
JFrogPassword string
// Optional: Custom logger (if nil, a default logger will be used)
Logger *logrus.Logger
// Optional: Request timeout (default: 30 minutes)
Timeout time.Duration
// Optional: Number of concurrent operations (default: 4)
Concurrent int
}
Config holds the configuration for the garf client.
type MirrorRequest ¶
type MirrorRequest struct {
// Source URL of the artifact to mirror
Source string
// Destination repository name in JFrog Artifactory
Destination string
// Optional: Properties to attach to the artifact
Properties map[string]string
// Optional: Whether to preserve the original URL structure (default: false)
Raw bool
// Optional: Whether to extract single files from zip archives (default: false)
Unzip bool
// Optional: Local file path to upload instead of downloading from source
// The source URL is still used for coordinate extraction
// TODO: This feature is not yet implemented
FromFile string
// Optional: Dry run mode - "all" skips everything, "upload" skips only upload
DryRun bool
DryRunMode string
// Optional: Source path prefix to strip from source URLs before processing.
// This is useful for JFrog-to-JFrog mirroring where you want to remove the source
// repository path. For example, setting this to "artifactory.corp.net/staging/"
// will strip that prefix from source URLs before generating the destination path.
// This enables clean mirroring from staging to production repositories.
SourcePathStrip string
}
MirrorRequest represents a single mirror operation request.
type MirrorResult ¶
type MirrorResult struct {
// Source URL that was mirrored
Source string
// Destination path where the artifact was stored
DestinationPath string
// Error if the operation failed (nil on success)
Error error
}
MirrorResult represents the result of a mirror operation.
Directories
¶
| Path | Synopsis |
|---|---|
|
garf
command
|
|
|
Package main demonstrates how to use garf as a library.
|
Package main demonstrates how to use garf as a library. |
|
pkg
|
|
|
core
Package core provides core types and constants for the garf application.
|
Package core provides core types and constants for the garf application. |
|
core/config
Package config provides configuration management functionality.
|
Package config provides configuration management functionality. |
|
destinations
Package destinations provides implementations for various registry destinations.
|
Package destinations provides implementations for various registry destinations. |
|
io/archive
Package archive provides functionality for handling various archive formats.
|
Package archive provides functionality for handling various archive formats. |
|
io/progress
Package progress provides utilities for tracking progress of operations.
|
Package progress provides utilities for tracking progress of operations. |
|
mirror
Package mirror provides the core interfaces and types for artifact mirroring.
|
Package mirror provides the core interfaces and types for artifact mirroring. |
|
processor
Package processor provides functionality for processing artifacts.
|
Package processor provides functionality for processing artifacts. |
|
sources
Package sources provides implementations of the core.Source interface.
|
Package sources provides implementations of the core.Source interface. |
|
testutil
Package testutil provides shared testing utilities for the garf project.
|
Package testutil provides shared testing utilities for the garf project. |
|
urlprocessor
Package urlprocessor provides interfaces and implementations for processing URLs to create structured paths for artifacts.
|
Package urlprocessor provides interfaces and implementations for processing URLs to create structured paths for artifacts. |