renderer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 10 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 renderer renders the managed SSH config, ported from one template pair. One renderer backs config render, config check, and reconcile so they cannot disagree.

Index

Constants

View Source
const (
	// ManagedHeader/ManagedEnd delimit the block ssh-manager owns in ~/.ssh/config.
	ManagedHeader = "# Managed by ssh-manager - do not edit (run: sshmgr config render)"
	ManagedEnd    = "# End of ssh-manager-managed block - content outside it is preserved"
	// RootConfig is the top-level config file's relative path under ~/.ssh.
	// Every uncategorized profile's Host blocks live inline here. A profile
	// with a category renders into profiles/<category>/config instead, which
	// the root config Includes - one file per category, never one per profile.
	RootConfig = "config"
)
View Source
const FlatHeader = "# ssh-manager flat export - every host inline, absolute paths, no Include.\n" +
	"# Generated from the manifest by `authama ssh config export --flat`; ssh does not read this file\n" +
	"# unless you point it here. Edit the manifest, not this copy, and export again.\n"

FlatHeader opens a flat export. It is deliberately not the managed header: sshmgr owns the files it renders under ~/.ssh, and a copy of an export carrying that header would be treated as one of them.

Variables

View Source
var CloudflaredPath = defaultCloudflaredPath

CloudflaredPath returns the cloudflared binary a Cloudflare Access host's ProxyCommand runs. A variable so tests pin it.

View Source
var SelfPath = defaultSelfPath

SelfPath returns the sshmgr binary a VM host's ProxyCommand runs. A variable so tests pin it.

View Source
var TermiusColumns = []string{"Groups", "Label", "Tags", "Hostname/IP", "Protocol", "Port", "Username", "Password"}

TermiusColumns is the header of Termius's CSV import template, as the third-party exporters written against it reproduce it (Termius 9.x). Termius publishes the template only as a download inside the app, so this is the one place to change if it moves.

Functions

func CloudflaredProxyCommand

func CloudflaredProxyCommand() string

CloudflaredProxyCommand is the ProxyCommand for a Cloudflare Access host: cloudflared opens the Access tunnel to %h (the HostName, which ssh substitutes) after the browser sign-in Access asks for. Quoted like the VM ProxyCommand; a path ssh cannot quote falls back to the bare name.

func ComposeRootConfig

func ComposeRootConfig(existing, managed string) string

ComposeRootConfig returns the full ~/.ssh/config with the managed block in place, preserving foreign content above and below it (e.g. an OrbStack Include). Old/legacy markers are recognized so the block is re-owned, not duplicated. An empty existing returns the managed block as-is.

func IsManagedEndLine

func IsManagedEndLine(s string) bool

func IsManagedFile

func IsManagedFile(content string) bool

IsManagedFile reports whether content opens with the managed header (or the pre-rename one) - i.e. whether sshmgr wrote it.

func IsManagedHeaderLine

func IsManagedHeaderLine(s string) bool

IsManagedHeaderLine and IsManagedEndLine report whether a trimmed line opens or closes the managed block (current or legacy markers).

func ProxyBinary

func ProxyBinary(value string) string

ProxyBinary extracts the binary path from a ProxyCommand value sshmgr rendered - a VM host's sshmgr or a Cloudflare Access host's cloudflared - and "" for any other value. doctor uses it to find a recorded path that no longer exists, or a cloudflared that was never installed.

func ProxyCommandFor

func ProxyCommandFor(alias string) string

ProxyCommandFor is the ProxyCommand a VM host renders: sshmgr asks the hypervisor for the VM's current address on each connection.

The path is double-quoted literally, not with Go's %q: ssh does not unescape, so %q would double every backslash in a Windows path. A path containing a double quote cannot be quoted for ssh at all and falls back to the bare command name, resolved through PATH.

func RenderAll

func RenderAll(m *manifest.Manifest, emitUseKeychain bool) (map[string]string, error)

RenderAll renders every managed file: {relative path -> content} - the root config, plus profiles/<category>/config for each category in use.

func RenderCategoryConfig

func RenderCategoryConfig(m *manifest.Manifest, category string) (string, error)

RenderCategoryConfig renders profiles/<category>/config: the Host blocks of every profile in that category, in manifest (file) order. It carries the managed header so sshmgr can tell a file it wrote from one a user wrote there by hand, and no Host * block - the root config's applies to every host, wherever its block lives.

