ssh

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPortOpen

func IsPortOpen(portChecker func(port int) Result, port int) resource.StateRefreshFunc

IsPortOpen returns a StateRefreshFunc for determining if the specified port is open

func IsServiceRunning

func IsServiceRunning(serviceChecker func(serviceName string) Result, serviceName string) resource.StateRefreshFunc

IsServiceRunning returns a StateRefreshFunc for determining if the specified service is running

func LogBufferContents

func LogBufferContents(buffer *bytes.Buffer)

LogBufferContents waits for data to be sent to the buffer and logs each line until the buffer can't be read from anymore if a copyBuffer is passed (not nil) the output will also be copied to it

func NewOpenPortCheckerFunc

func NewOpenPortCheckerFunc(client *Client) func(port int) Result

NewOpenPortCheckerFunc constructs a function based on the specified ssh.Client, which checks if the specified port is open

func NewServiceStatusChecker

func NewServiceStatusChecker(client *Client) func(serviceName string) Result

NewServiceStatusChecker constructs a function based on the specified ssh.Client, which checks if the specified service is running

func PanicOnError

func PanicOnError(r Result)

PanicOnError panic if a result has completed with an error (useful in situations where errors are not recoverable, but we want to allow error handling at an upper layer

func WaitForOpenPort

func WaitForOpenPort(portChecker func(port int) Result, port int) error

WaitForOpenPort returns when the specified port is open, or with an error if the operation times out

func WaitForService

func WaitForService(serviceChecker func(serviceName string) Result, serviceName string) error

WaitForService returns when the specified service is found to be running, or with an error if the operation times out

func WithHostKey

func WithHostKey(hostKey string) func(params *Connection) error

WithHostKey specifies the host keys of the target host

func WithHostParams

func WithHostParams(user string, host string, port int) func(params *Connection) error

WithHostParams accepts the minimal set of parameters required to make a connection

func WithPrivateKey

func WithPrivateKey(privateKey string) func(params *Connection) error

WithPrivateKey specifies the private keys to use for connecting to the target host

Types

type Agent

type Agent struct {
	Agent         bool   `json:"agent,string,omitempty"`
	AgentIdentity string `json:"agent_identity,omitempty"`
}

Agent holds SSH agent configuration parameters

type Bastion

type Bastion struct {
	BastionUser       string `json:"bastion_user,omitempty"`
	BastionPassword   string `json:"bastion_password,omitempty"`
	BastionPrivateKey string `json:"bastion_private_key,omitempty"`
	BastionHost       string `json:"bastion_host,omitempty"`
	BastionHostKey    string `json:"bastion_host_key,omitempty"`
	BastionPort       int    `json:"bastion_port,string,omitempty"`
}

Bastion holds all parameters required to make an SSH connection through a bastion host

type Client

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

Client abstracts all usage of SSH primitives into a nice, easy-to-use API

func NewClient

func NewClient(params ...func(*Connection) error) (*Client, error)

NewClient creates a new SSH client

func (*Client) RunCommand

func (c *Client) RunCommand(command string) (res Result)

RunCommand executes a command on the remote host and returns the command's output, the SSH communicator's output and an error

func (*Client) UploadData

func (c *Client) UploadData(remotePath string, input io.Reader) (res Result)

UploadData uploads all contents from the specified io.Reader to the remote path

func (*Client) UploadFile

func (c *Client) UploadFile(remotePath string, file *os.File) (res Result)

UploadFile uploads a local file to the remote path

type Connection

type Connection struct {
	User       string `json:"user,omitempty"`
	Password   string `json:"password,omitempty"`
	PrivateKey string `json:"private_key,omitempty"`
	Host       string `json:"host,omitempty"`
	HostKey    string `json:"host_key,omitempty"`
	Port       int    `json:"port,string,omitempty"`
	Bastion
	Agent
}

Connection holds all connection parameters used to connect to a host via SSH

type OutputBuffer

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

OutputBuffer used to send SSH command output to log.Printf

func WithLogging

func WithLogging() *OutputBuffer

WithLogging initializes a new output buffer

func (*OutputBuffer) Output

func (o *OutputBuffer) Output(line string)

Output writes the passed line into a byte buffer for later consumption; respects the terraform.UIOutput interface

type Result

type Result struct {
	Cmd    string
	Stdout string
	Stderr string
	Err    error
}

Result represents the result of a SSH command

func (*Result) Debug

func (r *Result) Debug()

Debug print debugging information and return the same object

func (Result) Error

func (r Result) Error() string

Error implementation of the error interface

func (*Result) GetDebugInfo

func (r *Result) GetDebugInfo() string

GetDebugInfo returns debugging information to be displayed where needed

func (Result) IsError

func (r Result) IsError() bool

IsError true if the Result contains an error

Jump to

Keyboard shortcuts

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