Documentation
¶
Index ¶
- Constants
- func CloseIgnore(errp *error, c io.Closer, ignore ...error)
- func GetSudoPassword(key string) (string, error)
- func ValidateCommand(command string) error
- type Config
- type ConnectionPool
- type PooledConnection
- type SSHClient
- func (c *SSHClient) Close() error
- func (c *SSHClient) Connect() error
- func (c *SSHClient) ExecuteCommand() (err error)
- func (c *SSHClient) ExecuteCommandWithOutput() (output string, err error)
- func (c *SSHClient) ExecuteScript(localScriptPath string) (output string, err error)
- func (c *SSHClient) ExecuteScriptWithArgs(localScriptPath string, args []string) (output string, err error)
- func (c *SSHClient) ExecuteSftp() (err error)
- func (c *SSHClient) ForceClose() error
Constants ¶
const ( DefaultSSHPort = "22" DefaultSSHUser = "master" DefaultSudoKey = "master" DefaultTimeout = 30 * time.Second SudoPrompt = "[sudo] password" PasswordPromptEnd = ": " )
const KeyringServiceName = "sshx"
Variables ¶
This section is empty.
Functions ¶
func CloseIgnore ¶
CloseIgnore closes the closer and handles errors appropriately. It will ignore errors in the ignore list and merge other errors into errp. This is useful for defer statements where we want to handle close errors but allow certain expected errors to be silently ignored.
Usage example:
func handle(r io.ReadCloser) (err error) {
defer CloseIgnore(&err, r, net.ErrClosed)
// ... read ...
return
}
func GetSudoPassword ¶
GetSudoPassword reads sudo password from system keyring (cross-platform support) macOS: Keychain, Linux: Secret Service (gnome-keyring/kwallet), Windows: Credential Manager
func ValidateCommand ¶
ValidateCommand validates command safety
Types ¶
type Config ¶
type Config struct {
Host string
Port string
User string
Password string
KeyPath string
SudoKey string
Command string
Mode string
SafetyCheck bool
Force bool
SftpAction string
LocalPath string
RemotePath string
PasswordAction string
PasswordKey string
PasswordValue string
}
Config represents SSH configuration properties for connecting to remote hosts.
type ConnectionPool ¶
type ConnectionPool struct {
// contains filtered or unexported fields
}
ConnectionPool manages SSH connections with pooling and health checks
func GetConnectionPool ¶
func GetConnectionPool() *ConnectionPool
GetConnectionPool returns the global connection pool singleton
func NewConnectionPool ¶
func NewConnectionPool() *ConnectionPool
NewConnectionPool creates a new connection pool
func (*ConnectionPool) Close ¶
func (p *ConnectionPool) Close()
Close closes all connections in the pool
func (*ConnectionPool) GetConnection ¶
func (p *ConnectionPool) GetConnection(config *Config) (*ssh.Client, error)
GetConnection retrieves or creates a connection from the pool
func (*ConnectionPool) ReleaseConnection ¶
func (p *ConnectionPool) ReleaseConnection(config *Config)
ReleaseConnection releases a connection back to the pool
func (*ConnectionPool) Stats ¶
func (p *ConnectionPool) Stats() map[string]interface{}
Stats returns connection pool statistics
type PooledConnection ¶
type PooledConnection struct {
// contains filtered or unexported fields
}
PooledConnection represents a pooled SSH connection
type SSHClient ¶
type SSHClient struct {
// contains filtered or unexported fields
}
SSHClient wraps an ssh.Client with optional pooled and sftp helpers.
func (*SSHClient) ExecuteCommand ¶
ExecuteCommand executes a command
func (*SSHClient) ExecuteCommandWithOutput ¶
ExecuteCommandWithOutput executes a command and returns the output
func (*SSHClient) ExecuteScript ¶
ExecuteScript executes a local script file 1. Upload script to remote temp directory 2. Add execute permission 3. Execute script 4. Clean up temp file
func (*SSHClient) ExecuteScriptWithArgs ¶
func (c *SSHClient) ExecuteScriptWithArgs(localScriptPath string, args []string) (output string, err error)
ExecuteScriptWithArgs executes a script with arguments
func (*SSHClient) ExecuteSftp ¶
ExecuteSftp executes SFTP operations
func (*SSHClient) ForceClose ¶
ForceClose forcefully closes the connection (does not release back to pool)