conn

package
v0.0.0-...-a51ba30 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewConn = newConn

NewConn create a now connection

View Source
var Simulate = func() {
	NewConn = newFakeConn
}

Simulate switch connection to output to stdout instead of run on server

Functions

func DefaultSSHKeyPath

func DefaultSSHKeyPath() string

DefaultSSHKeyPath returns default path for ssh key

$HOME/.ssh/id_rsa

func DefaultUser

func DefaultUser() string

DefaultUser returns default user

root

Types

type Command

type Command struct {
	// Interpreter used to run command e.g. sh, bash, ruby
	Interpreter string
	// Command lines used to make up a command to be ran
	Command []string
	// Additional environment variable to be used in the command
	Env map[string]string
	// User to run the command with e.g. root, admin
	User string
}

Command represents a command to be ran on a remote host

type CommandResponse

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

CommandResponse wraps output from stdout and stderr

func (CommandResponse) Stderr

func (commandResposne CommandResponse) Stderr() string

Stderr returns anything written to stderr while running a command

func (CommandResponse) Stdout

func (commandResposne CommandResponse) Stdout() string

Stdout returns anything written to stdout while running a command

type Config

type Config struct {
	KeyFilePath string
	User        string
}

Config for connection

type Conn

type Conn interface {
	ConnectTo(string) error
	Run(Command) (Response, error)
	Close()
	Address() string
}

Conn wraps connection, run and close of connection

type LoggerSSHConn

type LoggerSSHConn struct {
	ConnectedTo string
	Commands    []Command
	// contains filtered or unexported fields
}

LoggerSSHConn log all ssh command to stdout instead of running agains a server

Used for development and simulating configuration runs

func (LoggerSSHConn) Address

func (loggerSSHConn LoggerSSHConn) Address() string

Address of the connection

func (*LoggerSSHConn) Close

func (loggerSSHConn *LoggerSSHConn) Close()

Close mark the connection as closed

func (*LoggerSSHConn) ConnectTo

func (loggerSSHConn *LoggerSSHConn) ConnectTo(hostName string) error

ConnectTo track the host name that would be used to connect to server

func (*LoggerSSHConn) Run

func (loggerSSHConn *LoggerSSHConn) Run(command Command) (Response, error)

Run output the command to logger.Debug

type Response

type Response interface {
	Stdout() string
	Stderr() string
}

Response represent the stdout and stderr of a command over ssh

type SSHConn

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

SSHConn manage connections

func (SSHConn) Address

func (sshConn SSHConn) Address() string

Address of the server the connection is communicating with

func (*SSHConn) Close

func (sshConn *SSHConn) Close()

Close connection to client

func (*SSHConn) ConnectTo

func (sshConn *SSHConn) ConnectTo(ip string) error

ConnectTo creates new connection to specified address

func (*SSHConn) Run

func (sshConn *SSHConn) Run(command Command) (Response, error)

Run a command against the sshConn host

Returns the result of stdout and stderr in the command response Returns an error if an ssh session cannot be created or if the command has a non-zero exit code

Jump to

Keyboard shortcuts

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