config

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: 9 Imported by: 0

README

Config Package

This package provides configuration management functionality for the application.

Components

Config

The Config type represents the application's configuration:

type Config struct {
    Sources      map[string]SourceConfig
    Destinations map[string]DestinationConfig
}
SourceConfig

The SourceConfig type defines configuration for artifact sources:

type SourceConfig struct {
    Type string
    URL  string
    // Additional source-specific fields
}
DestinationConfig

The DestinationConfig type defines configuration for artifact destinations:

type DestinationConfig struct {
    Type     string
    URL      string
    User     string
    Password string
    // Additional destination-specific fields
}

Usage

Loading Configuration
config, err := config.LoadConfig("config.yaml")
if err != nil {
    log.Fatal(err)
}
Configuration File Format

Example YAML configuration:

sources:
  github:
    type: github
    url: https://github.com/owner/repo

destinations:
  jfrog:
    type: jfrog
    url: https://jfrog.example.com
    user: username
    password: password
Validating Configuration
if err := config.Validate(); err != nil {
    log.Printf("Invalid configuration: %v", err)
}

Supported Source Types

  • github: GitHub releases source
  • (Add other source types as they are implemented)

Supported Destination Types

  • jfrog: JFrog Artifactory destination
  • (Add other destination types as they are implemented)

Environment Variables

The following environment variables can be used to override configuration:

  • GITHUB_TOKEN: GitHub API token
  • JFROG_URL: JFrog Artifactory URL
  • JFROG_USER: JFrog username
  • JFROG_PASSWORD: JFrog password

Best Practices

  1. Use environment variables for sensitive information
  2. Validate configuration before use
  3. Provide meaningful error messages
  4. Use appropriate default values
  5. Document all configuration options
  6. Handle missing or invalid values gracefully
  7. Support both file-based and environment-based configuration

Documentation

Overview

Package config provides configuration management functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact = core.Artifact

Artifact is an alias for core.Artifact.

type Builder added in v0.5.6

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

Builder provides a fluent interface for building configuration.

func NewBuilder added in v0.5.6

func NewBuilder() *Builder

NewBuilder creates a new configuration builder.

func (*Builder) Build added in v0.5.6

func (b *Builder) Build() (*Config, error)

Build validates and returns the configuration.

func (*Builder) WithDestination added in v0.5.6

func (b *Builder) WithDestination(destPath, sourcePathStrip string) *Builder

WithDestination sets the destination configuration.

func (*Builder) WithRegistryCredentials added in v0.5.6

func (b *Builder) WithRegistryCredentials(creds *RegistryCredentials) *Builder

WithRegistryCredentials sets registry credentials.

func (*Builder) WithSource added in v0.5.6

func (b *Builder) WithSource(sourceURL, sourcePathStrip string) *Builder

WithSource sets the source configuration.

func (*Builder) WithViper added in v0.5.6

func (b *Builder) WithViper(prefix string, v *viper.Viper) *Builder

WithViper sets a viper instance for the given prefix.

type Config

type Config struct {
	Source      SourceConfig      `yaml:"source"`
	Destination DestinationConfig `yaml:"destination"`
	LogLevel    string            `yaml:"log_level"`
	Concurrent  int               `yaml:"concurrent"`
}

Config represents the configuration for the mirror process.

func Load

func Load(filename string) (*Config, error)

Load loads configuration from a file.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type CredentialsResolver added in v0.5.6

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

CredentialsResolver handles credential resolution from various sources.

func NewCredentialsResolver added in v0.5.6

func NewCredentialsResolver() *CredentialsResolver

NewCredentialsResolver creates a new credentials resolver.

func (*CredentialsResolver) ResolveCredentials added in v0.5.6

func (r *CredentialsResolver) ResolveCredentials(registryConfig *RegistryConfig, jfrogConfig *JFrogConfig) (*RegistryCredentials, error)

ResolveCredentials resolves registry credentials from flags and environment.

type Destination

type Destination interface {
	// Put stores an artifact in the destination
	Put(ctx context.Context, artifact *Artifact, content io.Reader) error

	// Exists checks if an artifact already exists in the destination
	Exists(ctx context.Context, artifact *Artifact) (bool, error)

	// Validate checks if the destination configuration is valid
	Validate() error
}

Destination represents a location where artifacts can be stored.

type DestinationConfig

type DestinationConfig struct {
	Type            string `yaml:"type"`
	URL             string `yaml:"url"`
	User            string `yaml:"user"`
	Password        string `yaml:"password"`
	DestPath        string `yaml:"dest_path"`
	SourcePathStrip string `yaml:"source_path_strip"`
}

DestinationConfig represents the configuration for a destination.

type JFrogConfig added in v0.5.6

type JFrogConfig struct {
	URL               string
	User              string
	Password          string
	PasswordFromStdin bool
}

JFrogConfig holds JFrog configuration parameters.

type RegistryConfig added in v0.5.6

type RegistryConfig struct {
	URL               string
	User              string
	Password          string
	Type              string
	PasswordFromStdin bool
}

RegistryConfig holds registry configuration parameters.

type RegistryCredentials added in v0.5.6

type RegistryCredentials struct {
	URL      string
	User     string
	Password string
	Type     string
}

RegistryCredentials holds registry authentication information.

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.

type SourceConfig

type SourceConfig struct {
	Type string `yaml:"type"`
	URL  string `yaml:"url"`
}

SourceConfig represents the configuration for a source.

Jump to

Keyboard shortcuts

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