change

package
v3.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 38 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 change previews a change before it is made, and makes it only if what it would do has not moved since it was previewed.

A preview runs the change for real, against a private copy of the home: the config files, and from ~/.ssh only the files a snapshot may hold (config, known_hosts, public keys). It then diffs what the copy became against what is there now, so the preview is not a description of the change but the change itself, made somewhere harmless. No private key is ever copied.

Apply takes the lock, previews again under it, and runs the change on the real home only if the new preview hashes the same as the one the person confirmed. Anything that moved in between - a CLI command, another browser tab - is reported with the new preview instead of being overwritten. The lock is held only for that, never while a person reads.

Index

Constants

This section is empty.

Variables

View Source
var ErrStale = fmt.Errorf("the change would now do something different from what you confirmed: %w", mutation.ErrDeclined)

ErrStale reports a confirmation made against a preview that no longer matches what the change would do.

Functions

func Apply

func Apply(p paths.Paths, ch Change, hash string, retain int, source string) (Plan, Result, error)

Apply makes ch on p if a fresh preview under the lock still hashes to hash. On ErrStale it returns that fresh preview, for the person to confirm again.

func ApplyManifestEdit

func ApplyManifestEdit(out io.Writer, p paths.Paths) error

ApplyManifestEdit re-renders ~/.ssh/config after a command changed the manifest, and reports what moved.

The rendered config is a pure function of the manifest, so every manifest edit makes the file on disk stale - which is exactly the drift `doctor` and `diff` exist to report. Leaving that to a later reconcile meant a successful edit ended with the tool complaining about a problem it had just created, and the user being told to run a second command to finish the first. So the rule is: a command that changes the manifest renders; a command that only touches key files (keygen, rotate) changes no manifest state and does not.

This is safe to run after any edit. Rendering replaces the managed block and preserves everything around it (renderer.ComposeRootConfig), so it never disturbs hand-written config, and it is idempotent - an edit that changes no Host block writes nothing and says nothing.

func WarnDangling

func WarnDangling(out io.Writer, p paths.Paths, m *manifest.Manifest)

WarnDangling reports the blocking dangling-key states inline, right after the command that could have caused one.

Only the blocking ones, and only after the command's own output: a key nothing will ever use is worth interrupting for, while an unminted key or a stale record is doctor's business. Failing to audit is silent - this is a courtesy on the end of a command that already succeeded, not a check in its own right.

Types

type Change

type Change struct {
	Command  string // "host add"
	Args     []string
	Subjects []history.Subject
	Run      func(p paths.Paths, out io.Writer) error

	// Mints marks a change that makes a new key. Its preview mints a
	// throwaway key in the copy, which apply cannot reproduce, so public key
	// blobs and fingerprints are left out of the hash: the confirmation
	// binds to everything else the change writes, and to which keys it makes.
	Mints bool

	// NoSnapshot skips the ~/.ssh snapshot before the change, for one that
	// manages the snapshots themselves and would otherwise prune its own.
	NoSnapshot bool

	// Effects lists what the change does outside the files a preview copies
	// - snapshots it removes, modes it fixes - as lines for the preview to
	// show. They are part of the hash, so they cannot change unseen either.
	Effects func(p paths.Paths) ([]string, error)

	// OnApply is the part of a change that a copy cannot hold - a Docker
	// context, a desktop notification, an encrypted backup of private keys.
	// It runs on apply only, under the lock, after the snapshot and before
	// Run. A preview never runs it, so a change with OnApply must say what it
	// does in Effects; Preview refuses one that does not.
	OnApply func(p paths.Paths, out io.Writer) error
}

Change is one change a person can ask for. Run makes it against p, the way the CLI command does after its guard; it never takes the lock or snapshots, which Apply does around it.

func AuditNotify

func AuditNotify() Change

AuditNotify is the --notify half of `sshmgr audit --notify`: the desktop alert for keys that need attention, if one is due. It is gated by the same daily or weekly cadence, so asking twice in a day sends one.

func Bundle

func Bundle(keep int) Change

Bundle is `sshmgr bundle [--keep N]`: an age-encrypted backup of ~/.ssh and the config, written to the config home's dist/. It takes no snapshot, as the CLI's does not: it changes nothing a snapshot would hold.

func Clean

func Clean(adopt bool) Change

Clean is `sshmgr clean --yes [--adopt]`: stale pins, stale inventory records and write residue. The residue is swept by the snapshot apply takes first, as the CLI's is.

func ConfigRender

func ConfigRender() Change

ConfigRender is `sshmgr config render --yes`: migrate any legacy per-profile known_hosts into the single store, then write the config.

func DoctorFix

func DoctorFix() Change

DoctorFix is the --fix half of `sshmgr doctor --fix`: set every config-home and ~/.ssh path back to its canonical mode.

func HostAdd

func HostAdd(profile, alias string, in HostInput) Change

HostAdd is `sshmgr host add <profile> <alias> -H <hostname> -u <user> [-p] [--tag]...`.

func HostApply

func HostApply(profile string, specs []editor.HostSpec, create bool, category string) Change

HostApply is `sshmgr host apply <profile> --host <spec>... --yes`, with --create-profile or --category for a profile that does not exist yet. Each spec is `<alias> <host>[:port] <user> [role]`.

func HostDelete

func HostDelete(profile, alias string) Change

HostDelete is `sshmgr host delete <profile> <alias> --yes`: the host, its block and its pins go; its key files stay.

