config

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const LegacyMirrorConfig = "mirror.yaml"

LegacyMirrorConfig is the removed mirror store config file name.

Variables

View Source
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.

View Source
var ErrLegacyMirrorConfig = errors.New(LegacyMirrorConfig + " is no longer read")

ErrLegacyMirrorConfig reports a mirror.yaml at the mirror root.

View Source
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

func CheckMirrorRoot(root string) error

CheckMirrorRoot fails when the mirror root still carries a mirror.yaml, naming the migration: its blocks move into the patchy config.

func Merge

func Merge(base, overlay map[string]any) map[string]any

Merge layers overlay onto base and returns the result, leaving both inputs untouched: maps merge recursively, lists and scalars in overlay replace base's wholesale, and an explicit nil (a YAML/JSON null) deletes the key — the way a project drops a value inherited from /etc or $HOME.

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

func (f *File) BuildConfig() (*spec.Config, *build.Spec, error)

BuildConfig returns the shared registries, signing and scan blocks (resolved) plus the validated build spec.

func (*File) BuildPlanConfig added in v0.12.1

func (f *File) BuildPlanConfig() (*spec.Config, *build.Spec, error)

BuildPlanConfig is BuildConfig for a run that never contacts a registry (`patchy build --dry-run`): registries may be absent, so CI and a workstation can build and scan with no registry configured at all.

func (*File) MirrorConfig

func (f *File) MirrorConfig() (*spec.Config, error)

MirrorConfig assembles and validates the mirror's view: the shared registries, signing and scan blocks plus the mirror: block's update and rewrites. A config without registries fails here, never at load.

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

func Load(o Options) (*Loaded, error)

Load finds, decodes, checks and merges every config layer. No file at all is an empty config, not an error.

func (*Loaded) HasProjectLayer

func (l *Loaded) HasProjectLayer() bool

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.

func (*Loaded) Path

func (l *Loaded) Path(p string) string

Path resolves a config path (mirror.directory, a dockerfile, a manifests path) against the working directory; every layer's relative paths mean the same thing.

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.

Jump to

Keyboard shortcuts

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