Documentation
¶
Overview ¶
Package openssh provides a rig protocol implementation that uses the system's openssh client "ssh" to connect to remote hosts.
Index ¶
- Variables
- type Config
- type Connection
- func (c *Connection) Connect(ctx context.Context) error
- func (c *Connection) Disconnect()
- func (c *Connection) ExecInteractive(ctx context.Context, cmdStr string, stdin io.Reader, stdout, stderr io.Writer) error
- func (c *Connection) IPAddress() string
- func (c *Connection) IsConnected() bool
- func (c *Connection) IsWindows() bool
- func (c *Connection) Protocol() string
- func (c *Connection) ProtocolName() string
- func (c *Connection) SetDefaults()
- func (c *Connection) StartProcess(ctx context.Context, cmdStr string, stdin io.Reader, stdout, stderr io.Writer) (protocol.Waiter, error)
- func (c *Connection) String() string
Constants ¶
This section is empty.
Variables ¶
var DefaultOptionArguments = sshconfig.OptionArguments{ "ControlPath": "~/.ssh/ctrl-%C", "ControlMaster": false, "ServerAliveInterval": "60", "ServerAliveCountMax": "3", "StrictHostKeyChecking": false, "Compression": false, "ConnectTimeout": "10", }
DefaultOptionArguments are the default options for the OpenSSH client.
var ( // ErrControlPathNotSet is returned when the controlpath is not set when disconnecting from a multiplexed connection. ErrControlPathNotSet = errors.New("controlpath not set") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Address string `yaml:"address" json:"address" validate:"required" jsonschema:"required,description=Address of the remote host"`
User *string `yaml:"user" json:"user,omitempty" jsonschema:"description=Optional SSH user"`
Port *int `yaml:"port" json:"port,omitempty" jsonschema:"minimum=1,maximum=65535,description=Optional SSH port"`
KeyPath *string `yaml:"keyPath,omitempty" json:"keyPath,omitempty" jsonschema:"description=Path to SSH private key"`
ConfigPath *string `yaml:"configPath,omitempty" json:"configPath,omitempty" jsonschema:"description=Path to SSH config file"`
Options sshconfig.OptionArguments `` /* 127-byte string literal not displayed */
DisableMultiplexing bool `` /* 148-byte string literal not displayed */
}
Config describes the configuration options for an OpenSSH connection.
func (*Config) Connection ¶
func (c *Config) Connection() (protocol.Connection, error)
Connection returns a new OpenSSH connection based on the configuration.
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults sets the default values for the configuration.
type Connection ¶
type Connection struct {
log.LoggerInjectable `yaml:"-"`
Config `yaml:",inline"`
// contains filtered or unexported fields
}
Connection is a rig.Connection implementation that uses the system openssh client "ssh" to connect to remote hosts. The connection is by default multiplexec over a control master, so that subsequent connections don't need to re-authenticate.
func NewConnection ¶
func NewConnection(cfg Config) (*Connection, error)
NewConnection creates a new OpenSSH connection. Error is currently always nil.
func (*Connection) Connect ¶
func (c *Connection) Connect(ctx context.Context) error
Connect connects to the remote host. If multiplexing is enabled, this will start a control master. If multiplexing is disabled, this will just run a noop command to check connectivity.
func (*Connection) Disconnect ¶
func (c *Connection) Disconnect()
Disconnect disconnects from the remote host. If multiplexing is enabled, this will close the control master. If multiplexing is disabled, this marks the connection as disconnected.
func (*Connection) ExecInteractive ¶
func (c *Connection) ExecInteractive(ctx context.Context, cmdStr string, stdin io.Reader, stdout, stderr io.Writer) error
ExecInteractive executes a command on the host and passes stdin/stdout/stderr as-is to the session. The session is terminated when ctx is cancelled.
func (*Connection) IPAddress ¶
func (c *Connection) IPAddress() string
IPAddress returns the IP address of the remote host.
func (*Connection) IsConnected ¶
func (c *Connection) IsConnected() bool
IsConnected returns true if the connection is alive. For multiplexed connections this probes the control master via ssh -O check. For non-multiplexed connections it runs a no-op command over a fresh session.
func (*Connection) IsWindows ¶
func (c *Connection) IsWindows() bool
IsWindows returns true if the remote host is windows. The result is cached after the first probe; subsequent calls are O(1). For reliable context propagation, Connect should be called first — detection is also triggered during Connect using the connect context.
func (*Connection) Protocol ¶
func (c *Connection) Protocol() string
Protocol returns the protocol family, "SSH".
func (*Connection) ProtocolName ¶
func (c *Connection) ProtocolName() string
ProtocolName returns the implementation name, "OpenSSH".
func (*Connection) SetDefaults ¶
func (c *Connection) SetDefaults()
SetDefaults sets default values.
func (*Connection) StartProcess ¶
func (c *Connection) StartProcess(ctx context.Context, cmdStr string, stdin io.Reader, stdout, stderr io.Writer) (protocol.Waiter, error)
StartProcess executes a command on the remote host, streaming stdin, stdout and stderr.
func (*Connection) String ¶
func (c *Connection) String() string