func RenderFlatConfig

func RenderFlatConfig(m *manifest.Manifest, p ExportPaths, emitUseKeychain bool) (string, error)

RenderFlatConfig renders the whole managed config as one self-contained file, for tools that read a single ssh_config and do not follow Include or Match (Termius's importer is one). Every profile's hosts are inline in manifest order, whatever their category, followed by the git ssh-mode block and Host * last, exactly as the split render orders them. Every ~ path is made absolute, so the file means the same wherever it is copied.

It is an export, never written over a file `config render` owns.

func RenderHostBlockFor

func RenderHostBlockFor(m *manifest.Manifest, profile string, host manifest.Host) (string, error)

RenderHostBlockFor renders the Host block one manifest host produces - byte for byte what RenderRootConfig emits for it. `sshmgr show` uses it to answer "what does this alias actually do" from the manifest, without asking the user to find the block in a file that now holds every profile's hosts at once.

func RenderRootConfig

func RenderRootConfig(m *manifest.Manifest, emitUseKeychain bool) (string, error)

RenderRootConfig renders the entire managed block: one Include per category in use, then every uncategorized profile's hosts inline under a banner (in manifest/file order), then the global Host * block last.

Host * must stay last. OpenSSH takes the first value it obtains for a given keyword, so a global block placed above the per-host blocks would silently override their more specific directives. The category Includes therefore sit at the top of the block, where each included file expands in place ahead of Host *.

The Includes open with `Match all`. An Include that follows a Host or Match line is conditional on it, and the managed block is composed under whatever foreign content the user keeps above it - a hand-written Host block there would otherwise scope every category to that one host and leave the rest unconfigured, with no error. `Match all` resets the condition to every host. It is emitted only when there is a category to include, so a manifest with none renders byte-identical to before.

Types

type ExportPaths

type ExportPaths struct {
	SSHDir string
	Home   string
}

ExportPaths is what an export needs to turn the ~ form paths the managed config uses into absolute ones: the SSH directory ~/.ssh stands for, and the home directory any other ~/ path is relative to. They differ under --ssh-dir, which is why the home is not derived from the SSH directory.

func ExportPathsFor

func ExportPathsFor(sshDir string) ExportPaths

ExportPathsFor is the ExportPaths for sshDir: the user's home, or the SSH directory's parent when there is no home to read.

type RenderHost

type RenderHost struct {
	Alias        string
	Hostname     string
	User         string
	Port         int
	IdentityFile string
	// IdentityAgent is the agent socket for a key kept in 1Password, "" for a
	// key on disk. Rendered quoted: the macOS socket path contains a space.
	IdentityAgent string
	KnownHosts    string
	RawOptions    manifest.OrderedOptions
	// ProxyCommand is set by sshmgr for a VM host (never from raw_options, which may not hold one).
	ProxyCommand string
}

RenderHost is the flat view a host block needs to render.

type TermiusExport

type TermiusExport struct {
	CSV     string
	Keys    []TermiusKey
	Skipped []string
}

TermiusExport is a rendered Termius import: the CSV, the keys to attach, and the hosts left out with the reason for each.

func RenderTermiusCSV

func RenderTermiusCSV(m *manifest.Manifest, p ExportPaths, opts TermiusOptions) (*TermiusExport, error)

RenderTermiusCSV renders the manifest's hosts as a Termius CSV import, one row per host Termius can reach: group = profile, label = alias, tags = the host's tags. Two kinds are left out and reported:

  • VM hosts, which are reached only through sshmgr's ProxyCommand, which Termius ignores (its docs say so), so a row would be a dead host;
  • git hosts (user git, or a github or gitlab provider), which are not shells, unless IncludeGit is set;
  • any alias named in Skip.

No password is ever written: the column is part of the template and stays empty.

type TermiusKey

type TermiusKey struct {
	Label   string // the host's alias, its Termius label
	KeyFile string // absolute path of the key ssh would use
	Agent   string // non-empty when the key lives in 1Password, not on disk
}

TermiusKey is one key the user attaches in Termius by hand: the CSV carries no keys, and Termius imports them into its own keychain, not by path.

type TermiusOptions

type TermiusOptions struct {
	IncludeGit bool     // also export git hosts
	Skip       []string // aliases to leave out
}

TermiusOptions narrows a Termius export.

Jump to

Keyboard shortcuts

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