ssh

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTerminated = &TerminatedError{}

ErrTerminated - command session terminated

Functions

This section is empty.

Types

type Listener

type Listener func(stdout string, hasMore bool)

Listener represent command listener (it will send stdout fragments as thier being available on stdout)

type MultiCommandSession

type MultiCommandSession interface {
	Run(command string, listener Listener, timeoutMs int, terminators ...string) (string, error)

	ShellPrompt() string

	System() string

	Reconnect() error

	Close()
}

MultiCommandSession represents a multi command session

func NewReplayMultiCommandSession

func NewReplayMultiCommandSession(shellPrompt, system string, commands *ReplayCommands) MultiCommandSession

type ReplayCommand

type ReplayCommand struct {
	Stdin  string
	Index  int
	Stdout []string
	Error  string
}

ReplayCommand represent a replay command

type ReplayCommands

type ReplayCommands struct {
	Commands map[string]*ReplayCommand
	Keys     []string
	BaseDir  string
}

replayCommands represnets command grouped by stdin

func NewReplayCommands

func NewReplayCommands(basedir string) (*ReplayCommands, error)

NewReplayCommands create a new replay commands or error if provided basedir does not exists and can not be created

func (*ReplayCommands) Disable

func (c *ReplayCommands) Disable(source interface{}) (err error)

func (*ReplayCommands) Enable

func (c *ReplayCommands) Enable(source interface{}) (err error)

func (*ReplayCommands) Load

func (c *ReplayCommands) Load() error

Load loads replay command from base directory

func (*ReplayCommands) Next

func (c *ReplayCommands) Next(stdin string) string

return stdout pointed by index and increases index or empty string if exhausted

func (*ReplayCommands) Register

func (c *ReplayCommands) Register(stdin, stdout string)

Register register stdin and corresponding stdout conversation

func (*ReplayCommands) Shell

func (c *ReplayCommands) Shell() string

Shell returns command shell

func (*ReplayCommands) Store

func (c *ReplayCommands) Store() error

Store stores replay command in the base directory

func (*ReplayCommands) System

func (c *ReplayCommands) System() string

System returns system name

type Service

type Service interface {
	//Service returns a service wrapper
	Client() *ssh.Client

	//OpenMultiCommandSession opens multi command session
	OpenMultiCommandSession(config *SessionConfig) (MultiCommandSession, error)

	//Run runs supplied command
	Run(command string) error

	//Upload uploads provided content to specified destination
	Upload(destination string, content []byte) error

	//Download downloads content from specified source.
	Download(source string) ([]byte, error)

	//OpenTunnel opens a tunnel between local to remote for network traffic.
	OpenTunnel(localAddress, remoteAddress string) error

	NewSession() (*ssh.Session, error)

	Close() error
}

Service represents ssh service

func NewReplayService

func NewReplayService(shellPrompt, system string, commands *ReplayCommands, storage map[string][]byte) Service

func NewService

func NewService(host string, port int, authConfig *cred.Config) (Service, error)

NewService create a new ssh service, it takes host port and authentication config

type SessionConfig

type SessionConfig struct {
	EnvVariables map[string]string
	Shell        string
	Term         string
	Rows         int
	Columns      int
}

SessionConfig represents a new session config

type TerminatedError

type TerminatedError struct {
	Err error
}

func (*TerminatedError) Error

func (t *TerminatedError) Error() string

type Tunnel

type Tunnel struct {
	RemoteAddress string

	Local       net.Listener
	Connections []net.Conn
	// contains filtered or unexported fields
}

Tunnel represents a SSH forwarding link

func NewForwarding

func NewForwarding(client *ssh.Client, remoteAddress string, local net.Listener) *Tunnel

NewForwarding creates a new ssh forwarding link

func (*Tunnel) Close

func (f *Tunnel) Close() error

Close closes forwarding link

func (*Tunnel) Handle

func (f *Tunnel) Handle() error

Handle listen on local client to create tunnel with remote address.

Jump to

Keyboard shortcuts

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