ssh

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection represents an SSH connection

func NewConnection

func NewConnection(config *ConnectionConfig) *Connection

NewConnection creates a new SSH connection

func (*Connection) Close

func (c *Connection) Close() error

Close closes the SSH connection

func (*Connection) Connect

func (c *Connection) Connect(ctx context.Context) error

Connect establishes the SSH connection

func (*Connection) Execute

func (c *Connection) Execute(ctx context.Context, command string) (*ExecuteResult, error)

Execute runs a command on the remote host

type ConnectionConfig

type ConnectionConfig struct {
	Host            string        `yaml:"host" json:"host"`
	Port            int           `yaml:"port" json:"port"`
	User            string        `yaml:"user" json:"user"`
	Password        string        `yaml:"password,omitempty" json:"password,omitempty"`
	PrivateKeyPath  string        `yaml:"private_key_path,omitempty" json:"private_key_path,omitempty"`
	PrivateKey      string        `yaml:"private_key,omitempty" json:"private_key,omitempty"`
	Timeout         time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	ConnectTimeout  time.Duration `yaml:"connect_timeout,omitempty" json:"connect_timeout,omitempty"`
	KeepAlive       time.Duration `yaml:"keep_alive,omitempty" json:"keep_alive,omitempty"`
	MaxRetries      int           `yaml:"max_retries,omitempty" json:"max_retries,omitempty"`
	StrictHostCheck bool          `yaml:"strict_host_check,omitempty" json:"strict_host_check,omitempty"`
}

ConnectionConfig holds SSH connection configuration

func (*ConnectionConfig) SetDefaults

func (c *ConnectionConfig) SetDefaults()

SetDefaults sets default values for connection config

func (*ConnectionConfig) Validate

func (c *ConnectionConfig) Validate() error

Validate validates the connection configuration

type ExecuteResult

type ExecuteResult struct {
	Command  string `json:"command"`
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code"`
}

ExecuteResult holds the result of command execution

func (*ExecuteResult) Success

func (r *ExecuteResult) Success() bool

Success returns true if the command executed successfully

type Executor

type Executor interface {
	Execute(ctx context.Context, command string) (*ExecuteResult, error)
	Connect(ctx context.Context) error
	Close() error
}

Executor defines the interface for executing commands remotely

type LocalExecutor

type LocalExecutor struct{}

LocalExecutor executes commands locally for testing

func (*LocalExecutor) Close

func (l *LocalExecutor) Close() error

Close is a no-op for local execution

func (*LocalExecutor) Connect

func (l *LocalExecutor) Connect(ctx context.Context) error

Connect is a no-op for local execution

func (*LocalExecutor) Execute

func (l *LocalExecutor) Execute(ctx context.Context, command string) (*ExecuteResult, error)

Execute runs a command locally using shell

type MockExecutor

type MockExecutor struct {
	// contains filtered or unexported fields
}

MockExecutor is a mock implementation of the Executor interface for testing

func NewMockExecutor

func NewMockExecutor() *MockExecutor

NewMockExecutor creates a new mock executor

func (*MockExecutor) Close

func (m *MockExecutor) Close() error

Close closes the connection (mock implementation)

func (*MockExecutor) Connect

func (m *MockExecutor) Connect(ctx context.Context) error

Connect establishes a connection (mock implementation)

func (*MockExecutor) Execute

func (m *MockExecutor) Execute(ctx context.Context, command string) (*ExecuteResult, error)

Execute executes a command (mock implementation)

type RealSSHConnection

type RealSSHConnection struct {
	// contains filtered or unexported fields
}

RealSSHConnection implements the Executor interface using real SSH connections

func NewRealSSHConnection

func NewRealSSHConnection(config *ConnectionConfig) *RealSSHConnection

NewRealSSHConnection creates a new real SSH connection

func (*RealSSHConnection) Close

func (c *RealSSHConnection) Close() error

Close closes the SSH connection

func (*RealSSHConnection) Connect

func (c *RealSSHConnection) Connect(ctx context.Context) error

Connect establishes the SSH connection

func (*RealSSHConnection) Execute

func (c *RealSSHConnection) Execute(ctx context.Context, command string) (*ExecuteResult, error)

Execute executes a command over SSH

type SSHConnectionPool

type SSHConnectionPool struct {
	// contains filtered or unexported fields
}

SSHConnectionPool manages a pool of SSH connections for efficiency

func NewSSHConnectionPool

func NewSSHConnectionPool(maxIdle, maxActive int) *SSHConnectionPool

NewSSHConnectionPool creates a new connection pool

func (*SSHConnectionPool) CloseAll

func (p *SSHConnectionPool) CloseAll() error

CloseAll closes all connections in the pool

func (*SSHConnectionPool) GetConnection

func (p *SSHConnectionPool) GetConnection(config *ConnectionConfig) (*RealSSHConnection, error)

GetConnection gets or creates a connection for the given configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL