Documentation
¶
Overview ¶
astpoke.go is the single place that reaches into kevinburke/ssh_config's unexported fields via reflect/unsafe — the adapter between this package's domain logic and the library's private AST shape.
Everything here is pinned to ssh_config v1.6.0: a dependency bump that renames or retypes one of these fields breaks the accessors. The tripwire test (astpoke_test.go) parses a fixture and asserts every accessor still binds, so an incompatible upgrade fails loudly in CI instead of corrupting writes. No other file in the package may import unsafe or call reflect on library types.
Package sshconfig parses ~/.ssh/config (following Include directives) into the domain model and writes edits back while preserving comments, ordering, and unknown options via a round-tripping AST.
Index ¶
- Variables
- type ConfigRepo
- type FileRepo
- func (r *FileRepo) AddHost(h config.Host) error
- func (r *FileRepo) AddHostIdentity(h config.HostID, path string) error
- func (r *FileRepo) BackupPaths() []string
- func (r *FileRepo) DeleteHost(h config.HostID) error
- func (r *FileRepo) DeleteHostField(h config.HostID, key string) error
- func (r *FileRepo) Load() (*config.SshConfigModel, error)
- func (r *FileRepo) RemoveHostIdentity(h config.HostID, id config.IdentityID) error
- func (r *FileRepo) Restore() ([]string, error)
- func (r *FileRepo) Save() error
- func (r *FileRepo) SetHostField(h config.HostID, key, val string) error
Constants ¶
This section is empty.
Variables ¶
var ErrMatchReadOnly = errors.New("Match blocks are read-only")
ErrMatchReadOnly is returned when a mutation targets a `Match` block. Match conditions depend on connection-time state, so sshush surfaces them read-only.
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned by stubbed methods during scaffolding.
Functions ¶
This section is empty.
Types ¶
type ConfigRepo ¶
type ConfigRepo interface {
Load() (*config.SshConfigModel, error)
SetHostField(h config.HostID, key, val string) error
DeleteHostField(h config.HostID, key string) error
AddHostIdentity(h config.HostID, path string) error
RemoveHostIdentity(h config.HostID, id config.IdentityID) error
AddHost(config.Host) error
DeleteHost(config.HostID) error
Save() error
BackupPaths() []string
Restore() ([]string, error)
}
ConfigRepo loads and mutates SSH configuration. Mutations operate on the in-memory AST; Save backs up the file then writes the AST.
type FileRepo ¶
type FileRepo struct {
Path string // path to user config; empty means ~/.ssh/config
// SshDir is the directory that relative Include directives and ~ resolve
// against (per OpenSSH, ~/.ssh). Empty means ~/.ssh.
SshDir string
// contains filtered or unexported fields
}
FileRepo is a ConfigRepo backed by an on-disk config file plus its Includes.
func (*FileRepo) AddHost ¶
AddHost appends a new Host block to the main config file. The block carries the host's set fields (HostName/User/Port) and any Options, indented four spaces, followed by a blank line. In-memory until Save.
func (*FileRepo) AddHostIdentity ¶
AddHostIdentity appends an IdentityFile directive to host h (IdentityFile may appear multiple times). In-memory until Save.
func (*FileRepo) BackupPaths ¶ added in v0.6.0
BackupPaths returns the loaded config files that have a sibling ".bak" to restore from. A ".bak" is written before sshush's first edit of a file, so its presence means there is a pre-edit snapshot to revert to.
func (*FileRepo) DeleteHost ¶
DeleteHost removes a host block from whichever file defines it.
func (*FileRepo) DeleteHostField ¶
DeleteHostField removes the first directive matching key from host h. It is a no-op (no error) if the host has no such directive. In-memory until Save.
func (*FileRepo) Load ¶
func (r *FileRepo) Load() (*config.SshConfigModel, error)
Load parses the user config and every file it Includes, building the unified model. A missing main config yields an empty model, not an error. Includes are resolved relative to ~/.ssh (per OpenSSH), with globbing and ~ expansion, deduped, and capped at maxIncludeDepth.
func (*FileRepo) RemoveHostIdentity ¶
RemoveHostIdentity removes the IdentityFile directive whose path resolves to identity id. No-op if not found.
func (*FileRepo) Restore ¶ added in v0.6.0
Restore overwrites each loaded file that has a ".bak" with the backup's contents, reverting every change made since the backup was taken (sshush's first edit this session). Returns the restored file paths. The in-memory AST is left stale on purpose — callers reload (via Refresh) to pick up the reverted content.
func (*FileRepo) Save ¶
Save writes every dirty file back to disk. Before the first write of a file this session it copies the file's original contents to "<path>.bak", so an unexpected result is always recoverable. Files are written with their existing permissions (default 0600).
func (*FileRepo) SetHostField ¶
SetHostField sets key=val on host h, updating the existing directive in place (preserving its indentation and trailing comment) or appending a new one that mimics the block's indentation. The change is in-memory only until Save.