assets

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 22 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 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

View Source
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.

View Source
const GroupSep = "/"

GroupSep parts a subgroup from its group: "Prod/Web". Groups go two deep: all after the first separator names the subgroup.

View Source
const IconPrefix = "icon:"

IconPrefix starts a Host.Icon naming one of the app's icons.

View Source
const RenewalRemindDefault = 3

RenewalRemindDefault is a new subscription's reminder, in days.

View Source
const SchemaVersion = 2

SchemaVersion is the version of the data file. A file of any other (older) version is discarded, not migrated.

Variables

View Source
var ErrExists = errors.New("assets: ID in use")

ErrExists is AddCredential's or AddProxy's error for an ID in use.

View Source
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).

View Source
var ErrNotFound = errors.New("assets: not found")

ErrNotFound reports an ID the store does not have.

View Source
var ErrSnapshotChanged = errors.New("assets: snapshot hosts changed")

ErrSnapshotChanged means hosts no longer match the preview baseline.

View Source
var ErrStreamURL = errors.New("assets: bad telnet:// or serial:// destination")

ErrStreamURL is a telnet:// or serial:// destination that cannot be read.

View Source
var RenewalMonths = []int{1, 3, 6, 12, 24, 36}

RenewalMonths are the periods the editor offers, in months.

View Source
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

func CleanGroup(g string) string

CleanGroup trims a group's path and the names in it.

func GroupLeaf added in v0.0.24

func GroupLeaf(g string) string

GroupLeaf returns a group's own name, without its parent's.

func GroupParent added in v0.0.24

func GroupParent(g string) string

GroupParent returns the group a subgroup is in, "" for a top-level group.

func IconText

func IconText(s string) string

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

func InGroupTree(g, group string) bool

InGroupTree reports whether g is group or one of its subgroups.

func NewID

func NewID() string

NewID makes a fresh entry ID.

func SubGroup added in v0.0.24

func SubGroup(parent, name string) string

SubGroup returns the path of the subgroup name in parent, name alone for a top-level group.

func ValidID

func ValidID(id string) bool

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

func ValidateSnippetContent(content string) error

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

func ValidateSnippetGroup(group string) error

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

func (f Forward) Exposed() bool

Exposed reports whether the forward listens beyond the loopback address, where others on the network may reach it.

func (Forward) Label

func (f Forward) Label() string

Label is the name shown for the forward.

func (Forward) Listen

func (f Forward) Listen() string

Listen is ListenAddr:ListenPort.

func (*Forward) Normalize

func (f *Forward) Normalize()

Normalize trims the forward's fields and fills defaults: it listens on 127.0.0.1 unless told otherwise.

func (Forward) Target

func (f Forward) Target() string

Target is TargetAddr:TargetPort.

func (Forward) Validate

func (f Forward) Validate() error

Validate checks a normalized forward.

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

type GroupLook struct {
	Icon  string `json:"icon,omitempty"`
	Color string `json:"color,omitempty"`
}

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"`
	// 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

func ParseStreamURL(s string) (h Host, ok bool, err error)

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) Addr

func (h Host) Addr() string

Addr is address:port for dialing.

func (Host) Label

func (h Host) Label() string

Label is the name shown for the host.

func (Host) LogsIn added in v0.0.14

func (h Host) LogsIn() bool

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

func (h Host) SSH() bool

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.

func (Host) Target

func (h Host) Target() string

Target is user@address, with :port when it is not 22; a Telnet URL, or a serial port with its speed and frame.

func (Host) Validate

func (h Host) Validate() error

Validate checks a normalized host.

type InUseError

type InUseError struct {
	Hosts    []string // IDs
	Forwards []string // IDs
}

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.

const (
	NewLineCR   NewLine = ""
	NewLineLF   NewLine = "lf"
	NewLineCRLF NewLine = "crlf"
)

func (NewLine) Bytes added in v0.0.14

func (n NewLine) Bytes() string

Bytes are the characters sent.

type Protocol added in v0.0.14

type Protocol string

Protocol is how a host is reached.

const (
	// ProtoSSH, the zero value, is an SSH server.
	ProtoSSH Protocol = ""
	// ProtoTelnet is a Telnet server: a terminal over plain TCP.
	ProtoTelnet Protocol = "telnet"
	// ProtoSerial is a device on a serial port of this computer.
	ProtoSerial Protocol = "serial"
)

func (Protocol) DefaultPort added in v0.0.14

func (p Protocol) DefaultPort() int

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.

func (Proxy) Addr

func (p Proxy) Addr() string

Addr is address:port for dialing.

func (*Proxy) Normalize

func (p *Proxy) Normalize()

Normalize trims the proxy's fields and fills defaults.

func (Proxy) Validate

func (p Proxy) Validate() error

Validate checks a normalized proxy.

type ProxyKind

type ProxyKind string

ProxyKind is the protocol of a proxy.

const (
	ProxyHTTP   ProxyKind = "http"   // HTTP CONNECT
	ProxySOCKS5 ProxyKind = "socks5" // SOCKS5, names resolved by the proxy
)

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

func (r Renewal) DaysLeft(now time.Time) (int, bool)

DaysLeft is how many days from now's day the next renewal is, 0 for today.

func (Renewal) Next added in v0.0.17

func (r Renewal) Next(now time.Time) (time.Time, bool)

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.

func (Renewal) On added in v0.0.17

func (r Renewal) On() bool

On says the host keeps a subscription.

func (Renewal) Reminding added in v0.0.17

func (r Renewal) Reminding(now time.Time) (int, bool)

Reminding says the next renewal is within the days of its reminder, and how many days away it is.

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.

func (*Snippet) Normalize

