ssh

package
v0.0.0-...-19f3ddf Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package ssh helps manage a pool of SSH clients. This file was copy-pasted from go/src/infra/libs of chromium repo to make cros-servod build. Let's call this "vendoring a pinned version of sshpool".

Index

Constants

This section is empty.

Variables

View Source
var SSHSigner ssh.Signer

SSHSigner public key

Functions

This section is empty.

Types

type Config

type Config interface {
	// Load implements reading configuration from the given ssh_config file
	Load(sshConfigPath string) error
	// Proxy returns proxy configuration used to establish SSH tunnel.
	Proxy(host string) *proxyConfig
	// SSHConfig returns ssh ClientConfig.
	SSHConfig(host string) *ssh.ClientConfig
}

Config is the interface that wraps the SSH and TLS configurations

func NewDefaultConfig

func NewDefaultConfig() (Config, error)

NewDefaultConfig creates a new instance of Config structure and populates it with the default SSH config.

type Pool

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

Pool is a pool of SSH clients to reuse.

Clients are pooled by the hostname they are connected to.

Users should call Get, which returns a Client from the pool if available, or creates and returns a new Client. The returned Client is not guaranteed to be good, e.g., the connection may have broken while the Client was in the pool.

The user should put the SSH client back into the pool after use. The user should not close the Client as Pool will close it if bad.

The user should Close the pool after use, to free any SSH Clients in the pool.

func New

func New(config Config) *Pool

New returns a new Pool. The provided ssh config is used for new SSH connections if pool has none to reuse.

config: SSH configuration to configure the new clients.
tlsConfig: Optional TLS configuration to establish SSH connections over TLS channel.

func (*Pool) Close

func (p *Pool) Close() error

Close closes all SSH clients in the Pool.

func (*Pool) Get

func (p *Pool) Get(host string) (*ssh.Client, error)

Get returns a good SSH client.

func (*Pool) GetContext

func (p *Pool) GetContext(ctx context.Context, host string) (*ssh.Client, error)

GetContext returns a good SSH client within the context timeout.

func (*Pool) Put

func (p *Pool) Put(host string, c *ssh.Client)

Put puts the client back in the pool if it is good. Otherwise, the Client is closed.

type RunResult

type RunResult struct {
	// Command executed on the resource.
	Command string
	// Exit code return.
	// Eg: 0 - everything is good
	// 	   1 - executed stop with error code `1`
	//     15 - timeout of execution
	ExitCode int
	// Standard output
	Stdout string
	// Standard error output
	Stderr string
}

RunResult represents result of executed command.

func Run

func Run(ctx context.Context, pool *Pool, addr string, cmd string) (result *RunResult)

Run executes command on the target address by SSH.

Jump to

Keyboard shortcuts

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