ssh

package
v3.1.0-rc.0-20240516-1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 13

Documentation

Overview

Package ssh implements the ssh client.

Index

Constants

View Source
const (
	DefaultSSHPort = 22
	DefaultTimeout = 15
	ROOT           = "root"
)

Default values.

Variables

This section is empty.

Functions

func SudoPrefix

func SudoPrefix(cmd string) string

SudoPrefix returns the prefix for sudo commands.

Types

type Client

type Client struct {
	logr.Logger
	// contains filtered or unexported fields
}

Client is a wrapper around the SSH client that provides a few helper.

func (*Client) Close

func (c *Client) Close()

Close closes the underlying ssh and sftp connection.

func (*Client) Cmd

func (c *Client) Cmd(cmd string) (string, error)

Cmd executes a command on the remote host.

func (*Client) Cmdf

func (c *Client) Cmdf(cmd string, a ...any) (string, error)

Cmdf execute a formatting command according to the format specifier.

func (*Client) Connect

func (c *Client) Connect() error

Connect connects to the host using the provided ssh information.

func (*Client) ConnectSftpClient

func (c *Client) ConnectSftpClient(opts ...sftp.ClientOption) error

ConnectSftpClient connects to the host sftp client using the provided ssh information.

func (*Client) Copy

func (c *Client) Copy(src, dst string) error

Copy copies a file to the remote host.

func (*Client) Fetch

func (c *Client) Fetch(local, remote string) error

Fetch fetches a file from the remote host.

func (*Client) Fs

func (c *Client) Fs() filesystem.Interface

Fs returns the filesystem of the ssh client.

func (*Client) Host

func (c *Client) Host() string

Host returns the host name of the ssh client.

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the remote host is reachable.

func (*Client) RemoteFileExist

func (c *Client) RemoteFileExist(remote string) (bool, error)

RemoteFileExist checks if a file exists on the remote host.

func (*Client) SudoCmd

func (c *Client) SudoCmd(cmd string) (string, error)

SudoCmd executes a command on the remote host with sudo.

func (*Client) SudoCmdf

func (c *Client) SudoCmdf(cmd string, a ...any) (string, error)

SudoCmdf executes a formatting command on the remote host with sudo.

type Command

type Command interface {
	Cmd(cmd string) (string, error)
	Cmdf(cmd string, a ...any) (string, error)
	SudoCmd(cmd string) (string, error)
	SudoCmdf(cmd string, a ...any) (string, error)
}

Command collects the methods for executing commands.

type Connector

type Connector interface {
	Connect() error
	Close()
}

Connector collects the methods for connecting and closing.

type Interface

type Interface interface {
	Connector
	Command
	Sftp
	LocalFileSystem
	Ping() error
	Host() string
}

Interface is the interface for ssh client.

func NewClient

func NewClient(host string, auth infrav1.Auth, log *logr.Logger) Interface

NewClient returns a new client given ssh information.

type LocalFileSystem

type LocalFileSystem interface {
	Fs() filesystem.Interface
}

LocalFileSystem collects the methods for return a local filesystem.

type Sftp

type Sftp interface {
	Copy(local, remote string) error
	Fetch(local, remote string) error
	RemoteFileExist(remote string) (bool, error)
}

Sftp collects the methods for sftp.

Jump to

Keyboard shortcuts

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