ssh

package
v0.123.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MPL-2.0 Imports: 23 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// TrySudo is a shell function that tries to execute a command with sudo if the user has sudo permissions.
	// The result is cached both in the provider (across shell invocations) and in _try_sudo_use_sudo (within a script).
	TrySudo = `_try_sudo_check(){ ` +
		`if [ -z "${_try_sudo_cached:-}" ]; then ` +
		`_try_sudo_use_sudo="${TRY_SUDO_USE_SUDO:-0}"; ` +
		`_try_sudo_cached=1; ` +
		`fi; ` +
		`}; ` +
		`try_sudo(){ ` +
		`_try_sudo_check; ` +
		`if [ "$_try_sudo_use_sudo" = "1" ]; then ` +
		`sudo "$@"; ` +
		`else ` +
		`"$@"; ` +
		`fi; ` +
		`}`
)

Variables

This section is empty.

Functions

func NewErrUserHasNoPermission added in v0.46.4

func NewErrUserHasNoPermission(username string) error

NewErrUserHasNoPermission creates a new error indicating that the SSH user does not have required permissions.

func ShellQuote added in v0.118.0

func ShellQuote(s string) string

ShellQuote returns s wrapped in single quotes so that a POSIX shell treats it as a single literal word.

Types

type Client

type Client interface {
	// Username returns the SSH username.
	Username() string

	// ExecuteNodeCommands executes a command on a node.
	ExecuteNodeCommands(ctx context.Context, nodeName string, commands []string) ([]byte, error)

	// NodeUpload uploads a file to a node by SFTP.
	NodeUpload(ctx context.Context, nodeName string,
		remoteFileDir string, fileUploadRequest *api.FileUploadRequest) error

	// NodeStreamUpload uploads a file to a node by streaming its content over SSH.
	NodeStreamUpload(ctx context.Context, nodeName string,
		remoteFileDir string, fileUploadRequest *api.FileUploadRequest) error
}

Client is an interface for performing SSH requests against the Proxmox Nodes.

func NewClient

func NewClient(
	username string, password string,
	agent bool, agentSocket string, agentForwarding bool,
	privateKey string,
	socks5Server string, socks5Username string, socks5Password string,
	nodeResolver NodeResolver,
) (Client, error)

NewClient creates a new SSH client.

type NodeResolver

type NodeResolver interface {
	Resolve(ctx context.Context, nodeName string) (ProxmoxNode, error)
}

NodeResolver is an interface for resolving node names to IP addresses to use for SSH connection.

type ProxmoxNode added in v0.31.0

type ProxmoxNode struct {
	Address string
	Port    int32
}

ProxmoxNode represents node address and port for SSH connection.

Jump to

Keyboard shortcuts

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