Documentation
¶
Overview ¶
Package core provides core types and constants for the garf application.
Package core provides source type detection functionality.
Package core provides validation functionality for garf parameters.
Index ¶
- Constants
- Variables
- func DetectSourceType(sourceURL, sourcePathStrip string) string
- func IsGitHubURL(urlStr string) (bool, error)
- func ParseProperties(properties []string) map[string]string
- func ValidateDryRunMode(dryRunMode string) error
- func ValidateGitHubURL(urlStr string) error
- func ValidateSourcePathStrip(sourcePathStrip string) error
- type Artifact
- type Destination
- type ErrorGroup
- type MirrorOptions
- type Source
Constants ¶
const ( // SourceTypeGitHub represents the GitHub source type for downloading from GitHub releases. SourceTypeGitHub = "github" // SourceTypeGeneric represents the generic HTTP source type for downloading from any HTTP/HTTPS URL. SourceTypeGeneric = "generic" )
Source type constants.
const ( // RegistryTypeJFrog represents the JFrog Artifactory registry type. RegistryTypeJFrog = "jfrog" // RegistryTypeCloudsmith represents the Cloudsmith registry type. RegistryTypeCloudsmith = "cloudsmith" )
Registry type constants.
const (
// GitHubHost is the standard GitHub hostname.
GitHubHost = "github.com"
)
Variables ¶
var ValidDestinationTypes = map[string]struct{}{ RegistryTypeJFrog: {}, RegistryTypeCloudsmith: {}, }
ValidDestinationTypes contains the set of valid destination types for validation. Using map[string]struct{} for memory efficiency in set operations.
Functions ¶
func 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 IsGitHubURL ¶
IsGitHubURL checks if a URL is from GitHub. During testing, localhost and 127.0.0.1 are considered valid GitHub URLs.
func ParseProperties ¶
ParseProperties parses a slice of strings into a map of key-value pairs. For each string, it splits at the first '=' character and trims any surrounding whitespace from both the key and value.
func ValidateDryRunMode ¶ added in v0.5.0
ValidateDryRunMode validates the dry run mode parameter.
func ValidateGitHubURL ¶
ValidateGitHubURL validates that the given URL is a GitHub URL. Returns an error if the URL is invalid or not from GitHub. During testing, localhost and 127.0.0.1 are considered valid GitHub URLs.
func ValidateSourcePathStrip ¶ added in v0.5.0
ValidateSourcePathStrip validates the source path strip parameter for security and correctness.
Types ¶
type Artifact ¶
type Artifact struct {
// Name is the unique identifier for the artifact
Name string
// Version represents the artifact version
Version string
// Location is the source location of the artifact
Location string
// Metadata contains additional artifact information
Metadata map[string]string
}
Artifact represents a single artifact that can be mirrored.
type Destination ¶
type Destination interface {
// Put stores an artifact in the destination and returns the destination path
// If raw is true, keeps the original URL structure
// Returns the final destination path/URL where the artifact was stored
Put(ctx context.Context, artifact *Artifact, content io.Reader, raw bool) (string, error)
// Exists checks if an artifact already exists in the destination
// If raw is true, keeps the original URL structure
Exists(ctx context.Context, artifact *Artifact, raw bool) (bool, error)
// BuildDestinationPath builds the destination path without uploading
// This is useful for dry-run mode to show where the artifact would be uploaded
BuildDestinationPath(artifact *Artifact, raw bool) (string, error)
// Validate checks if the destination configuration is valid
Validate() error
}
Destination represents a location where artifacts can be stored.
type ErrorGroup ¶
type ErrorGroup struct {
// contains filtered or unexported fields
}
ErrorGroup collects multiple errors and combines them into a single error.
func (*ErrorGroup) Add ¶
func (g *ErrorGroup) Add(err error)
Add adds an error to the group if it is not nil.
func (*ErrorGroup) Err ¶
func (g *ErrorGroup) Err() error
Err returns nil if no errors were added, otherwise returns a combined error with all error messages.
type MirrorOptions ¶
type MirrorOptions struct {
// Context allows for cancellation and timeouts
Context context.Context
// Raw keeps the original URL structure instead of creating a cleaner path
Raw bool
// Concurrent specifies the number of concurrent mirror operations
// If set to 0, a sensible default will be used
Concurrent int
// ProgressFunc is called to report progress during mirroring
ProgressFunc func(current, total int64, message string)
// DryRun indicates if this is a dry run operation
DryRun bool
// DryRunMode specifies the dry run mode: "all" or "upload"
DryRunMode string
// Unzip indicates if ZIP files should be extracted during mirroring
Unzip bool
// PreserveZipName indicates if the ZIP filename should be preserved when extracting,
// replacing the ZIP extension with the extracted file's extension
PreserveZipName bool
// Checksum is the SHA256 checksum to verify the artifact against
// If empty, no verification is performed
Checksum string
}
MirrorOptions configures how artifacts are mirrored.
func (*MirrorOptions) Validate ¶
func (o *MirrorOptions) Validate() error
Validate validates the mirror options.
type Source ¶
type Source interface {
// List returns all available artifacts from the source
List(ctx context.Context) ([]*Artifact, error)
// Get retrieves a specific artifact by its coordinates
Get(ctx context.Context, artifact *Artifact) (io.ReadCloser, error)
// Validate checks if the source configuration is valid
Validate() error
}
Source represents a source from which artifacts can be retrieved.