Documentation
¶
Overview ¶
Package service holds what ohmyssh actually does: choosing which host to connect to, which password to try, and when to remember one.
It has no dependency on the CLI framework. That is what makes the password policy — the part with the most branches and the least obvious behaviour — testable by calling it directly instead of driving the command line.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectOptions ¶
type ConnectOptions struct {
// ConfigPath is the ssh config to read; empty means the default.
ConfigPath string
// Password is the one given on the command line. It wins over a saved one.
Password string
// NoPrompt refuses to ask for a password, so a host that needs one fails.
NoPrompt bool
// NoSavePassword uses saved passwords but does not add new ones.
NoSavePassword bool
// NoAgent skips ssh-agent authentication.
NoAgent bool
// KnownHosts overrides the known_hosts path.
KnownHosts string
// Insecure disables host key verification.
Insecure bool
// Timeout bounds the TCP connect and the SSH handshake.
Timeout time.Duration
}
ConnectOptions is what the command line decided about a connection: the service layer's view of the global flags, so that service never sees a *cli.Command.
type ConnectService ¶
type ConnectService interface {
// Browse shows the host browser and returns when the user quits.
Browse(ctx context.Context, opts ConnectOptions, filter string) error
// Connect opens an interactive session on target, running command instead
// of a login shell when command is non-empty.
Connect(ctx context.Context, opts ConnectOptions, target string, command []string) error
// Exec runs command on target without a PTY, streaming its output. command
// must be non-empty; the caller checks the command line it came from.
Exec(ctx context.Context, opts ConnectOptions, target string, command []string, stdout, stderr io.Writer) error
// Transfer moves a file or a directory tree between the local machine and
// target, reporting progress as it goes.
Transfer(ctx context.Context, opts ConnectOptions, req TransferRequest, progress sshclient.ProgressFunc) (TransferResult, error)
// AddHost writes a host the user filled in to the file ohmyssh keeps its own
// hosts in, and returns the reloaded list, which is what the browser shows
// next.
AddHost(ctx context.Context, opts ConnectOptions, host config.NewHost) ([]config.SSHHost, error)
// RemoveHost deletes a host from that same file and returns the reloaded
// list. A host that came from the user's ssh config is refused: ohmyssh does
// not write that file.
RemoveHost(ctx context.Context, opts ConnectOptions, host config.SSHHost) ([]config.SSHHost, error)
}
ConnectService covers the ways ohmyssh reaches a host: browsing them, opening an interactive session, running one command without a PTY, and moving files to and from one.
func NewConnectService ¶
func NewConnectService( logger *zerolog.Logger, transport repository.Transport, hosts repository.Hosts, creds repository.Credential, ) ConnectService
NewConnectService wires the connect use cases to their dependencies.
type CredentialService ¶
type CredentialService interface {
// Forget deletes the password saved for target, resolving that target the
// same way a connection would. ok is false when nothing was saved for it.
Forget(configPath, target string) (key string, ok bool, err error)
// ForgetAll deletes every saved password, returning how many there were.
ForgetAll() (int, error)
// Saved lists the identities with a saved password, sorted.
Saved() []string
// Path reports where the passwords are stored, for help text.
Path() string
}
CredentialService manages the passwords ohmyssh remembers.
It returns what it did rather than printing it: the command layer owns the wording, and the store stays the only thing that knows about files.
func NewCredentialService ¶
func NewCredentialService(hosts repository.Hosts, creds repository.Credential) CredentialService
NewCredentialService wires the credential use cases to their dependencies.
Unlike ConnectService there is no logger to carry here: nothing on this path has anything to say beyond what it returns.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service carries what the services in this package share. Embedding it keeps the logger out of each constructor's parameter list beyond this one.
func NewService ¶
NewService returns the shared base.
type TransferRequest ¶
type TransferRequest struct {
// Target names the host: an alias from the ssh config, or a bare
// [user@]host[:port]. It is resolved exactly the way connect resolves it.
// It is empty for a transfer the browser asked for, which names the host
// with the host itself rather than with a string it would have to re-resolve.
Target string
// Local and Remote are the two ends. Which of them is read and which is
// written is what Direction decides.
Local string
Remote string
Direction sshclient.Direction
}
TransferRequest is one file or directory tree moving between the local machine and a host.
type TransferResult ¶
TransferResult reports what a finished transfer moved, so the caller can say so without having to have measured the tree itself.