func HostEdit

func HostEdit(profile, alias string, in HostInput) Change

HostEdit is `sshmgr host edit <profile> <alias> [...]`.

func KeyAdd

func KeyAdd(profile, name, keyType, host string) Change

KeyAdd is `sshmgr key add <profile> <name> [--type] [--host]`: declare the key, mint it, and wire it to a host when one is named.

func KeyDelete

func KeyDelete(ref manifest.KeyRef) Change

KeyDelete is `sshmgr key delete <profile/key> --yes`: the declaration and the record go; the files stay.

func Keygen

func Keygen(target string) Change

Keygen is `sshmgr keygen <profile|alias> --no-pin --yes`, without --force: it mints the target's missing keys and leaves every existing one alone.

func NotifyTest

func NotifyTest() Change

NotifyTest is `sshmgr notify test`: one test desktop notification.

func ProfileAdd

func ProfileAdd(name, keyScope, keyName, keyComment string) Change

ProfileAdd is `sshmgr profile add <name> [--key-scope] [--key-name] [--key-comment]`.

func ProfileCategory

func ProfileCategory(name, category string) Change

ProfileCategory is `sshmgr profile edit <name> --category <category>`: it moves the profile's key directory, private keys and all, and the inventory records follow. "" returns it to the flat layout.

func ProfileDelete

func ProfileDelete(name string) Change

ProfileDelete is `sshmgr profile delete <name> --yes`: the manifest, the inventory records, the rendered blocks and the pins go; key files stay.

func ProfileEdit

func ProfileEdit(name string, keyScope, keyName *string) Change

ProfileEdit is `sshmgr profile edit <name> [--key-scope] [--key-name]`. A nil field is left as it is.

func ProfilePurge

func ProfilePurge(name string) Change

ProfilePurge is `sshmgr profile delete <name> --purge --yes`: everything ProfileDelete removes, and the profile's key files too. It never runs without the encrypted backup the CLI writes first; the web has no --no-key-backup.

func ProvidersExport

func ProvidersExport() Change

ProvidersExport is `sshmgr providers --export`, without --force: write the shipped provider catalog into the home to customize, unless one is there.

func Reconcile

func Reconcile() Change

Reconcile is `sshmgr reconcile --yes --no-pin`: mint every missing key, record keys already on disk, render the config, fix modes.

func SnapshotRestore

func SnapshotRestore(snapshotsDir, id string, retain int) Change

SnapshotRestore is `sshmgr snapshots restore <id> --yes`: put back the config, known_hosts and public keys a snapshot holds, after snapshotting ~/.ssh as it is now. snapshotsDir is the real home's: a preview restores from it into the copy, where it has no snapshot of its own to take, and apply restores into the home through the same function the CLI uses.

A snapshot written before private keys were left out is refused, as the snapshot page refuses to open one: restoring it would put plaintext private keys back on disk from an archive nobody can see into here.

func SnapshotsPrune

func SnapshotsPrune(keep int) Change

SnapshotsPrune is `sshmgr snapshots prune --keep <n>`. It takes no snapshot of its own first, which would push one more out.

func TokenApply

func TokenApply() Change

TokenApply is `authama token apply` with no terminal to ask: the token config is resolved from the server's environment and every tool's file is merged. A registry docker keeps in a credential store is handled as the config's _settings.docker_creds_store says, and refused when it says nothing.

func TokenDelete

func TokenDelete(target, host string) Change

TokenDelete is `authama token delete <target> <host>`.

func VMAdd

func VMAdd(profile, alias, hypervisor, vmName, user string) Change

VMAdd is `sshmgr vm add <profile> <alias> --hypervisor --vm -u <user> --yes`.

func VMDockerContext

func VMDockerContext(alias string) Change

VMDockerContext is `sshmgr vm docker-context <alias>`: create, or update, the Docker context ssh://<alias> for a VM host.

type FileDiff

type FileDiff struct {
	Path  string
	State string // added | removed | changed
	Lines []history.DiffLine
}

FileDiff is one file the change touches. Path is relative to the home it belongs to, prefixed "~/.ssh/" or "config/" so the two trees read apart.

func DiffTrees

func DiffTrees(before, after map[string]string) []FileDiff

DiffTrees compares two captured trees, file by file, in path order.

type HostInput

type HostInput struct {
	Hostname, User *string
	Port           *int
	Tags           *[]string
	KeyName        *string
}

HostInput is what a person can set on a host from the web. Pointer fields are left unchanged when nil, as an unset CLI flag is.

type Plan

type Plan struct {
	Command string
	Args    []string
	Files   []FileDiff
	Effects []string
	Hidden  []string // files the copy holds no content for that the change removes or creates
	Output  string
	Err     string // the change would fail, with this message
	Mints   bool   // the keys it shows are throwaway; apply mints new ones
	// NoSnapshot is set when apply takes no snapshot of ~/.ssh first.
	NoSnapshot bool
	Hash       string
}

Plan is a preview: what the change would write, what it would say, and a hash binding the two to the state they were computed from.

func Preview

func Preview(p paths.Paths, ch Change) (Plan, error)

Preview runs ch against a private copy of p and reports what it would do. It writes nothing outside the copy and records nothing in the history.

type Result

type Result struct {
	Output   string
	OpID     string
	Snapshot string
}

Result is a change that was made.

Jump to

Keyboard shortcuts

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