Documentation
¶
Overview ¶
Package settings reads the user's two settings files - <config home>/.env and <config home>/authama.json - into the process environment at start-up.
Every setting authama has is an AUTHAMA_* environment variable (see envnames). The files are two more ways to supply them, and the order is:
command-line flags > the real environment > .env > authama.json > defaults
That order is kept by construction: a file only ever sets a variable the environment does not already have (under either its current or legacy name), .env is applied before authama.json, and flags are read by each command ahead of the variable. The tool's own state - the history database, logs, snapshots, bundles, the lock - is not configuration and lives apart, in the state home (see paths).
Index ¶
Constants ¶
const ( SectionHypervisors = "hypervisors" SectionDevboxes = "devboxes" )
The structured sections: JSON-only settings with no environment variable.
const SchemaURL = "https://raw.githubusercontent.com/simtabi/authama/main/docs/schema/authama.schema.json"
SchemaURL is where the published JSON Schema for authama.json lives.
const Version = 1
Version is the authama.json format version this build reads.
Variables ¶
var Specs = []Spec{ {Section: "paths", Name: "state_dir", Env: envnames.StateDir, Kind: KindPath, Default: "$XDG_STATE_HOME/authama or ~/.local/state/authama", Doc: "Where authama keeps its own state: the history database and audit log, snapshots, bundles, the lock and caches."}, {Section: "paths", Name: "age_identity_file", Env: envnames.AgeIdentityFile, Kind: KindPath, Doc: "The age identity (private key) `ssh restore` decrypts bundles with."}, {Section: "paths", Name: "tokens_config", Env: envnames.TokensConfig, Kind: KindPath, Default: "./authama-tokens.json, else <config home>/tokens.json", Doc: "The token config: which environment variables build which registry credential."}, {Section: "paths", Name: "tokens_catalog", Env: envnames.TokensCatalog, Kind: KindPath, Default: "the built-in catalog", Doc: "A catalog.json to use instead of the built-in token services and providers."}, {Section: "backup", Name: "age_recipient", Env: envnames.AgeRecipient, Kind: KindString, Doc: "The age recipient (public key) bundles are encrypted to. Required for `ssh bundle` and the backups destructive commands take first."}, {Section: "backup", Name: "snapshot_retain", Env: envnames.SnapshotRetain, Kind: KindInt, Min: 1, Default: "10", Doc: "How many ~/.ssh snapshots to keep."}, {Section: "backup", Name: "old_key_max_age_days", Env: envnames.OldKeyMaxAgeDays, Kind: KindInt, Min: 0, Default: "90", Doc: "Days an archived predecessor key may stay before doctor flags it; 0 turns the check off."}, {Section: "ssh", Name: "auto_pin", Env: envnames.AutoPin, Kind: KindBool, Default: "true", Doc: "Pin a new host's key on first use (trust on first use) when a profile is minted."}, {Section: "git", Name: "mode", Env: envnames.GitMode, Kind: KindEnum, Enum: []string{"profile", "ssh", "https"}, Default: "the manifest's defaults.git.mode, else profile", Doc: "How `ssh git` rewrites remotes."}, {Section: "tokens", Name: "docker_creds_store", Env: envnames.DockerCredsStore, Kind: KindEnum, Enum: []string{"login", "refuse"}, Default: "ask at a terminal, else refuse", Doc: "What to do with registries Docker keeps in a credential store: store them with `docker login` or refuse and warn."}, {Section: "history", Name: "enabled", Env: envnames.History, Kind: KindBool, Default: "true", Doc: "Record every change in the history database (`authama history`)."}, {Section: "notifications", Name: "desktop", Env: envnames.Notifications, Kind: KindBool, Default: "true", Doc: "Show desktop notifications for keys due for rotation and dangling keys."}, {Section: "vm", Name: "hypervisors", Env: envnames.VMHypervisors, Kind: KindString, Default: "every built-in driver and every custom one in the hypervisors section", Doc: "The hypervisors you have and use, comma-separated (e.g. \"parallels,vmpal\"). `ssh vm list`, `ssh vm sync`, doctor and the web UI query only these; a VM host on another hypervisor is reported, never changed."}, {Section: "vm", Name: "prune_gone", Env: envnames.VMPruneGone, Kind: KindBool, Default: "true", Doc: "Let `ssh vm sync` remove the host entry (never its key files) and Docker context of a VM its hypervisor no longer has. Off: sync only reports it."}, {Section: "vm", Name: "repin_changed", Env: envnames.VMRepin, Kind: KindBool, Default: "false", Doc: "Let `ssh vm sync` replace a VM host's known_hosts pin when the guest's host key changed (a rebuilt VM), as `--repin` does. Off: sync reports it."}, }
Specs is every setting authama.json can hold, in documentation order. The published schema is generated from it (TestSchemaIsCurrent).
Functions ¶
func Schema ¶
Schema renders the JSON Schema (draft 2020-12) for authama.json from Specs. docs/schema/authama.schema.json is this output; a test keeps them equal.
func Starter ¶
func Starter() []byte
Starter is the authama.json `settings init` writes: the schema reference and the version, nothing else, so every setting keeps its default until the user sets it.
Types ¶
type ApplyResult ¶
type ApplyResult struct {
Set, Kept []string // variables
}
ApplyResult is what applying authama.json did.
type Devbox ¶ added in v0.1.3
type Devbox struct {
Profile string `json:"profile"`
Hypervisor string `json:"hypervisor"`
VM string `json:"vm"`
User string `json:"user"`
// Key is the key name the host uses. When the profile has no such key and
// ~/.ssh/<key> is a loose keypair, sync adopts that pair into the profile.
Key string `json:"key,omitempty"`
// DockerContext keeps a Docker context ssh://<alias> (default true).
DockerContext *bool `json:"docker_context,omitempty"`
Description string `json:"description,omitempty"`
}
Devbox declares one VM authama should keep as an SSH host: which hypervisor runs it, the VM's name there, the guest user and the key. `ssh vm sync` adds a declared devbox that is not a host yet, and adopts a declared loose key (copying it, never moving it) when the profile has no key of that name.
func (Devbox) WantsDockerContext ¶ added in v0.1.3
WantsDockerContext is DockerContext, defaulting to true.
type DotenvResult ¶
type DotenvResult struct {
Path string
Present bool
// Refused is set when the file was not read because others can read it.
Refused string
// Set lists the variables taken from the file; Kept those already in the
// environment, which wins.
Set, Kept []string
Warnings []string
}
DotenvResult is what loading a .env file did.
func LoadDotenv ¶
func LoadDotenv(path string, env Env) DotenvResult
LoadDotenv reads path into the environment without replacing anything already set there, under either spelling of a setting. A missing file is not an error. On Unix a file that group or others can read is refused, as doctor flags it: it is where tokens live. Malformed lines are skipped with a warning.
type File ¶
type File struct {
Path string
Values map[string]string
// VM holds the structured "hypervisors" and "devboxes" sections, which
// have no environment variable.
VM VMConfig
}
File is a parsed authama.json: the dotted key of each setting it sets, with the value as the environment variable will carry it.
func (*File) Apply ¶
func (f *File) Apply(env Env) ApplyResult
Apply puts the file's values into the environment, never over a variable already set (by the environment or by .env), under either spelling. Paths starting with ~ are expanded.
type Pair ¶
Pair is one KEY=value assignment read from a .env file.
func ParseDotenv ¶
ParseDotenv reads .env syntax: KEY=value lines, blank lines and # comments, an optional `export ` prefix, and values that are bare, "double-quoted" (with \n, \t, \", \\ and \$ escapes) or 'single-quoted' (literal). A bare value ends at a # preceded by whitespace. A line that is none of these is returned as a warning naming its line number - never its content, which may be a secret - and skipped.
type Spec ¶
type Spec struct {
Section, Name string
Env string
Kind Kind
Enum []string
Min int
Default string
Doc string
}
Spec is one user setting: its place in authama.json and the variable it supplies.
type VMConfig ¶ added in v0.1.3
type VMConfig struct {
Hypervisors map[string]hypervisor.CommandSpec `json:"hypervisors,omitempty"`
Devboxes map[string]Devbox `json:"devboxes,omitempty"`
}
VMConfig is the "hypervisors" and "devboxes" sections.
func LoadVMConfig ¶ added in v0.1.3
LoadVMConfig reads the structured sections of the authama.json at path and registers its custom hypervisors. A missing file is an empty config.
func (VMConfig) DevboxAliases ¶ added in v0.1.3
DevboxAliases returns the declared aliases, sorted.
type ValidationError ¶
ValidationError lists every problem found in an authama.json.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string