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(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) 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
- type OptionArguments
Constants ¶
This section is empty.
Variables ¶
var DefaultOptionArguments = 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" validate:"required"` User *string `yaml:"user"` Port *int `yaml:"port"` KeyPath *string `yaml:"keyPath,omitempty"` ConfigPath *string `yaml:"configPath,omitempty"` Options OptionArguments `yaml:"options,omitempty"` DisableMultiplexing bool `yaml:"disableMultiplexing,omitempty"` }
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 will do nothing.
func (*Connection) ExecInteractive ¶
func (c *Connection) ExecInteractive(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.
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 connected.
func (*Connection) IsWindows ¶
func (c *Connection) IsWindows() bool
IsWindows returns true if the remote host is windows.
func (*Connection) Protocol ¶
func (c *Connection) Protocol() string
Protocol returns the protocol name.
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
type OptionArguments ¶
OptionArguments are options for the OpenSSH client. For example StrictHostkeyChecking: false becomes -o StrictHostKeyChecking=no.
func (OptionArguments) Copy ¶
func (o OptionArguments) Copy() OptionArguments
Copy returns a copy of the options.
func (OptionArguments) IsSet ¶
func (o OptionArguments) IsSet(key string) bool
IsSet returns true if the option is set.
func (OptionArguments) Set ¶
func (o OptionArguments) Set(key string, value any)
Set sets an option key to value.
func (OptionArguments) SetIfUnset ¶
func (o OptionArguments) SetIfUnset(key string, value any)
SetIfUnset sets the option if it's not already set.
func (OptionArguments) ToArgs ¶
func (o OptionArguments) ToArgs() []string
ToArgs converts the options to command line arguments.