Documentation
¶
Overview ¶
Package encode writes a table of typed rows in a file format: the last stage of the export pipeline (dataset, selection, format).
Every format escapes for itself, because each is read by something different: a spreadsheet runs a cell starting with "=", a browser runs a "</table><script>", PHP ends a string at an unescaped quote, a Markdown table splits on "|". Each format has a test for its own hazard.
Index ¶
- Constants
- Variables
- func Bundle(f Format, exp *ClientExport) ([]byte, error)
- func ClientNames() []string
- func FileName(f Format, exp *ClientExport, base string) string
- func HostNames() []string
- func Names() []string
- func TableNames() []string
- func TermiusCSV(hosts []Host) (string, error)
- func Text(v any) string
- type Client
- type ClientExport
- type ClientFile
- type Format
- type Host
- type HostSource
- type Options
- type Table
Constants ¶
const ClientCSV = "hosts-csv"
ClientCSV is the generic client CSV's name in the pipeline, where "csv" is the table CSV.
Variables ¶
var Clients = map[string]Client{ "csv": {Name: "csv", Client: "any client that imports a CSV (Royal TS, Xshell, SecureCRT's import script, a spreadsheet)", Render: renderGenericCSV}, "windows-terminal": {Name: "windows-terminal", Client: "Windows Terminal (a JSON fragment)", ViaSSH: true, Render: renderWindowsTerminal}, "iterm2": {Name: "iterm2", Client: "iTerm2 (Dynamic Profiles)", ViaSSH: true, Render: renderITerm2}, "putty": {Name: "putty", Client: "PuTTY and KiTTY (a .reg file)", Render: renderPuTTY}, "remmina": {Name: "remmina", Client: "Remmina (one .remmina file per host)", Render: renderRemmina}, "securecrt": {Name: "securecrt", Client: "SecureCRT (an XML settings file for File > Import Settings; Termius imports it too)", Render: renderSecureCRT}, "mobaxterm": {Name: "mobaxterm", Client: "MobaXterm (a .mxtsessions file for Sessions > Import; Termius imports it too)", Render: renderMobaXterm}, }
Clients are the SSH client formats, by their own name ("csv" is hosts-csv in the pipeline).
var ErrNotHosts = errors.New("encode: a host format writes host rows, not a table")
ErrNotHosts is a host format asked to write a table.
var ErrUnknownFormat = errors.New("encode: unknown format")
ErrUnknownFormat is a format this package does not have.
var GenericCSVColumns = []string{"alias", "group", "hostname", "port", "user", "key_path", "tags"}
GenericCSVColumns are the generic export's columns.
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 Bundle ¶
func Bundle(f Format, exp *ClientExport) ([]byte, error)
Bundle is an export as one file: its only file as it is, or, for a format that writes a file per host (its extension is zip), every file in a zip under its own name.
func FileName ¶
func FileName(f Format, exp *ClientExport, base string) string
FileName is what a host format's file is called: the client's own name for it (authama-putty.reg), or the zip's.
func TermiusCSV ¶
TermiusCSV is a Termius CSV import of hosts, one row each: group = profile, label = alias, tags = the host's tags. No password is ever written: the column is part of the template and stays empty.
Types ¶
type Client ¶
type Client struct {
Name, Client string
// ViaSSH formats launch `ssh <alias>`, so OpenSSH reads the managed config
// and a ProxyCommand or VM host works as it does at the terminal; the
// others hand the client a host, port, user and key and keep only hosts
// the client can reach on its own.
ViaSSH bool
Render func(hosts []Host) (*ClientExport, error)
}
Client is one SSH client's import format.
type ClientExport ¶
type ClientExport struct {
Files []ClientFile
Skipped []string
Notes []string
}
ClientExport is a rendered export: the files, the hosts left out with the reason for each, and notes the user needs to finish the import.
type ClientFile ¶
ClientFile is one file an export writes: its name and its bytes.
type Format ¶
type Format struct {
Name string // csv, json, ...
Extension string // without the dot
MediaType string
Label string // for a page: "CSV", "PHP array", ...
Write func(w io.Writer, t Table, o Options) error
// Hosts is set on a host format (hosts.go): it writes the hosts a
// selection kept, read from a HostSource, and Write refuses a table.
Hosts func(src HostSource, aliases []string, o Options) (*ClientExport, error)
// Client is the client format's own name in Clients, which the pipeline
// may call otherwise: the generic "csv" client is "hosts-csv" there, since
// "csv" is the table format.
Client string
}
Format is one file format.
type Host ¶
type Host struct {
Group, Alias, Hostname, User string
Port int
Tags []string
KeyFile string // absolute; "" when the key is in 1Password
Agent string // the 1Password agent socket, when it is
}
Host is one host as an SSH client's import sees it: the profile as its group, the alias as its name, and the key as an absolute path.
type HostSource ¶
type HostSource interface {
// ClientHosts are the hosts named, as a client sees them. A host the
// client cannot reach on its own (behind a ProxyCommand, when viaSSH is
// false) or a git host (unless includeGit) is left out, with the reason
// in skipped. client names the client in that reason.
ClientHosts(aliases []string, client string, viaSSH, includeGit bool) (hosts []Host, skipped []string, err error)
// SSHConfig is the managed config of exactly the hosts named, as
// `authama ssh config export --flat` writes it for every host.
SSHConfig(aliases []string) (string, error)
}
HostSource is what a host format reads.
type Options ¶
type Options struct {
NoHeader bool // csv, tsv, markdown, html: leave the heading row out
Compact bool // json, js, php, yaml: no indentation
Shape string // json, js, php, yaml: "objects" (default) or "table" ({columns, rows})
Title string // html: the page title
// IncludeGit keeps git hosts (user git, or a github or gitlab provider)
// in a host format, which otherwise leaves them out: they are not shells.
IncludeGit bool
}
Options tune a format. A format ignores what does not apply to it.