Documentation
¶
Overview ¶
Package editor does manifest editing - profile/host add·edit·delete. Edits go through the manifest (never a hand-edited config), are validated, and written atomically. Delete prunes the inventory deployment record so no dangling tracking is left behind.
Note: remote key REVOCATION on delete needs the provider adapters (gh/glab/REST), which are a later wave; until then revoke prunes local deployment tracking but does not call a remote (matching v1's behavior for manual/web-panel providers).
Index ¶
- func AnyAdded(res []ApplyResult) bool
- func FormatApply(profile string, newProfile bool, res []ApplyResult, preview bool) string
- type ApplyAction
- type ApplyResult
- type CategoryResult
- type DeleteResult
- type Editor
- func (e *Editor) AddHost(profile, alias string, f HostFields) error
- func (e *Editor) AddKey(profile, name string, keyType *string, rotateAfterDays *int, hostAlias string) error
- func (e *Editor) AddProfile(name, keyScope string, keyName *string) error
- func (e *Editor) ApplyCreatingProfile(profile, category string, create bool, specs []HostSpec) ([]ApplyResult, error)
- func (e *Editor) ApplyHosts(profile string, specs []HostSpec, dryRun bool) ([]ApplyResult, error)
- func (e *Editor) DeleteHost(profile, alias string, revoke bool) (DeleteResult, error)
- func (e *Editor) DeleteKey(ref manifest.KeyRef, revoke bool) (DeleteResult, error)
- func (e *Editor) DeleteProfile(name string, revoke bool) (DeleteResult, error)
- func (e *Editor) EditHost(profile, alias string, f HostFields) error
- func (e *Editor) EditProfile(name string, keyScope *string, keyName *string) error
- func (e *Editor) SetCategory(name, category string) (CategoryResult, error)
- func (e *Editor) SetKeyComment(name, tmpl string) error
- type HostFields
- type HostSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyAdded ¶
func AnyAdded(res []ApplyResult) bool
AnyAdded reports whether the batch added a host.
func FormatApply ¶
func FormatApply(profile string, newProfile bool, res []ApplyResult, preview bool) string
FormatApply is the report `host apply` prints, for a dry run or a real one.
Types ¶
type ApplyAction ¶
type ApplyAction string
ApplyAction is what ApplyHosts did (or would do) to one host.
const ( HostAdded ApplyAction = "added" HostUpdated ApplyAction = "updated" HostUnchanged ApplyAction = "unchanged" )
type ApplyResult ¶
type ApplyResult struct {
Alias string
Action ApplyAction
Changes []string
}
ApplyResult is one host's outcome; Changes lists the fields that moved.
type CategoryResult ¶
type CategoryResult struct {
From, To string // profile directories, relative to ~/.ssh
Moved bool // the key directory was renamed from From to To
RecordsUpdated int // inventory records re-pointed at the new location
}
CategoryResult reports what SetCategory changed on disk.
type DeleteResult ¶
DeleteResult is what one manifest-level deletion changed. It is data for the caller to fold into its own report - it carries no Format of its own, because the manifest half of a deletion is no longer the whole story: the lifecycle service composes this with the config re-render, the known_hosts pruning and whatever happened to the key files, and only it can describe the outcome truthfully.
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor edits the manifest at the resolved home.
func (*Editor) AddHost ¶
func (e *Editor) AddHost(profile, alias string, f HostFields) error
AddHost adds a host to a profile.
func (*Editor) AddKey ¶
func (e *Editor) AddKey(profile, name string, keyType *string, rotateAfterDays *int, hostAlias string) error
AddKey declares a key on a profile and, when hostAlias is set, points that host at it. Type and rotateAfterDays are optional overrides of the manifest defaults. It only edits the manifest - minting the key file is the caller's next step, so a failed edit never leaves a key on disk nothing refers to.
func (*Editor) AddProfile ¶
AddProfile adds a new profile. keyScope defaults to per_service.
func (*Editor) ApplyCreatingProfile ¶
func (e *Editor) ApplyCreatingProfile(profile, category string, create bool, specs []HostSpec) ([]ApplyResult, error)
ApplyCreatingProfile runs the batch, first creating the profile when asked. Creating it is a separate save, so if the batch then fails validation the manifest is put back exactly as it was - otherwise a refused batch left an empty profile behind. A new profile has no key directory yet, so restoring the manifest is the whole of the undo.
func (*Editor) ApplyHosts ¶
ApplyHosts upserts specs into a profile: a missing alias is added the way `host add` adds it, an existing one is edited the way `host edit` edits it (hostname, user, port when given) and has its role/tags merged in - never removed. The whole batch is validated by the manifest's own rules and saved once, so a bad spec leaves the manifest untouched. dryRun reports without saving.
func (*Editor) DeleteHost ¶
func (e *Editor) DeleteHost(profile, alias string, revoke bool) (DeleteResult, error)
DeleteHost removes a host, revoking/pruning its key.
func (*Editor) DeleteKey ¶
DeleteKey removes a key's declaration from its profile and drops its inventory record. It refuses while any host still resolves to the key: deleting it then would leave a Host block pointing at an IdentityFile that no longer exists, which ssh reports as a bare permission denial. Key files on disk are the caller's to remove (see the lifecycle service) so an accidental delete costs nothing but a manifest edit.
func (*Editor) DeleteProfile ¶
func (e *Editor) DeleteProfile(name string, revoke bool) (DeleteResult, error)
DeleteProfile removes a profile, revoking/pruning its hosts' keys.
func (*Editor) EditHost ¶
func (e *Editor) EditHost(profile, alias string, f HostFields) error
EditHost updates a host's fields (only the non-nil ones).
func (*Editor) EditProfile ¶
EditProfile updates a profile's key_scope and/or key_name (nil/empty keeps).
func (*Editor) SetCategory ¶
func (e *Editor) SetCategory(name, category string) (CategoryResult, error)
SetCategory files a profile under category ("" returns it to the flat layout) and brings the tree along: the profile's key directory is renamed into place when it is still at the old location, and inventory records are re-pointed. When the directory has already been moved by hand - the usual way a tree reaches this state - only the records change.
It refuses when both locations exist, rather than choosing one: two key directories for one profile is a conflict for a person to resolve.
func (*Editor) SetKeyComment ¶
SetKeyComment sets a profile's key_comment template; "" returns it to defaults.key_comment. It applies to keys minted from now on: a key's comment is written into its .pub when ssh-keygen creates it.
type HostFields ¶
type HostFields struct {
Hostname *string
User *string
Port *int
Provider *string
TokenEnv *string
KeyName *string
// Tags are the tags a new host starts with (AddHost only).
Tags []string
// SetTags replaces an existing host's tags with this list (de-duplicated); an
// empty list clears them. nil leaves them unchanged.
SetTags *[]string
// Untag removes these tags after any SetTags; a tag the host lacks is ignored.
Untag []string
// VM marks the host as a local VM whose address the hypervisor supplies at connect time.
VM *manifest.VMSpec
// Proxy names a proxy kind ("cloudflared"); "none" or "" clears it. nil leaves it unchanged.
Proxy *string
}
HostFields are the optional attributes for add/edit host (nil = unset/keep).
type HostSpec ¶
type HostSpec struct {
Alias string `json:"alias"`
Hostname string `json:"host"`
User string `json:"user"`
Port int `json:"port,omitempty"`
Role string `json:"role,omitempty"`
Tags []string `json:"tags,omitempty"`
}
HostSpec is one compact host declaration: `<alias> <host>[:port] <user> [role]`, e.g. `web-01 203.0.113.21 ploi web`. The role, when given, is stored as a tag. Port 0 means "not given": 22 on add, unchanged on update.
func ParseHostSpec ¶
ParseHostSpec parses one spec from its whitespace-separated fields.
func ParseHostSpecLine ¶
ParseHostSpecLine parses one spec written as a single string.
func ParseHostSpecs ¶
ParseHostSpecs reads many specs. Text is one spec per line, with blank lines and `#` comments skipped. Input whose first non-space byte is `[` is read as a JSON array whose items are either spec strings or objects ({"alias","host","user","port","role","tags"}).