func (s *Snippet) Normalize()

Normalize trims metadata without altering the separately stored command body.

func (Snippet) Validate

func (s Snippet) Validate() error

Validate checks normalized metadata.

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

func Open(path string) (*Store, error)

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) Add

func (s *Store) Add(h Host) (Host, error)

Add validates and adds a host, giving it an ID.

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

func (s *Store) AddForward(f Forward) (Forward, error)

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

func (s *Store) AddGroup(name string) error

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

func (s *Store) AddGroupLook(name string, look GroupLook) error

AddGroupLook is AddGroup making a group that looks as look.

func (*Store) AddHost

func (s *Store) AddHost(h Host) (Host, error)

AddHost adds a host with a preallocated ID for its encrypted secrets.

func (*Store) AddProxy

func (s *Store) AddProxy(p Proxy) (Proxy, error)

AddProxy adds a proxy under the ID it has (from NewID), so its password can be stored before it is.

func (*Store) AddSnippet

func (s *Store) AddSnippet(n Snippet) (Snippet, error)

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

func (s *Store) CredentialUsers(id string) []Host

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

func (s *Store) Delete(id string) error

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

func (s *Store) DeleteCredential(id string) error

DeleteCredential removes a credential no host uses; one in use is an *InUseError listing the hosts.

func (*Store) DeleteForward

func (s *Store) DeleteForward(id string) error

DeleteForward removes a port forward.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(name string) error

DeleteGroup removes a group and its subgroups. Their hosts stay, in no group.

func (*Store) DeleteProxy

func (s *Store) DeleteProxy(id string) error

DeleteProxy removes a proxy no host uses; one in use is an *InUseError listing the hosts.

func (*Store) DeleteSnippet

func (s *Store) DeleteSnippet(id string) error

DeleteSnippet removes metadata; the app coordinates encrypted body deletion.

func (*Store) Discarded

func (s *Store) Discarded() []string

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

func (s *Store) EditGroup(old, name string, look GroupLook) error

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) Favorites

func (s *Store) Favorites() []Host

Favorites returns the favorite hosts, sorted.

func (*Store) Forward

func (s *Store) Forward(id string) (Forward, bool)

Forward returns the port forward of id.

func (*Store) Forwards

func (s *Store) Forwards() []Forward

Forwards returns every port forward, sorted by label.

func (*Store) Get

func (s *Store) Get(id string) (Host, bool)

Get returns the host of id.

func (*Store) GroupLook added in v0.0.24

func (s *Store) GroupLook(g string) GroupLook

GroupLook returns how group g looks.

func (*Store) Groups

func (s *Store) Groups() []string

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) InGroup

func (s *Store) InGroup(group string) []Host

InGroup returns the hosts of a group, "" for those without one.

func (*Store) JumpPath

func (s *Store) JumpPath(id string) ([]Host, error)

JumpPath is the hosts dialed through to reach id, first hop first, each jump host's own chain expanded before it.

func (*Store) Len

func (s *Store) Len() int

Len is the number of hosts.

func (*Store) List

func (s *Store) List() []Host

List returns every host, sorted by label.

func (*Store) MoveGroup added in v0.0.8

func (s *Store) MoveGroup(name, target string, after bool) error

MoveGroup places name immediately before or after target, saving the full display order without making implicit groups into permanent empty groups. Groups move among those of their own level: a subgroup among the subgroups of its group.

func (*Store) Proxies

func (s *Store) Proxies() []Proxy

Proxies returns every proxy, sorted by name.

func (*Store) Proxy

func (s *Store) Proxy(id string) (Proxy, bool)

Proxy returns the proxy of id.

func (*Store) ProxyUsers

func (s *Store) ProxyUsers(id string) []Host

ProxyUsers are the hosts that use the proxy of id, sorted.

func (*Store) RenameGroup

func (s *Store) RenameGroup(old, name string) error

RenameGroup renames a group, and moves its hosts and subgroups with it.

func (*Store) Restore

func (s *Store) Restore(in Snapshot) error

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

func (s *Store) RestoreIfHostsUnchanged(in Snapshot, expected []Host) error

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

func (s *Store) SaveForward(f Forward) (Forward, error)

SaveForward adds a port forward (no ID) or replaces the one of its ID.

func (*Store) SaveProxy

func (s *Store) SaveProxy(p Proxy) (Proxy, error)

SaveProxy adds a proxy (no ID) or replaces the one of its ID.

func (*Store) SaveSnippet

func (s *Store) SaveSnippet(n Snippet) (Snippet, error)

SaveSnippet creates an entry with an empty ID or updates an existing one.

func (*Store) Search

func (s *Store) Search(q string) []Host

Search returns the hosts whose name, address, user, group, provider or note contain every word of q, ignoring case.

func (*Store) SetFavorite

func (s *Store) SetFavorite(id string, fav bool) error

SetFavorite marks or unmarks a host as a favorite.

func (*Store) SetGroup

func (s *Store) SetGroup(id, group string) error

SetGroup moves a host into a group, "" for none.

func (*Store) Snapshot

func (s *Store) Snapshot() Snapshot

Snapshot returns a copy of every entry.

func (*Store) Snippet

func (s *Store) Snippet(id string) (Snippet, bool)

Snippet returns metadata for id.

func (*Store) Snippets

func (s *Store) Snippets() []Snippet

Snippets returns a copy sorted by group, then name, ignoring case.

func (*Store) Touch

func (s *Store) Touch(id string) error

Touch records that the host was just connected to.

func (*Store) Update

func (s *Store) Update(h Host) (Host, error)

Update replaces the host with h's ID.

Jump to

Keyboard shortcuts

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