importer

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 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 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

func BackupTargets(p paths.Paths)

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 New

func New(p paths.Paths, emitUseKeychain bool) *Importer

New builds an importer.

func (*Importer) InPlaceOf added in v0.1.6

func (im *Importer) InPlaceOf(real paths.Paths) *Importer

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

type Source struct {
	Root  string
	Files []string
}

Source is what an import reads: the config files, in order, and the folder they belong to.

func Locate added in v0.1.6

func Locate(path string) (Source, error)

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.

Jump to

Keyboard shortcuts

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