editor

package
v0.1.2 Latest Latest
Warning

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

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

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

type DeleteResult struct {
	Removed    string
	Revoked    []string
	PrunedKeys []string
}

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 New

func New(p paths.Paths) *Editor

New builds a manifest editor.

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

func (e *Editor) AddProfile(name, keyScope string, keyName *string) error

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

func (e *Editor) ApplyHosts(profile string, specs []HostSpec, dryRun bool) ([]ApplyResult, error)

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

func (e *Editor) DeleteKey(ref manifest.KeyRef, revoke bool) (DeleteResult, error)

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

func (e *Editor) EditProfile(name string, keyScope *string, keyName *string) error

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

func (e *Editor) SetKeyComment(name, tmpl string) error

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

func ParseHostSpec(fields []string) (HostSpec, error)

ParseHostSpec parses one spec from its whitespace-separated fields.

func ParseHostSpecLine

func ParseHostSpecLine(line string) (HostSpec, error)

ParseHostSpecLine parses one spec written as a single string.

func ParseHostSpecs

func ParseHostSpecs(r io.Reader) ([]HostSpec, error)

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"}).

func (HostSpec) AllTags

func (s HostSpec) AllTags() []string

AllTags is the role followed by any extra tags, de-duplicated, in order.

Jump to

Keyboard shortcuts

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