Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SSHClient ¶
type SSHClient interface {
// Create creates a new SSH client
Create(user, host, keyPath string) (SSHClient, error)
// StartTunnel starts an SSH tunnel with port forwarding from local to remote
// It returns a function to stop the tunnel and an error if the tunnel fails to start
StartTunnel(ctx context.Context, localPort, remotePort string) (stop func() error, err error)
// OpenTunnel establishes an SSH tunnel forwarding remotePort to an
// automatically chosen free local port, retrying on transient connection
// errors. It returns the tunnel info (including the local port and a stop
// function) and an error if the tunnel cannot be established.
OpenTunnel(ctx context.Context, remotePort string) (*TunnelInfo, error)
// Exec executes a command on the remote host
Exec(ctx context.Context, cmd string) (string, error)
// ExecCapture executes a command on the remote host and returns stdout and stderr separately
ExecCapture(ctx context.Context, cmd string) (stdout, stderr string, err error)
// ExecFatal executes a command and returns error if it fails
ExecFatal(ctx context.Context, cmd string) string
// Uploads a local file to the remote host
Upload(ctx context.Context, localPath, remotePath string) error
// UploadPrivate uploads like Upload but sets remotePerm on the remote path via SFTP after create and before copying payload (reduces permission race on secrets).
UploadPrivate(ctx context.Context, localPath, remotePath string, remotePerm os.FileMode) error
// Close closes the SSH connection
Close() error
}
SSHClient provides SSH operations
func NewClientWithJumpHost ¶
func NewClientWithJumpHost(jumpUser, jumpHost, jumpKeyPath, targetUser, targetHost, targetKeyPath string) (SSHClient, error)
NewClientWithJumpHost creates a new SSH client that connects through a jump host It first connects to the jump host, then establishes a connection to the target host through it
type TunnelInfo ¶
TunnelInfo holds information about an established SSH tunnel
func EstablishSSHTunnel
deprecated
func EstablishSSHTunnel(ctx context.Context, sshClient SSHClient, remotePort string) (*TunnelInfo, error)
EstablishSSHTunnel establishes an SSH tunnel with port forwarding from remote node to local port on the client.
Deprecated: use SSHClient.OpenTunnel instead. The tunnel logic now lives on the client so every SSH consumer gets free-port allocation and retry without calling a free function. This wrapper is kept for backward compatibility and simply delegates to sshClient.OpenTunnel.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ssh provides a self-healing SSH client whose connection strategy ("how we connect" — directly or through jump hosts) is separated from the operations performed over it ("what we do").
|
Package ssh provides a self-healing SSH client whose connection strategy ("how we connect" — directly or through jump hosts) is separated from the operations performed over it ("what we do"). |