Documentation
¶
Overview ¶
Package importer onboards an existing ~/.ssh into the manifest + inventory. It parses an ssh config (following relative Include directives) into profiles + hosts, fingerprints any private keys it can find into the inventory, and adopts non-canonical keys into the profiles/ layout. Profile assignment derives from an IdentityFile under profiles/<profile>/ or profiles/<category>/<profile>/ (which also carries the category over), else "imported".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackupTargets ¶ added in v0.1.6
BackupTargets copies manifest + inventory into <home>/.state/import-backup-<ts>/.
Types ¶
type ImportResult ¶
type ImportResult struct {
Profiles map[string]int // profile -> host count (counts all parsed hosts)
KeysFound int
Adopted int
DryRun bool
// Skipped names each host left out because the manifest would refuse it
// (e.g. a hostname ssh itself refuses), with the reason.
Skipped []string
// Sources are the config files read, in order, and Root the folder
// relative Includes and ~/.ssh/ identity paths resolved against.
Sources []string
Root string
}
ImportResult summarizes an import run.
func (ImportResult) Format ¶
func (r ImportResult) Format() string
Format renders the human-readable import summary (mirrors ImportResult.format).
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer onboards an ssh config.
func (*Importer) InPlaceOf ¶ added in v0.1.6
InPlaceOf makes the import read as it would for real, a home p is a preview's copy of. The source is compared with real's ~/.ssh, not the copy's, so an IdentityFile resolves where it will on apply; and a key it would adopt is stood in for by an empty file, which says the key would be created without copying it.
func (*Importer) Run ¶
func (im *Importer) Run(configPath string, dryRun bool) (ImportResult, error)
Run parses configPath into a fresh manifest + inventory (replacing any existing). With dryRun it parses and reports without writing or adopting keys.
configPath may be a config file or any folder holding ssh config files; see Locate for how a folder is read.
type ParsedHost ¶
type ParsedHost struct {
Alias string
Hostname string
User string
Port int
IdentityFile string // "" if none
Profile string
Category string // "" unless the IdentityFile sat under profiles/<category>/<profile>/
Extra []kv
}
ParsedHost is one host block parsed from an ssh config.
type Source ¶ added in v0.1.6
Source is what an import reads: the config files, in order, and the folder they belong to.
func Locate ¶ added in v0.1.6
Locate finds the ssh config to import at path:
- a file: that file;
- a folder with a config file: that file, whose Includes pull in the rest (~/.ssh, or another machine's copy of it);
- a folder with ssh/config: that file, for a config home such as ~/.config;
- any other folder: every file named config, or ending .conf, up to four levels down, in path order (a flat folder of *.conf files, a config.d/, profiles/<name>/config), read as if one Included the next.