ssh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// NewSession is used to open an session. The method takes no
	// parameters and returns session and nil or nil and an error if one
	// occurred.
	NewSession() (Session, error)

	// Execute is used to run command on the ssh server. It takes a
	// command as parameter and returns the output in string form and nil
	// or an empty string and an error if one occurred.
	Execute(cmd string) (string, error)

	// CloseSession is used to close an open session. The method takes no
	// parameters.
	CloseSession()
}

Client is a simple interface wrapper around golang.org/x/crypto/ssh. It requires consumer to implement the NewSession() method, the Execute() method and the CloseSession() method.

func NewClient

func NewClient(host string, username string, password string) (Client, error)

NewClient is used to create a instance of the client struct. It creates a ssh connection the to specified host. This method takes a host as parameter which should match the following pattern: 127.0.0.1:22 or example.com:22 and an username and password. It returns an instance of the client struct and nil or nil and an error if one occurred.

type ClientMock

type ClientMock struct {
	NewSessionFunc   func() (Session, error)
	ExecuteFunc      func(cmd string) (string, error)
	CloseSessionFunc func()
}

ClientMock is an struct used to mock the Client object in the ssh-provision/pkg/ssh package. It has three parameters NewSessionFunc, ExecuteFunc and CloseSessionFunc. These functions will be called if the underlying NewSession(), Execute() and CloseSession() functions are called.

func (*ClientMock) CloseSession

func (m *ClientMock) CloseSession()

CloseSession is used to close an open session. The method takes no parameters.

func (*ClientMock) Execute

func (m *ClientMock) Execute(cmd string) (string, error)

Execute is used to run command on the ssh server. It takes a command as parameter and returns the output in string form and nil or an empty string and an error if one occurred.

func (*ClientMock) NewSession

func (m *ClientMock) NewSession() (Session, error)

NewSession is used to open an session. The method takes no parameters and returns session and nil or nil and an error if one occurred.

type Session

type Session interface {
	// Output is used to run a command on the remote server and collect
	// it's output. It takes a command of type string as a parameter and
	// returns an byte array and nil or nil and an error if one occurred.
	Output(cmd string) ([]byte, error)

	// Close is used to close an open connection to the ssh server. It
	// takes no parameters and returns nil or an error if one occurred.
	Close() error
}

Session is a simple interface wrapper around the session struct from golang.org/x/crypto/ssh. It requires consumer to implement the Output() method and the Close() method.

type SessionMock

type SessionMock struct {
	OutputFunc func(cmd string) ([]byte, error)
	CloseFunc  func() error
}

SessionMock is an struct used to mock the session object in the ssh-provision/pkg/ssh package. It has two parameters OutputFunc and CloseFunc of type func. These functions will be called if the underlying Output() and Close() functions are called.

func (*SessionMock) Close

func (m *SessionMock) Close() error

Close is used to close an open connection to the ssh server. It takes no parameters and returns nil or an error if one occurred.

func (*SessionMock) Output

func (m *SessionMock) Output(cmd string) ([]byte, error)

Output is used to run a command on the remote server and collect it's output. It takes a command of type string as a parameter and returns an byte array and nil or nil and an error if one occurred.

Jump to

Keyboard shortcuts

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