config

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config contiene la configuración de la aplicación Shipwright.

Package config contiene la configuración de la aplicación Shipwright.

Index

Constants

View Source
const (
	// Default values.
	DefaultEnvironment     = "development"
	DefaultPipelineName    = "go-service"
	DefaultCoverage        = 90.0
	DefaultGoVersion       = "1.26.7"
	DefaultJavaVersion     = "17"
	DefaultRegistryBaseURL = ""
	DefaultRegistryUser    = ""
	DefaultGitProtocol     = "https"
	DefaultGitRef          = "main"
	DefaultLogLevel        = "info"
	DefaultLogFormat       = "json"
	DefaultLintTimeout     = "5m"
	DefaultDaggerTimeout   = 30 * time.Second

	// Environment prefix.
	EnvPrefix = "SHIPWRIGHT_"
)

Configuration constants.

View Source
const (
	// Pipeline configuration.
	KeyPipelineName        = "pipeline.name"
	KeyPipelineCoverage    = "pipeline.coverage"
	KeyPipelineSkipPush    = "pipeline.skip_push"
	KeyPipelineOnlyBuild   = "pipeline.only_build"
	KeyPipelineOnlyTest    = "pipeline.only_test"
	KeyPipelineVerbose     = "pipeline.verbose"
	KeyPipelineGoVersion   = "pipeline.go_version"
	KeyPipelineJavaVersion = "pipeline.java_version"

	// Registry configuration.
	KeyRegistryBaseURL = "registry.base_url"
	KeyRegistryUser    = "registry.user"
	KeyRegistryPass    = "registry.pass"
	KeyRegistryImage   = "registry.image"
	KeyRegistryTag     = "registry.tag"

	// Git configuration.
	KeyGitRepo      = "git.repo"
	KeyGitRef       = "git.ref"
	KeyGitProtocol  = "git.protocol"
	KeyGitUserEmail = "git.user_email"
	KeyGitUserName  = "git.user_name"
	KeyGitSSHKey    = "git.ssh_key"

	// Security configuration.
	KeySecurityEnableVulnCheck = "security.enable_vuln_check"
	KeySecurityEnableLinting   = "security.enable_linting"
	KeySecurityLintTimeout     = "security.lint_timeout"
	KeySecurityExcludePatterns = "security.exclude_patterns"

	// Logging configuration.
	KeyLogLevel            = "logging.level"
	KeyLogFormat           = "logging.format"
	KeyLogSamplingEnable   = "logging.sampling_enable"
	KeyLogSamplingRate     = "logging.sampling_rate"
	KeyLogSamplingInterval = "logging.sampling_interval"

	// Release configuration.
	KeyReleaseEnabled        = "release.enabled"
	KeyReleaseUseGoreleaser  = "release.use_goreleaser"
	KeyReleaseBuildTargets   = "release.build_targets"
	KeyReleaseArchiveFormats = "release.archive_formats"
	KeyReleaseChecksum       = "release.checksum"
	KeyReleaseSign           = "release.sign"

	// Dagger configuration.
	KeyDaggerLogOutput = "dagger.log_output"
	KeyDaggerTimeout   = "dagger.timeout"
)

Configuration key constants for consistent access.

View Source
const (
	// MaxStepTimeout is the maximum allowed timeout for a step (2 hours)
	MaxStepTimeout = 2 * time.Hour
	// DefaultStepTimeout is the default timeout for steps (5 minutes)
	DefaultStepTimeout = 5 * time.Minute
	// DefaultStepRetries is the default number of retries for steps
	DefaultStepRetries = 0
)

Variables

View Source
var (
	ErrPipelineNameRequired    = errors.New("pipeline name is required")
	ErrRegistryBaseURLRequired = errors.New("registry base URL is required")
	ErrGoVersionRequired       = errors.New("go version is required")
	ErrInvalidCoverage         = errors.New("coverage must be between 0 and 100")
)

Static errors for err113 compliance.

View Source
var ErrNoPort = Error{errors.New("PORT is not defined")}

ErrNoPort when a port number for the application is not set

Functions

func TestConfigLoading

func TestConfigLoading(_ *testing.T)

func ValidateEnvironment

func ValidateEnvironment(env string) error

ValidateEnvironment validates that the environment is one of the allowed values. Valid values: "dev", "development", "staging", "production", "prod".

func ValidateGitRepoURL

func ValidateGitRepoURL(repoURL string) error

