settings

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 14 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 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: "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

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

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 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
}

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 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