ssh

package
v0.0.0-...-c7702ad Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartTunnel

func StartTunnel(ctx context.Context, sshClient *ssh.Client, localPort, remotePort string) (func() error, 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

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)

	// Exec executes a command on the remote host
	Exec(ctx context.Context, cmd string) (string, 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 NewClient

func NewClient(user, host, keyPath string) (SSHClient, error)

NewClient creates a new SSH client

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

type TunnelInfo struct {
	LocalPort  int
	RemotePort int
	StopFunc   func() error
}

TunnelInfo holds information about an established SSH tunnel

func EstablishSSHTunnel

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 It automatically finds a free local port to avoid conflicts when running parallel tests. Uses retry logic for transient connection errors. Returns the tunnel info, local port and error if the tunnel fails to start

Jump to

Keyboard shortcuts

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