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 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."}, }
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.
Types ¶
type ApplyResult ¶
type ApplyResult struct {
Set, Kept []string // variables
}
ApplyResult is what applying authama.json did.
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 ¶
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 ValidationError ¶
ValidationError lists every problem found in an authama.json.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string