config

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfigFileMode os.FileMode = 0o644

DefaultConfigFileMode is the mode WriteFileAtomic creates a file with when the target does not already exist.

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) (string, error)

HashToken produces an argon2id hash of the given token, encoded in the PHC-style format expected by VerifyToken.

func RenameHostFile added in v1.0.38

func RenameHostFile(dir, oldID, newID string) (path string, original []byte, err error)

RenameHostFile finds the *.yaml file in dir whose parsed id equals oldID, replaces its exact "id: <oldID>" line with "id: <newID>", and atomically rewrites the file (temp file + os.Rename, same directory). It does NOT re-marshal the YAML — every other line, including comments and formatting, is preserved byte-for-byte. Returns the file's path and its ORIGINAL full content (before the rewrite), so a caller can restore it verbatim if a later step (e.g. a store migration) fails.

Fails closed rather than guessing: if no file's parsed id matches oldID, or the id line isn't found in the exact "id: <oldID>" form (e.g. it carries a trailing comment), this returns an error and touches nothing.

func VerifyToken

func VerifyToken(token, encoded string) (bool, error)

VerifyToken checks token against an argon2id PHC string.

func WriteFileAtomic added in v1.0.38

func WriteFileAtomic(path string, data []byte) error

WriteFileAtomic replaces path's contents with data via a temp file in the same directory followed by os.Rename, so a crash mid-write can never leave a truncated config file — only the old content or the new. When path already exists its mode is preserved; otherwise DefaultConfigFileMode is used.

Used for both directions of a host rename: RenameHostFile's forward write and the API handler's revert when the store migration that follows fails. The revert used a plain os.WriteFile with a hardcoded 0644 until the final review of #246 — non-atomic, and it flattened the file's mode on the way back.

Types

type APIKey

type APIKey struct {
	ID          string   `yaml:"id"`
	SecretHash  string   `yaml:"secret_hash"`
	Scopes      []string `yaml:"scopes"`
	Description string   `yaml:"description,omitempty"`
}

APIKey is one entry from auth/keys.yaml.

func ParseKeysYAML

func ParseKeysYAML(raw []byte) ([]APIKey, error)

ParseKeysYAML parses an `auth/keys.yaml` file body.

func (APIKey) HasScope

func (k APIKey) HasScope(want string) bool

HasScope returns true if the key holds the requested scope, supporting "*" wildcard suffix at the action level only ("instances:*" matches "instances:read").

type Host

type Host struct {
	ID     string            `yaml:"id"`
	Addr   string            `yaml:"addr"`              // "unix" or "user@host"
	Socket string            `yaml:"socket"`            // path on the host
	SSHKey string            `yaml:"ssh_key,omitempty"` // optional
	Labels map[string]string `yaml:"labels,omitempty"`
	// Drain, when true, makes the API refuse to *create* new instances on
	// this host. Replace-shaped writes against existing pods, lifecycle
	// ops, and reads are unaffected. Hot-reloadable via SIGHUP.
	Drain bool `yaml:"drain,omitempty"`
	// Prune is the optional per-host host-health cleanup policy. nil means "use
	// the global flag defaults". Pointer fields inside distinguish "unset"
	// (inherit default) from an explicit zero value.
	Prune *PruneConfig `yaml:"prune,omitempty"`
	// CaddyAdminAddr is the Caddy admin API address (host:port) on this host,
	// e.g. "100.64.1.2:2019". When set, the ingress controller targets this
	// address instead of the global -ingress-caddy-admin-addr default. Empty
	// means use the global default.
	CaddyAdminAddr string `yaml:"caddy_admin_addr,omitempty"`
}

Host is the in-memory representation of a single hosts/*.yaml file.

func LoadHosts

func LoadHosts(dir string) ([]Host, error)

LoadHosts reads every *.yaml in dir into a Host. Unknown fields are rejected. Duplicate IDs are an error.

type HostsDir added in v1.0.38

type HostsDir string

HostsDir is a directory of hosts/*.yaml files. Its RenameHostFile method lets it satisfy internal/api's HostFileRenamer interface without api importing config's LoadHosts internals or config importing api.

func (HostsDir) RenameHostFile added in v1.0.38

func (d HostsDir) RenameHostFile(oldID, newID string) (path string, original []byte, err error)

type Operator

type Operator struct {
	Username     string `yaml:"username"`
	PasswordHash string `yaml:"password_hash"`
}

Operator is the single-operator UI credential, parsed from the -operator-file YAML. PasswordHash is an argon2id PHC string (produce one with `podman-api hash-token <plaintext>`).

func ParseOperatorYAML

func ParseOperatorYAML(raw []byte) (Operator, error)

ParseOperatorYAML parses an operator credential file. Username defaults to "operator" when omitted; password_hash is required.

type PruneConfig

type PruneConfig struct {
	Enabled       *bool     `yaml:"enabled,omitempty"`
	Interval      *string   `yaml:"interval,omitempty"` // Go duration, e.g. "12h"
	DiskThreshold *int      `yaml:"disk_threshold_pct,omitempty"`
	Scope         *[]string `yaml:"scope,omitempty"`
	DryRun        *bool     `yaml:"dry_run,omitempty"`
}

PruneConfig is the raw per-host prune policy as parsed from hosts/*.yaml. Every field is a pointer so an omitted field inherits the global default rather than overriding it with a zero value. Resolution lives in the prune package (config must not depend on prune).

Jump to

Keyboard shortcuts

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