settings

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 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 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

View Source
const (
	SectionHypervisors = "hypervisors"
	SectionDevboxes    = "devboxes"
)

The structured sections: JSON-only settings with no environment variable.

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

View Source
const Version = 1

Version is the authama.json format version this build reads.

Variables

View Source
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: "export", Name: "save_to", Env: envnames.ExportSaveTo, Kind: KindEnum, Enum: []string{"user", "manifest"}, Default: "user",
		Doc: "Where a saved export selection goes: user keeps it in this account's state (private to you), manifest in the manifest's defaults.export, so it travels with the manifest. Both are read; on a name in both, yours wins."},
	{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: "history", Name: "permanent", Env: envnames.HistoryPermanent, Kind: KindBool, Default: "false",
		Doc: "Keep the history for good: `history reset` and the web UI's Start the history again refuse, so the record of every change cannot be set aside."},
	{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: "multiplex", Env: envnames.VMMultiplex, Kind: KindBool, Default: "true",
		Doc: "Share one SSH connection per VM host (ControlMaster, kept 10 minutes), so a run of docker or ssh commands asks the hypervisor for the address once. Not on Windows, whose OpenSSH has no ControlMaster."},
	{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."},
	{Section: "api", Name: "enabled", Env: envnames.API, Kind: KindBool, Default: "false",
		Doc: "Serve the read API at /api/v1/ on `serve`, for programs holding an API token (`authama api token create`). It reads only: profiles, keys, hosts, which tokens are set (never a secret), the history, the event feed and doctor. Off: /api/v1/ is not served."},
	{Section: "webhooks", Name: "enabled", Env: envnames.Webhooks, Kind: KindBool, Default: "false",
		Doc: "Have `serve` send each new event (a change finished, a watched file changed) to the endpoints added with `authama webhook add`, signed as Standard Webhooks do. Off: nothing is sent; `authama webhook deliver` still sends by hand."},
	{Section: "webhooks", Name: "allow_private", Env: envnames.WebhooksAllowPrivate, Kind: KindBool, Default: "false",
		Doc: "Let an endpoint be on this machine or a private network (loopback, 10/8, 172.16/12, 192.168/16, link-local), and use plain http on loopback. Off: only https to public addresses, so a webhook cannot be aimed at services behind your firewall."},
	{Section: "mcp", Name: "enabled", Env: envnames.MCP, Kind: KindBool, Default: "false",
		Doc: "Let `authama mcp` serve the Model Context Protocol over stdio, for an AI client that starts it. Its tools read only, as the API does. Off: `authama mcp` refuses to start."},
	{Section: "web", Name: "addr", Env: envnames.WebAddr, Kind: KindString, Default: "127.0.0.1",
		Doc: "The address `serve` listens on. A non-loopback address still needs --allow-remote."},
	{Section: "web", Name: "port", Env: envnames.WebPort, Kind: KindInt, Min: 1, Default: "7822",
		Doc: "The port `serve` listens on first. When it is taken the next free one is used, as with the default; only --port makes a taken port an error."},
	{Section: "web", Name: "base_path", Env: envnames.WebBasePath, Kind: KindString, Default: "/",
		Doc: "A path the web UI is served under, such as /authama, so it can sit behind a reverse proxy beside other sites. Every link, form and redirect carries it."},
	{Section: "web", Name: "menu_export", Env: envnames.WebMenuExport, Kind: KindBool, Default: "true",
		Doc: "Show Export in the web UI's menu: every list in any format, filtered and with the columns you choose. Off hides the menu item; the page and each list's download stay."},
	{Section: "web", Name: "auto_restart", Env: envnames.WebAutoRestart, Kind: KindBool, Default: "true",
		Doc: "Restart `serve` by itself when its binary is rebuilt or reinstalled (make install), on the same address with the same sign-in, and reload every open page into the new build; a page with unsaved input offers Reload instead. Off: a page says it is from an older build and offers Restart now."},
}

Specs is every setting authama.json can hold, in documentation order. The published schema is generated from it (TestSchemaIsCurrent).

Functions

func DotenvProblems added in v0.1.6

func DotenvProblems(path string) []string

DotenvProblems checks a .env without loading it.

func FileProblems added in v0.1.6

func FileProblems(target string, named bool) []string

FileProblems checks one settings file against the schema. named is true when the file was given on the command line, where a missing file is an error rather than "every setting at its default".

func FileValue added in v0.1.6

func FileValue(path, key string) (string, bool)

FileValue is the value authama.json at path holds for key, as the environment variable would carry it, and whether it holds one.

func Problems added in v0.1.6

func Problems(envFile, settingsFile string) []string

Problems is `settings validate` with no FILE: .env's syntax and permissions, then authama.json against the schema. An absent authama.json is not a problem. The CLI and the web UI's Validate page both read it.

func Schema

func Schema() ([]byte, error)

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 Set added in v0.1.6

func Set(path, key, value string) error

Set writes one setting into the authama.json at path, creating the file (as Starter) when there is none and keeping every other setting as it was. The value is given as it would be typed - true, 10, a path - and is checked against the setting's kind before anything is written; the whole file is checked again after, so Set never leaves a file Parse refuses.

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.

func Truthy

func Truthy(v string) bool

Truthy reads a boolean-ish variable value: 1, true, yes, on.

func Unset added in v0.1.6

func Unset(path, key string) error

Unset takes one setting out of the authama.json at path, so it goes back to its default; every other setting is kept. A setting the file does not hold is not an error.

func ValidUser added in v0.1.3

func ValidUser(u string) bool

ValidUser reports whether u is a guest user name authama will embed in the key-install script (letters, digits, '.', '_' and '-').

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) Planned added in v0.1.6

func (d Devbox) Planned() bool

Planned reports a devbox declared without a VM yet: it only keeps its key (reserved, so doctor does not call it loose) until the VM exists.

func (Devbox) WantsDockerContext added in v0.1.3

func (d Devbox) WantsDockerContext() bool

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 Env

type Env struct {
	Lookup func(string) (string, bool)
	Setenv func(string, string) error
}

Env is the process environment, injectable for tests.

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 LoadFile

func LoadFile(path string) (*File, error)

LoadFile reads and validates authama.json. A missing file is (nil, nil).

func Parse

func Parse(path string, b []byte) (*File, error)

Parse validates authama.json content.

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 Kind

type Kind string

Kind is a setting's value type.

const (
	KindString Kind = "string"
	KindPath   Kind = "path"
	KindInt    Kind = "integer"
	KindBool   Kind = "boolean"
	KindEnum   Kind = "enum"
)

type Pair

type Pair struct {
	Key   string
	Value string
	Line  int
}

Pair is one KEY=value assignment read from a .env file.

func ParseDotenv

func ParseDotenv(r io.Reader) ([]Pair, []string)

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.

func Find

func Find(key string) (Spec, bool)

Find returns the spec for a dotted key.

func (Spec) Key

func (s Spec) Key() string

Key is the dotted authama.json path, e.g. "backup.age_recipient".

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

func LoadVMConfig(path string) (VMConfig, error)

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

func (c VMConfig) DevboxAliases() []string

DevboxAliases returns the declared aliases, sorted.

func (VMConfig) PlannedKeys added in v0.1.6

func (c VMConfig) PlannedKeys() map[string]manifest.ReservedKey

PlannedKeys are the keys planned devboxes keep, as reservations keyed by the ~/.ssh file name, For naming the devbox.

type ValidationError

type ValidationError struct {
	Path     string
	Problems []string
}

ValidationError lists every problem found in an authama.json.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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