Documentation
¶
Overview ¶
Package config loads the layered patchy configuration the cluster-free command groups (dev, mirror, build) share: one file shape, merged from up to seven locations, least to most preferred —
/etc/patchy/config.<ext> $HOME/.config/patchy/config.<ext> <workdir>/mise/patchy.<ext> <workdir>/patchy/config.<ext> <workdir>/.mise/patchy.<ext> <workdir>/.patchy/config.<ext> <workdir>/patchy.<ext>
where <ext> is yaml, yml, json or toml. Each layer decodes to a generic map; maps merge recursively, lists and scalars are replaced whole by the more specific layer, and an explicit null deletes an inherited key. The merge is deliberately not viper's: viper lowercases every key, which would corrupt user-defined keys like build args.
Every layer is strictly decoded on its own first, so an unknown key is reported against the file that carries it; the merged map is then decoded once more into File. Semantic validation is per verb (File's MirrorConfig and BuildConfig accessors): a config with no registries is fine for the dev commands.
The engines never see files: internal/mirror and internal/build receive the typed structs assembled here, which keeps mirror validate deterministic and the engines testable without a filesystem layout.
Index ¶
Constants ¶
const LegacyMirrorConfig = "mirror.yaml"
LegacyMirrorConfig is the removed mirror store config file name.
Variables ¶
var ErrAmbiguous = errors.New("ambiguous config")
ErrAmbiguous reports one location holding the config in more than one format; the CLI treats it as a usage error.
var ErrLegacyMirrorConfig = errors.New(LegacyMirrorConfig + " is no longer read")
ErrLegacyMirrorConfig reports a mirror.yaml at the mirror root.
var Extensions = []string{"yaml", "yml", "json", "toml"}
Extensions lists the accepted config formats, in the order a location is probed. More than one present at one location is ambiguous.
Functions ¶
func CheckMirrorRoot ¶
CheckMirrorRoot fails when the mirror root still carries a mirror.yaml, naming the migration: its blocks move into the patchy config.
Types ¶
type Dev ¶
type Dev struct {
Addr string `yaml:"addr"`
Name string `yaml:"name"`
Secret string `yaml:"secret"`
SecretFile string `yaml:"secret-file"`
MinSeverity string `yaml:"min-severity"`
EnhanceURL string `yaml:"enhance-url"`
EnhanceTimeout time.Duration `yaml:"enhance-timeout"`
ResolveURL string `yaml:"resolve-url"`
ResolveTimeout time.Duration `yaml:"resolve-timeout"`
ResolveDelay time.Duration `yaml:"resolve-delay"`
NoAutoResolve bool `yaml:"no-auto-resolve"`
}
Dev is the dev: block: one key per dev-command flag. The CLI reads the values through viper (flag > env > file > default); the types here exist so an unknown or mistyped key fails against the file that carries it.
type File ¶
type File struct {
// Registries are where mirror and build publish; every entry goes to
// every registry (or the --registry selection).
Registries []spec.Registry `yaml:"registries"`
// Signing is the default signing block; a registry's own replaces it.
Signing spec.Signing `yaml:"signing"`
// Scan holds the scanner roster and the defaults every entry's scan
// block overrides field by field.
Scan spec.Scan `yaml:"scan"`
Mirror Mirror `yaml:"mirror"`
Build build.Spec `yaml:"build"`
Dev Dev `yaml:"dev"`
}
File is the patchy config's shape: the blocks mirror and build share at the top level, then one block per command group.
func (*File) BuildConfig ¶
BuildConfig returns the shared registries, signing and scan blocks (resolved) plus the validated build spec.
type Loaded ¶
type Loaded struct {
// File is the merged config, strictly decoded.
File *File
// Merged is the merged generic map — what viper layers flags and
// environment over for the flag-backed keys.
Merged map[string]any
// Sources lists the loaded layers in precedence order (least
// preferred first), as display paths.
Sources []string
// Warnings are non-fatal findings for narration (a legacy
// .patchy.yaml that is no longer read).
Warnings []string
// Workdir is the absolute working directory relative paths resolve
// against.
Workdir string
// contains filtered or unexported fields
}
Loaded is a resolved configuration.
func Load ¶
Load finds, decodes, checks and merges every config layer. No file at all is an empty config, not an error.
func (*Loaded) HasProjectLayer ¶
HasProjectLayer reports whether any loaded layer lives in the working directory (as opposed to /etc or $HOME) — mirror add scaffolds a project patchy.yaml only when none does.
type Mirror ¶
type Mirror struct {
// Directory is the mirror store root, relative to the working
// directory (default: the working directory). Also --directory/-C.
Directory string `yaml:"directory"`
// Workers bounds concurrent registry operations (also --workers).
Workers int `yaml:"workers"`
// Update tunes the tracked-tag soak window.
Update spec.Update `yaml:"update"`
// SourceRegistryRewrites reroutes upstream pulls (e.g. through a
// pull-through cache); recorded sources keep the canonical path.
SourceRegistryRewrites map[string]string `yaml:"sourceRegistryRewrites"`
}
Mirror is the mirror: block.
type Options ¶
type Options struct {
// Workdir is the project root the four workdir locations hang off
// and relative config paths resolve against (default: os.Getwd).
Workdir string
// Home is the user's home (default: os.UserHomeDir; none skips the
// user layer).
Home string
// SystemDir is the system-wide config directory (default /etc/patchy).
SystemDir string
}
Options locates the config roots. Every field is injectable so tests can point the search at temp directories; zero values resolve to the real process working directory, the user's home, and /etc/patchy.