ValidateGitRepoURL validates that the Git repository URL has a valid format. It supports both HTTPS (https://host/user/repo.git) and SSH (git@host:user/repo.git) formats.

func ValidateGoVersion

func ValidateGoVersion(version string) error

ValidateGoVersion validates that the Go version follows semantic versioning format. It accepts X.Y or X.Y.Z formats (e.g., "1.25" or "1.25.5").

func ValidateRegistryURL

func ValidateRegistryURL(registryURL string) error

ValidateRegistryURL validates that the registry URL has a valid format. It accepts URLs with or without schemes. If no scheme is provided, https:// is assumed. This maintains backward compatibility with existing configurations.

Types

type Config

type Config struct {
	Environment string                    `koanf:"environment"`
	Pipeline    PipelineConfig            `koanf:"pipeline"`
	Registry    RegistryConfig            `koanf:"registry"`
	Git         GitConfig                 `koanf:"git"`
	Security    SecurityConfig            `koanf:"security"`
	Logging     LoggingConfig             `koanf:"logging"`
	Release     ReleaseConfig             `koanf:"release"`
	Dagger      DaggerConfig              `koanf:"dagger"`
	Plugins     map[string]map[string]any `koanf:"plugins"`
}

Config provides a simplified configuration interface with sane defaults.

func New

func New() (*Config, error)

New creates a new configuration with the following precedence: 1. Environment variables (SHIPWRIGHT_*) 2. Default values.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type ConfigurationWrapper

type ConfigurationWrapper struct {
	*Config
}

ConfigurationWrapper wraps Config to implement interfaces.Configuration.

func NewConfigurationWrapper

func NewConfigurationWrapper() (*ConfigurationWrapper, error)

NewConfigurationWrapper creates a new configuration wrapper.

func (*ConfigurationWrapper) All

func (cw *ConfigurationWrapper) All() map[string]any

All returns all configuration as map.

func (*ConfigurationWrapper) Environment

func (cw *ConfigurationWrapper) Environment() string

Environment returns the environment.

func (*ConfigurationWrapper) Get

func (cw *ConfigurationWrapper) Get(key string) any

Get gets an interface value.

func (*ConfigurationWrapper) GetBool

func (cw *ConfigurationWrapper) GetBool(key string) bool

GetBool gets a bool value using map lookup for better performance.

func (*ConfigurationWrapper) GetConfigSummary

func (cw *ConfigurationWrapper) GetConfigSummary() string

GetConfigSummary returns a summary of the configuration.

func (*ConfigurationWrapper) GetDuration

func (cw *ConfigurationWrapper) GetDuration(key string) time.Duration

GetDuration gets a duration value using map lookup for better performance.

func (*ConfigurationWrapper) GetFloat

func (cw *ConfigurationWrapper) GetFloat(key string) float64

GetFloat gets a float value using map lookup for better performance.

func (*ConfigurationWrapper) GetInt

func (cw *ConfigurationWrapper) GetInt(key string) int

GetInt gets an int value using map lookup for better performance.

func (*ConfigurationWrapper) GetString

func (cw *ConfigurationWrapper) GetString(key string) string

GetString gets a string value using map lookup for better performance.

func (*ConfigurationWrapper) Has

func (cw *ConfigurationWrapper) Has(key string) bool

Has checks if a key exists.

func (*ConfigurationWrapper) Load

func (cw *ConfigurationWrapper) Load() error

Load loads the configuration.

func (*ConfigurationWrapper) LoadWithDefaults

func (cw *ConfigurationWrapper) LoadWithDefaults(_ map[string]any) error

LoadWithDefaults loads configuration with defaults.

func (*ConfigurationWrapper) Logging

Logging returns logging configuration.

func (*ConfigurationWrapper) Pipeline

Pipeline returns pipeline configuration.

func (*ConfigurationWrapper) Registry

Registry returns registry configuration.

func (*ConfigurationWrapper) Security

Security returns security configuration.

func (*ConfigurationWrapper) Set

func (cw *ConfigurationWrapper) Set(key string, value any)

Set sets a value.

type DaggerConfig

type DaggerConfig struct {
	LogOutput bool          `koanf:"log_output"`
	Timeout   time.Duration `koanf:"timeout"`
}

DaggerConfig defines Dagger configuration.

type Error

type Error struct {
	Err error
}

Error is the config package's error type if an environment variable is missing

func (Error) Error

func (e Error) Error() string

Error ...

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the underlying error for go error catching logic

type GitConfig

type GitConfig struct {
	Repo      string `koanf:"repo"`
	Ref       string `koanf:"ref"`
	Protocol  string `koanf:"protocol"`
	UserEmail string `koanf:"user_email"`
	UserName  string `koanf:"user_name"`
	SSHKey    string `koanf:"ssh_key"`
}

GitConfig defines Git configuration.

type LoggingConfig

type LoggingConfig struct {
	Level            string        `koanf:"level"`
	Format           string        `koanf:"format"`
	SamplingEnable   bool          `koanf:"sampling_enable"`
	SamplingRate     float64       `koanf:"sampling_rate"`
	SamplingInterval time.Duration `koanf:"sampling_interval"`
}

LoggingConfig defines logging configuration.

type PipelineConfig

type PipelineConfig struct {
	Name        string  `koanf:"name"`
	Environment string  `koanf:"environment"`
	Coverage    float64 `koanf:"coverage"`
	SkipPush    bool    `koanf:"skip_push"`
	OnlyBuild   bool    `koanf:"only_build"`
	OnlyTest    bool    `koanf:"only_test"`
	Verbose     bool    `koanf:"verbose"`
	GoVersion   string  `koanf:"go_version"`
	JavaVersion string  `koanf:"java_version"`
}

PipelineConfig defines pipeline configuration.

type RegistryConfig

type RegistryConfig struct {
	BaseURL string `koanf:"base_url"`
	User    string `koanf:"user"`
	Pass    string `koanf:"pass"`
	Image   string `koanf:"image"`
	Tag     string `koanf:"tag"`
}

RegistryConfig defines container registry configuration.

type ReleaseConfig

type ReleaseConfig struct {
	Enabled        bool     `koanf:"enabled"`
	UseGoreleaser  bool     `koanf:"use_goreleaser"`
	BuildTargets   []string `koanf:"build_targets"`
	ArchiveFormats []string `koanf:"archive_formats"`
	Checksum       bool     `koanf:"checksum"`
	Sign           bool     `koanf:"sign"`
}

ReleaseConfig defines release configuration.

type SecurityConfig

type SecurityConfig struct {
	EnableVulnCheck bool     `koanf:"enable_vuln_check"`
	EnableLinting   bool     `koanf:"enable_linting"`
	LintTimeout     string   `koanf:"lint_timeout"`
	ExcludePatterns []string `koanf:"exclude_patterns"`
}

SecurityConfig defines security configuration.

type StepConfig

type StepConfig struct {
	Name    string `yaml:"name"`
	Timeout string `yaml:"timeout,omitempty"` // e.g., "5m", "1h"
	Retries int    `yaml:"retries,omitempty"`
}

StepConfig represents configuration for a single step

type YAMLConfig

type YAMLConfig struct {
	Pipeline struct {
		Name        string       `yaml:"name"`
		Environment string       `yaml:"environment"`
		Coverage    float64      `yaml:"coverage"`
		GoVersion   string       `yaml:"goVersion"`
		Steps       interface{}  `yaml:"steps"`                 // Can be []string or []StepConfig
		StepConfigs []StepConfig `yaml:"stepConfigs,omitempty"` // Detailed step configurations
	} `yaml:"pipeline"`

	Registry struct {
		BaseURL string `yaml:"baseUrl"`
		Image   string `yaml:"image"`
		User    string `yaml:"user"`
	} `yaml:"registry"`

	Security struct {
		EnableVulnCheck bool `yaml:"enableVulnCheck"`
		EnableLinting   bool `yaml:"enableLinting"`
	} `yaml:"security"`

	Release struct {
		Enabled             bool     `yaml:"enabled"`
		UseGoreleaser       bool     `yaml:"useGoreleaser"`
		CreateGithubRelease bool     `yaml:"createGithubRelease"`
		Platforms           []string `yaml:"platforms"`
	} `yaml:"release"`

	Logging struct {
		Level string `yaml:"level"`
	} `yaml:"logging"`

	Git struct {
		Protocol string `yaml:"protocol"`
	} `yaml:"git"`

	Plugins map[string]map[string]any `yaml:"plugins"`
}

YAMLConfig represents the structure of the .shipwright.yml file

type YAMLParser

type YAMLParser struct{}

YAMLParser handles parsing of YAML configuration files

func NewYAMLParser

func NewYAMLParser() *YAMLParser

NewYAMLParser creates a new YAML parser

func (*YAMLParser) ApplyToConfiguration

func (p *YAMLParser) ApplyToConfiguration(yamlConfig *YAMLConfig, config interfaces.Configuration) error

ApplyToConfiguration applies YAML config to the main configuration

func (*YAMLParser) FindConfigFile

func (p *YAMLParser) FindConfigFile() (string, error)

FindConfigFile looks for configuration files in common locations

func (*YAMLParser) GetStepRetries

func (p *YAMLParser) GetStepRetries(yamlConfig *YAMLConfig, stepName string) int

GetStepRetries returns the number of retries for a step from configuration.

func (*YAMLParser) GetStepTimeout

func (p *YAMLParser) GetStepTimeout(yamlConfig *YAMLConfig, stepName string) (time.Duration, error)

GetStepTimeout returns the timeout for a step from configuration. It checks stepConfigs first, then falls back to defaults.

func (*YAMLParser) GetSteps

func (p *YAMLParser) GetSteps(yamlConfig *YAMLConfig) []string

GetSteps returns the list of steps from YAML config

func (*YAMLParser) ParseFile

func (p *YAMLParser) ParseFile(filePath string) (*YAMLConfig, error)

ParseFile parses a YAML configuration file

func (*YAMLParser) ValidateConfig

func (p *YAMLParser) ValidateConfig(yamlConfig *YAMLConfig) error

ValidateConfig validates the YAML configuration

Jump to

Keyboard shortcuts

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