Documentation
¶
Overview ¶
Package assets is SSHYard's asset store: the hosts the user saved, with their groups and favorites, and the credentials, proxies and port forwards they use, kept as JSON in the user's data directory. Secrets are never stored here; they live in the system keychain (package keychain), under the ID of the credential, proxy or forward they belong to.
Index ¶
- Constants
- Variables
- func CleanGroup(g string) string
- func GroupLeaf(g string) string
- func GroupParent(g string) string
- func IconText(s string) string
- func InGroupTree(g, group string) bool
- func NewID() string
- func SubGroup(parent, name string) string
- func ValidID(id string) bool
- func ValidateSnippetContent(content string) error
- func ValidateSnippetGroup(group string) error
- type AIPolicy
- type AuthMethod
- type Credential
- type CredentialKind
- type FieldError
- type Forward
- type ForwardKind
- type ForwardProtocol
- type GroupLook
- type Host
- type InUseError
- type MetricsMode
- type NewLine
- type Protocol
- type Proxy
- type ProxyKind
- type Renewal
- type SerialLine
- type Snapshot
- type Snippet
- type Store
- func (s *Store) Add(h Host) (Host, error)
- func (s *Store) AddCredential(c Credential) (Credential, error)
- func (s *Store) AddForward(f Forward) (Forward, error)
- func (s *Store) AddGroup(name string) error
- func (s *Store) AddGroupLook(name string, look GroupLook) error
- func (s *Store) AddHost(h Host) (Host, error)
- func (s *Store) AddProxy(p Proxy) (Proxy, error)
- func (s *Store) AddSnippet(n Snippet) (Snippet, error)
- func (s *Store) Credential(id string) (Credential, bool)
- func (s *Store) CredentialUsers(id string) []Host
- func (s *Store) Credentials() []Credential
- func (s *Store) Delete(id string) error
- func (s *Store) DeleteCredential(id string) error
- func (s *Store) DeleteForward(id string) error
- func (s *Store) DeleteGroup(name string) error
- func (s *Store) DeleteProxy(id string) error
- func (s *Store) DeleteSnippet(id string) error
- func (s *Store) Discarded() []string
- func (s *Store) EditGroup(old, name string, look GroupLook) error
- func (s *Store) Favorites() []Host
- func (s *Store) Forward(id string) (Forward, bool)
- func (s *Store) Forwards() []Forward
- func (s *Store) Get(id string) (Host, bool)
- func (s *Store) GroupLook(g string) GroupLook
- func (s *Store) Groups() []string
- func (s *Store) InGroup(group string) []Host
- func (s *Store) JumpPath(id string) ([]Host, error)
- func (s *Store) Len() int
- func (s *Store) List() []Host
- func (s *Store) MoveGroup(name, target string, after bool) error
- func (s *Store) NestGroup(name, parent string) error
- func (s *Store) Proxies() []Proxy
- func (s *Store) Proxy(id string) (Proxy, bool)
- func (s *Store) ProxyUsers(id string) []Host
- func (s *Store) RenameGroup(old, name string) error
- func (s *Store) Restore(in Snapshot) error
- func (s *Store) RestoreIfHostsUnchanged(in Snapshot, expected []Host) error
- func (s *Store) SaveCredential(c Credential) (Credential, error)
- func (s *Store) SaveForward(f Forward) (Forward, error)
- func (s *Store) SaveProxy(p Proxy) (Proxy, error)
- func (s *Store) SaveSnippet(n Snippet) (Snippet, error)
- func (s *Store) Search(q string) []Host
- func (s *Store) SetFavorite(id string, fav bool) error
- func (s *Store) SetGroup(id, group string) error
- func (s *Store) Snapshot() Snapshot
- func (s *Store) Snippet(id string) (Snippet, bool)
- func (s *Store) Snippets() []Snippet
- func (s *Store) Touch(id string) error
- func (s *Store) Update(h Host) (Host, error)
Constants ¶
const DateLayout = time.DateOnly
DateLayout is how a Renewal writes its day: a calendar day, the same in every time zone, so that a backup opened elsewhere keeps it.
const GroupSep = "/"
GroupSep parts a subgroup from its group: "Prod/Web", "Prod/Web/Blue". Groups nest to any depth.
const IconPrefix = "icon:"
IconPrefix starts a Host.Icon naming one of the app's icons.
const RenewalRemindDefault = 3
RenewalRemindDefault is a new subscription's reminder, in days.
const SchemaVersion = 2
SchemaVersion is the version of the data file. A file of any other (older) version is discarded, not migrated.
Variables ¶
var ErrExists = errors.New("assets: ID in use")
ErrExists is AddCredential's or AddProxy's error for an ID in use.
var ErrJumpLoop = errors.New("assets: the jump chain loops")
ErrJumpLoop reports a jump chain that comes back to a host already on it (A through B, B through A), or reaches one host twice (A through B and C, with C through B too).
var ErrNotFound = errors.New("assets: not found")
ErrNotFound reports an ID the store does not have.
var ErrSnapshotChanged = errors.New("assets: snapshot hosts changed")
ErrSnapshotChanged means hosts no longer match the preview baseline.
var ErrStreamURL = errors.New("assets: bad telnet:// or serial:// destination")
ErrStreamURL is a telnet:// or serial:// destination that cannot be read.
var RenewalMonths = []int{1, 3, 6, 12, 24, 36}
RenewalMonths are the periods the editor offers, in months.
var RenewalReminds = []int{0, 1, 3, 7, 15, 30}
RenewalReminds are the days before a renewal the editor offers to remind of it, never first.
Functions ¶
func CleanGroup ¶ added in v0.0.24
CleanGroup trims a group's path and the names in it.
func GroupParent ¶ added in v0.0.24
GroupParent returns the group a subgroup is in, "" for a top-level group.
func IconText ¶
IconText is what a host keeps of its icon: one of the app's as it is, else the text trimmed, at most two emoji or four letters wide, whole characters only.
func InGroupTree ¶ added in v0.0.24
InGroupTree reports whether g is group or one of its subgroups, at any depth.
func SubGroup ¶ added in v0.0.24
SubGroup returns the path of the subgroup name in parent, name alone for a top-level group.
func ValidID ¶
ValidID reports whether id can name an entry: what NewID makes, and no character that would reach into another entry's keychain key.
func ValidateSnippetContent ¶
ValidateSnippetContent accepts at most 64 KiB of UTF-8 command text, with CR, LF and TAB as the only allowed C0 controls. Errors never contain the body.
func ValidateSnippetGroup ¶
ValidateSnippetGroup checks a trimmed group name; "" is the default group.
Types ¶
type AIPolicy ¶
type AIPolicy struct {
Mode string `json:"mode,omitempty"`
WritableRoots []string `json:"writableRoots,omitempty"`
Sensitive []string `json:"sensitive,omitempty"`
}
AIPolicy is how an AI pane on this host may act. Paths are remote POSIX paths. Mode empty means inherit.
type AuthMethod ¶
type AuthMethod string
AuthMethod is how a host authenticates.
const ( // AuthPassword and AuthKey use secrets owned by this host. AuthPassword AuthMethod = "password" AuthKey AuthMethod = "key" // AuthCredential uses the credential of the host's CredentialID. AuthCredential AuthMethod = "credential" // AuthAgent signs with the keys of the system's SSH agent. AuthAgent AuthMethod = "agent" // AuthAsk keeps nothing: the password is asked at each connection // and held in memory only. AuthAsk AuthMethod = "ask" // AuthNone is a Telnet or serial host logged in to by hand, in the // terminal: its prompts are not answered. AuthNone AuthMethod = "none" )
type Credential ¶
type Credential struct {
ID string `json:"id"`
Name string `json:"name"`
Kind CredentialKind `json:"kind"`
// User, when set, logs in instead of the host's user.
User string `json:"user,omitempty"`
Note string `json:"note,omitempty"`
// Fingerprint is the SHA256 fingerprint of a key's public half.
Fingerprint string `json:"fingerprint,omitempty"`
// KeyType is the key's algorithm, such as ssh-ed25519.
KeyType string `json:"keyType,omitempty"`
// Encrypted records that the key has a passphrase; AskPassphrase
// that it is not saved but asked once per run.
Encrypted bool `json:"encrypted,omitempty"`
AskPassphrase bool `json:"askPassphrase,omitempty"`
// Certificate is the OpenSSH user certificate of a key, one
// key-cert.pub line; public, so it is kept here.
Certificate string `json:"certificate,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
Credential is a password or private key that hosts refer to. Its JSON holds metadata only; the secret is in the keychain under cred/<id>/<kind>.
func (*Credential) Normalize ¶
func (c *Credential) Normalize()
Normalize trims the credential's fields.
func (Credential) Validate ¶
func (c Credential) Validate() error
Validate checks a normalized credential.
type CredentialKind ¶
type CredentialKind string
CredentialKind is what a credential holds.
const ( // CredPassword is a password. CredPassword CredentialKind = "password" // CredKey is a private key, kept in OpenSSH form (a PuTTY key is // converted when imported), maybe with a passphrase. CredKey CredentialKind = "key" )
type FieldError ¶
type FieldError struct {
Field string // "name", "address", "port", "user", "auth", "credential", "kind", "target", …
Reason string
}
FieldError reports an invalid field of a host.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type Forward ¶
type Forward struct {
ID string `json:"id"`
Name string `json:"name"`
Kind ForwardKind `json:"kind"`
HostID string `json:"hostId"`
// Listen is where connections come in: on this computer for local
// and dynamic forwards, on the server for remote ones.
ListenAddr string `json:"listenAddr"`
ListenPort int `json:"listenPort"`
// Target is where they go: seen from the server for local
// forwards, from this computer for remote ones; none for dynamic.
TargetAddr string `json:"targetAddr,omitempty"`
TargetPort int `json:"targetPort,omitempty"`
Protocol ForwardProtocol `json:"protocol,omitempty"`
// User, when set, is the username a dynamic forward's clients
// authenticate with (HTTP and SOCKS5).
User string `json:"user,omitempty"`
AutoStart bool `json:"autoStart,omitempty"`
Note string `json:"note,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
Forward is a port forwarding rule through a host. Its listener's password (dynamic forwards) is in the keychain under forward/<id>/password.
func (Forward) Exposed ¶
Exposed reports whether the forward listens beyond the loopback address, where others on the network may reach it.
type ForwardKind ¶
type ForwardKind string
ForwardKind is the kind of a port forward.
const ( ForwardLocal ForwardKind = "local" // ssh -L ForwardRemote ForwardKind = "remote" // ssh -R ForwardDynamic ForwardKind = "dynamic" // ssh -D )
type ForwardProtocol ¶
type ForwardProtocol string
ForwardProtocol is what a dynamic forward's proxy speaks.
const ( ProtoAuto ForwardProtocol = "" // tell from the first bytes ProtoHTTP ForwardProtocol = "http" ProtoSOCKS4 ForwardProtocol = "socks4" // and 4a ProtoSOCKS5 ForwardProtocol = "socks5" )
type GroupLook ¶ added in v0.0.24
GroupLook is how a group shows in the sidebar: its icon, as a host's (Host.Icon), and the color of it (Host.Color); "" for the folder in the sidebar's own color.
type Host ¶
type Host struct {
ID string `json:"id"`
Name string `json:"name"`
// Protocol is how the host is reached; empty is SSH.
Protocol Protocol `json:"protocol,omitempty"`
Address string `json:"address"`
Port int `json:"port"`
User string `json:"user"`
Group string `json:"group,omitempty"`
Favorite bool `json:"favorite,omitempty"`
Auth AuthMethod `json:"auth"`
// Icon is the host's icon: one of the app's own, by its key after
// IconPrefix ("icon:database"), or a short text the user typed, as
// an emoji. Empty picks one from the address.
Icon string `json:"icon,omitempty"`
// Color is the tint behind the icon, a name of theme.TintNames.
// Empty picks one from the address.
Color string `json:"color,omitempty"`
// CredentialID is the credential of AuthCredential.
CredentialID string `json:"credentialId,omitempty"`
AskPassphrase bool `json:"askPassphrase,omitempty"`
// Certificate is the OpenSSH user certificate of an AuthKey host's
// key, one key-cert.pub line; public, so it is kept here.
Certificate string `json:"certificate,omitempty"`
// JumpChain are the hosts connected through, in order, before this
// one (ProxyJump); each with its own credential and host key check.
JumpChain []string `json:"jumpChain,omitempty"`
// ProxyID is the proxy the first hop is dialed through.
ProxyID string `json:"proxyId,omitempty"`
// CwdFollow lets a Files pane follow the directory the terminal of
// the same tab reports (OSC 7). New hosts have it on.
CwdFollow bool `json:"cwdFollow"`
// TerminalDir, RemoteDir and LocalDir are where an SSH host's
// terminal, the server side of its Files panes and their side on
// this computer start; "~" or "~/…" is under the home folder. Empty
// is the home folder.
TerminalDir string `json:"terminalDir,omitempty"`
RemoteDir string `json:"remoteDir,omitempty"`
LocalDir string `json:"localDir,omitempty"`
// SFTPSudo runs the SFTP server of an SSH host's Files panes as root
// through sudo, which the login password, or one typed, answers.
SFTPSudo bool `json:"sftpSudo,omitempty"`
// Tmux is the tmux session an SSH host's terminals attach to each
// time their shell starts, created when there is none; empty is
// none.
Tmux string `json:"tmux,omitempty"`
// OSC52 overrides the global OSC 52 write policy (allow, ask or
// deny). Empty follows the global setting.
OSC52 string `json:"osc52,omitempty"`
// Metrics is whether this host shows the metrics bar: follow the
// global setting, always, or never.
Metrics MetricsMode `json:"metrics,omitempty"`
// AIPolicy is the host's AI permission override. An empty mode
// inherits the global default.
AIPolicy AIPolicy `json:"aiPolicy,omitempty"`
// Serial is a serial host's port and its settings.
Serial *SerialLine `json:"serial,omitempty"`
// NewLine is what Enter sends to a Telnet or serial host.
NewLine NewLine `json:"newline,omitempty"`
// LocalEcho shows what is typed to a Telnet or serial host that
// does not echo it.
LocalEcho bool `json:"localEcho,omitempty"`
// Encoding is the output encoding the host's new terminals decode
// with, a vt.OutputEncoding; empty is UTF-8.
Encoding string `json:"encoding,omitempty"`
// SessionLog logs each of the host's terminals from when it
// connects.
SessionLog bool `json:"sessionLog,omitempty"`
// Provider is who the server is rented from, as the user names it.
Provider string `json:"provider,omitempty"`
// Renewal is the host's subscription; its zero value keeps none.
Renewal Renewal `json:"renewal,omitzero"`
// Note is the user's own note on the host, as what it is for.
Note string `json:"note,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
LastUsed time.Time `json:"lastUsed,omitzero"`
}
Host is a saved host, an SSH or Telnet server or a serial device: where it is and how to reach it. It holds no secret; host-owned and reusable secrets live in the encrypted store.
func ParseStreamURL ¶ added in v0.0.14
ParseStreamURL reads a quick connect destination naming a Telnet or serial host: telnet://[user@]host[:port], or serial://DEVICE[?baud=9600&data=8&parity=none&stop=1], DEVICE being a path such as /dev/ttyUSB0 or a port such as COM3. ok is false for any other destination, which is left to SSH. The host has no ID.
func (Host) LogsIn ¶ added in v0.0.14
LogsIn reports whether a Telnet or serial host answers its login prompts with its user and password.
func (*Host) Normalize ¶
func (h *Host) Normalize()
Normalize trims the host's fields and fills defaults.
func (Host) SSH ¶ added in v0.0.14
SSH reports whether the host is an SSH server, with files, AI, metrics, port forwards and jump hosts; Telnet and serial hosts have a terminal only.
type InUseError ¶
InUseError reports an entry other entries still use, so it can not be deleted: the hosts (and forwards) using it.
func (*InUseError) Error ¶
func (e *InUseError) Error() string
type MetricsMode ¶
type MetricsMode string
MetricsMode is a host's metrics bar: follow the global setting, on, or off. Off hides the bar while the global setting is on. The global setting off hides every host, including one set to on.
const ( // MetricsFollow uses the global metrics setting. MetricsFollow MetricsMode = "" // MetricsOn shows the bar while the global setting is on. MetricsOn MetricsMode = "on" // MetricsOff never collects or shows the bar for this host. MetricsOff MetricsMode = "off" )
type NewLine ¶ added in v0.0.14
type NewLine string
NewLine is what Enter sends to a Telnet or serial host.
type Protocol ¶ added in v0.0.14
type Protocol string
Protocol is how a host is reached.
func (Protocol) DefaultPort ¶ added in v0.0.14
DefaultPort is the port a host of p listens on unless told otherwise; 0 for a serial host.
type Proxy ¶
type Proxy struct {
ID string `json:"id"`
Name string `json:"name"`
Kind ProxyKind `json:"kind"`
Address string `json:"address"`
Port int `json:"port"`
// User, when set, authenticates (Basic for HTTP, username and
// password for SOCKS5) with the password in the keychain.
User string `json:"user,omitempty"`
Note string `json:"note,omitempty"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
Proxy is an HTTP or SOCKS5 proxy the first hop to a host is dialed through. Its password is in the keychain under proxy/<id>/password.
type Renewal ¶ added in v0.0.17
type Renewal struct {
Start string `json:"start"`
Months int `json:"months"`
Remind int `json:"remind"`
}
Renewal is a host's subscription, as a rented server bills: it began on Start and renews every Months months, on the day of the month it began, or the month's last day where that comes first. Remind is how many days before each renewal to remind of it, 0 for never.
func (Renewal) DaysLeft ¶ added in v0.0.17
DaysLeft is how many days from now's day the next renewal is, 0 for today.
func (Renewal) Next ¶ added in v0.0.17
Next is the first renewal on or after the day of now (in now's location), as a calendar day at midnight UTC: the one of today is still to come until the day is over. The day it began is not one.
type SerialLine ¶ added in v0.0.14
type SerialLine struct {
Device string `json:"device"`
Baud int `json:"baud"`
DataBits int `json:"dataBits"`
Parity string `json:"parity"`
StopBits string `json:"stopBits"`
}
SerialLine is a serial host's port and its settings.
func (SerialLine) Config ¶ added in v0.0.14
func (l SerialLine) Config() serial.Config
Config is the line as the serial package opens it.
type Snapshot ¶
type Snapshot struct {
Hosts []Host `json:"hosts"`
Credentials []Credential `json:"credentials"`
Proxies []Proxy `json:"proxies"`
Forwards []Forward `json:"forwards"`
Groups []string `json:"groups,omitempty"`
GroupOrder []string `json:"groupOrder,omitempty"`
GroupLooks map[string]GroupLook `json:"groupLooks,omitempty"`
Snippets []Snippet `json:"snippets,omitempty"`
}
Snapshot is everything the store holds, for a backup. Like the store, it holds no secret.
type Snippet ¶
type Snippet struct {
ID string `json:"id"`
Name string `json:"name"`
Group string `json:"group,omitempty"`
SendEnter bool `json:"sendEnter"`
}
Snippet holds metadata only; its command body belongs in the encrypted store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps hosts, credentials, proxies and port forwards in a JSON file. It is safe for concurrent use.
func Open ¶
Open reads the store at path; a missing file is an empty store. A file of an older schema version is discarded and an empty store written in its place: there is no migration. An empty path keeps the store in memory only.
func (*Store) AddCredential ¶
func (s *Store) AddCredential(c Credential) (Credential, error)
AddCredential adds a credential under the ID it has (from NewID), so its secrets can be stored before it is.
func (*Store) AddForward ¶
AddForward adds a port forward under the ID it has, when it has one (made with NewID, so that its keychain entry can be written first).
func (*Store) AddGroup ¶
AddGroup makes an empty group, for hosts to be moved into, or with a path ("Prod/Web") a subgroup. The names are trimmed; a group of that name, in any case, is a "taken" FieldError.
func (*Store) AddGroupLook ¶ added in v0.0.24
AddGroupLook is AddGroup making a group that looks as look.
func (*Store) AddProxy ¶
AddProxy adds a proxy under the ID it has (from NewID), so its password can be stored before it is.
func (*Store) AddSnippet ¶
AddSnippet adds an entry under its supplied ID so its body can be saved first.
func (*Store) Credential ¶
func (s *Store) Credential(id string) (Credential, bool)
Credential returns the credential of id.
func (*Store) CredentialUsers ¶
CredentialUsers are the hosts that use the credential of id, sorted.
func (*Store) Credentials ¶
func (s *Store) Credentials() []Credential
Credentials returns every credential, sorted by name.
func (*Store) Delete ¶
Delete removes the host of id. A host other hosts jump through, or port forwards enter by, is in use and not deleted (an *InUseError).
func (*Store) DeleteCredential ¶
DeleteCredential removes a credential no host uses; one in use is an *InUseError listing the hosts.
func (*Store) DeleteForward ¶
DeleteForward removes a port forward.
func (*Store) DeleteGroup ¶
DeleteGroup removes a group and its subgroups. Their hosts stay, in no group.
func (*Store) DeleteProxy ¶
DeleteProxy removes a proxy no host uses; one in use is an *InUseError listing the hosts.
func (*Store) DeleteSnippet ¶
DeleteSnippet removes metadata; the app coordinates encrypted body deletion.
func (*Store) Discarded ¶
Discarded are the IDs of the hosts of an older data file Open threw away, so that the caller can drop what it kept for them elsewhere.
func (*Store) EditGroup ¶ added in v0.0.24
EditGroup is RenameGroup giving the group look as well, in one write. The group is kept from then on, should it be left empty.
func (*Store) Groups ¶
Groups returns the names of the groups in display order: those of the hosts and those made with AddGroup, empty or not, and the group of each subgroup. Hosts without a group are in none of them.
func (*Store) JumpPath ¶
JumpPath is the hosts dialed through to reach id, first hop first, each jump host's own chain expanded before it.
func (*Store) MoveGroup ¶ added in v0.0.8
MoveGroup places name immediately before or after target, saving the full display order without making implicit groups into permanent empty groups. A group moved beside one of another group goes into that group, with its subgroups, hosts and look; it never goes into itself.
func (*Store) NestGroup ¶ added in v0.0.26
NestGroup moves name, with its subgroups, hosts and look, into parent, "" for the top level, after the groups already there.
func (*Store) ProxyUsers ¶
ProxyUsers are the hosts that use the proxy of id, sorted.
func (*Store) RenameGroup ¶
RenameGroup renames a group, and moves its hosts and subgroups with it.
func (*Store) Restore ¶
Restore merges a snapshot into the store: each entry replaces the one of its ID, or is added, and nothing else is removed. A credential or proxy whose name another one here has is renamed "name (2)". Everything is checked first: when an entry is invalid, or refers to one that is neither here nor in the snapshot, nothing changes.
func (*Store) RestoreIfHostsUnchanged ¶ added in v0.0.9
RestoreIfHostsUnchanged merges only while hosts still equal a prior List result. The comparison and persistence share the store lock with other writers.
func (*Store) SaveCredential ¶
func (s *Store) SaveCredential(c Credential) (Credential, error)
SaveCredential adds a credential (no ID) or replaces the one of its ID. Names are unique, ignoring case.
func (*Store) SaveForward ¶
SaveForward adds a port forward (no ID) or replaces the one of its ID.
func (*Store) SaveSnippet ¶
SaveSnippet creates an entry with an empty ID or updates an existing one.
func (*Store) Search ¶
Search returns the hosts whose name, address, user, group, provider or note contain every word of q, ignoring case.
func (*Store) SetFavorite ¶
SetFavorite marks or unmarks a host as a favorite.