config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and validates siphon's config file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path() string

Path returns the absolute path to siphon's config file. Honors $SIPHON_CONFIG_HOME first, then $XDG_CONFIG_HOME, then the OS default.

func Save

func Save(cfg *Config) error

Save writes cfg to the configured Path, creating directories as needed. Note: Name is yaml:"-" so it is not serialized — the map key is the canonical source of a profile's name on disk.

Types

type AuditConfig

type AuditConfig struct {
	Enabled bool   `yaml:"enabled"`
	Path    string `yaml:"path,omitempty"`
}

AuditConfig controls the append-only audit log of destructive operations. Disabled by default; Path defaults to <state>/siphon/audit.log when empty.

type Config

type Config struct {
	Version   int                      `yaml:"version"`
	Defaults  Defaults                 `yaml:"defaults"`
	Storage   StorageConfig            `yaml:"storage"`
	Audit     AuditConfig              `yaml:"audit"`
	Telemetry TelemetryConfig          `yaml:"telemetry"`
	Secrets   SecretsConfig            `yaml:"secrets"`
	Profiles  map[string]ProfileConfig `yaml:"profiles"`
	Groups    map[string]GroupConfig   `yaml:"groups"`
}

func Load

func Load() (*Config, error)

Load reads and parses the config file. Returns an empty Config if the file does not exist (first-run case). Env-var interpolation (${VAR}) is performed BEFORE YAML parsing so values resolve to their interpolated form in the typed struct.

func (*Config) EffectiveRetention

func (c *Config) EffectiveRetention(profile string) *RetentionConfig

EffectiveRetention returns the RetentionConfig for a profile: its own block if present, else the defaults block, else nil (keep everything). The profile block replaces the defaults wholesale — it is not merged.

type Defaults

type Defaults struct {
	DumpDir       string           `yaml:"dump_dir"`
	Jobs          int              `yaml:"jobs"`
	Compression   int              `yaml:"compression"`
	SecretBackend string           `yaml:"secret_backend"`
	Retention     *RetentionConfig `yaml:"retention,omitempty"`
}

type GFSConfig

type GFSConfig struct {
	Daily   int `yaml:"daily,omitempty"`
	Weekly  int `yaml:"weekly,omitempty"`
	Monthly int `yaml:"monthly,omitempty"`
}

GFSConfig is the YAML shape of a grandfather-father-son rule.

type GroupConfig

type GroupConfig struct {
	Color              string `yaml:"color"`
	Require2FA         bool   `yaml:"require_2fa"`
	ConfirmDestructive bool   `yaml:"confirm_destructive"`
	// TOTPSecret is the base32 RFC-6238 secret shared with the operator's
	// authenticator app, consulted when Require2FA is set. It is a secret-ref
	// (e.g. env:SIPHON_PROD_TOTP), so the plaintext secret never lives in config.
	TOTPSecret string `yaml:"totp_secret,omitempty"`
}

type ProfileConfig

type ProfileConfig struct {
	Name      string           `yaml:"-"`
	Driver    string           `yaml:"driver"`
	Host      string           `yaml:"host"`
	Port      int              `yaml:"port"`
	User      string           `yaml:"user"`
	Password  string           `yaml:"password"` // may be a SecretRef like ${VAR} or keychain://...
	Database  string           `yaml:"database"`
	SSLMode   string           `yaml:"sslmode"`
	Group     string           `yaml:"group"`
	Retention *RetentionConfig `yaml:"retention,omitempty"` // overrides Defaults.Retention wholesale
	Tunnel    *TunnelConfig    `yaml:"tunnel,omitempty"`    // optional SSH bastion for reaching this DB
}

ProfileConfig is the unresolved on-disk form of a connection profile. Name is NOT read from YAML — it is populated by Load() from the map key in Config.Profiles so callers don't need to thread the name separately.

type RetentionConfig

type RetentionConfig struct {
	KeepLast int       `yaml:"keep_last,omitempty"` // keep the N newest chains
	MaxAge   string    `yaml:"max_age,omitempty"`   // Go duration string, e.g. "720h"
	GFS      GFSConfig `yaml:"gfs,omitempty"`       // grandfather-father-son tiers
}

RetentionConfig is the YAML shape of a retention policy. It lives in config (not dumps) so config stays a leaf; the app layer maps it to a dumps.RetentionPolicy. A nil pointer (block omitted) means "keep everything". A profile's retention block REPLACES the defaults block wholesale — it is not field-merged — so a profile's policy is read as a single coherent rule set.

func (*RetentionConfig) Validate

func (r *RetentionConfig) Validate() error

Validate rejects nonsensical retention settings (negative counts, an unparseable duration). An all-zero policy is valid and means "keep everything", so an empty or misconfigured block can never wipe the catalog.

type SecretsConfig

type SecretsConfig struct {
	AWSSM       bool   `yaml:"awssm"`                  // enable the awssm:// backend
	AWSSMRegion string `yaml:"awssm_region,omitempty"` // optional; defaults to the AWS chain's region
}

SecretsConfig enables optional secret backends. The keychain:// backend is always available (no config, no network). AWS Secrets Manager (awssm://) is gated by AWSSM because constructing it loads AWS config; off by default so a machine without AWS creds doesn't pay that cost or fail at startup.

type StorageConfig

type StorageConfig struct {
	Type     string `yaml:"type"`               // "local" | "s3" (default "local")
	Bucket   string `yaml:"bucket,omitempty"`   // s3: target bucket
	Prefix   string `yaml:"prefix,omitempty"`   // s3: optional key prefix within the bucket
	Region   string `yaml:"region,omitempty"`   // s3: AWS region
	Endpoint string `yaml:"endpoint,omitempty"` // s3: custom endpoint for S3-compatible services (MinIO, R2)
}

StorageConfig selects where the dump catalog physically lives. Type "local" (or empty, the default) uses Defaults.DumpDir on the local filesystem. Type "s3" stores dumps in an S3 or S3-compatible bucket. Credentials are NOT held here — the S3 SDK resolves them from the standard chain (env vars, shared config, instance role), so the config file stays free of secrets.

func (StorageConfig) Validate

func (s StorageConfig) Validate() error

Validate checks the storage block for internal consistency. It is called by Load so a malformed storage config fails fast with a clear message rather than surfacing as an obscure runtime error on first backup.

type TelemetryConfig

type TelemetryConfig struct {
	Enabled bool   `yaml:"enabled"`
	Path    string `yaml:"path,omitempty"`
}

TelemetryConfig controls opt-in aggregate operational metrics (per-op counts and error tallies — never identifying data). Disabled by default; Path defaults to <state>/siphon/telemetry.json when empty.

type TunnelConfig

type TunnelConfig struct {
	Bastion   string `yaml:"bastion"`              // [user@]host[:port] of the SSH jump host
	LocalPort int    `yaml:"local_port,omitempty"` // local forward port (defaults to the DB port)
}

TunnelConfig describes an SSH bastion through which this profile's database is reached. `siphon tunnel <profile>` opens an `ssh -L` local forward from LocalPort to the profile's Host:Port via Bastion, using the system ssh client (so the user's ssh config, keys, and agent apply). It is delegation, not a reimplementation of SSH.

Jump to

Keyboard shortcuts

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