Documentation
¶
Overview ¶
Package ssh provides a small SSH client for running remote commands, copying files, and writing env files on a remote host.
Index ¶
- type Option
- func WithAddr(addr string, port int) Option
- func WithHostKey(publicKey string) Option
- func WithPrivateKey(envKey string, path string) Option
- func WithPrivateKeyFromEnvKey(envKey string) Option
- func WithPrivateKeyFromFile(filepath string) Option
- func WithTimeout(d time.Duration) Option
- func WithUser(user string) Option
- type RespType
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.2.6
type Option func(opt *clientOptions) error
Option configures the SSH client.
func WithHostKey ¶ added in v1.2.6
WithHostKey pins the remote host key. publicKey is a single line in authorized_keys format (e.g. the output of `ssh-keyscan -t ed25519 host`, host prefix included or not). When this option is not supplied, host key verification is DISABLED, which is only acceptable for hosts you already trust the network path to.
func WithPrivateKey ¶
WithPrivateKey loads the private key from the environment variable envKey, falling back to the file at path when the variable is unset or empty.
func WithPrivateKeyFromEnvKey ¶
WithPrivateKeyFromEnvKey loads the private key from the environment variable envKey.
func WithPrivateKeyFromFile ¶
WithPrivateKeyFromFile loads the private key from filepath. A leading ~ is expanded to the user's home directory.
func WithTimeout ¶ added in v1.2.6
WithTimeout bounds the TCP connection attempt. The default is 30 seconds.
type Runner ¶
type Runner interface {
// CreateEnvFile renders env as KEY=value lines (sorted by key, with
// ${VAR} references resolved from the local environment) and uploads it
// to path on the remote host with 0600 permissions.
CreateEnvFile(path string, env map[string]string) error
// RunRemote executes cmds sequentially in a single remote shell session,
// streaming stdout and stderr locally. It returns the first error.
RunRemote(cmds ...string) error
// CopyFiles uploads each of filepaths (resolved relative to workspace)
// into remotePath, creating remotePath if needed. permissions is an
// octal mode such as "0644"; empty defaults to "0644". Each filepath
// may contain ${workspace} and ${ENV_VAR} references, which are expanded
// before glob pattern matching. Filepaths may also be glob patterns
// (e.g., "*.txt", "bin/*", "${BUILD_DIR}/*.so").
CopyFiles(permissions, remotePath string, workspace string, filepaths ...string) error
// Close terminates the underlying SSH connection.
Close() error
}
Runner is the remote half of the script API.