gconn

package module
v0.0.0-...-fae770f Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: BSD-3-Clause Imports: 17 Imported by: 2

README

gconn GoDoc Report card

A library for executing commands on local and remote machines with helpers to handle the outputs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(c Client, cmd string, args ...string) error

Run a command with the given client ignoring all output.

func RunWithLogger

func RunWithLogger(l *log.Logger, c Client, cmd string, args ...string) error

RunWithLogger will send all output of the command to the given logger.

Types

type Client

type Client interface {
	// Create a new session for the given command.
	NewSession(cmd string, args ...string) (Session, error)
	// Dial to the given address and get a connection.
	Dial(n, addr string) (net.Conn, error)
	// Close the client and all respective sessions.
	Close() error
}

Client will create provide the connection to the target and the session for commands to be executed.

func NewLocalClient

func NewLocalClient() Client

NewLocalClient will execute commands on the local machine.

func NewLoggedClient

func NewLoggedClient(l *log.Logger, c Client) Client

NewLoggedClient will create a client, that will send all session output and error output to the given logger.

func NewSSHClient

func NewSSHClient(addr, user string, opts ...SSHOption) (Client, error)

NewSSHClient will connect via SSH to the given address using the user specified.

func NewSSHProxyClient

func NewSSHProxyClient(proxy Client, addr, user string, opts ...SSHOption) (Client, error)

NewSSHProxyClient will create a connection through a proxy client, i.e. the given client will be used as a proxy to the target configured in this client.

func NewWrappedClient

func NewWrappedClient(client Client, wrapper string) Client

NewWrappedClient will use the given client and wrap all sessions with a command. This can be used to wrap commands in a `sudo` session for example.

type SSHOption

type SSHOption func(*sshCfg) error

func SSHWithAgent

func SSHWithAgent() SSHOption

func SSHWithAskPassword

func SSHWithAskPassword() SSHOption

func SSHWithCustomAskPassword

func SSHWithCustomAskPassword(f func() (string, error)) SSHOption

func SSHWithHostCheck

func SSHWithHostCheck(f func(string, net.Addr, ssh.PublicKey) error) SSHOption

func SSHWithHostCheckFile

func SSHWithHostCheckFile() SSHOption

func SSHWithPort

func SSHWithPort(port int) SSHOption

type Session

type Session interface {
	// Close the session. Might return io.EOF if the session was already
	// closed. Especially with SSH that is expected behavior.
	Close() error

	// Get a handle to the standard input of the command session.
	StdinPipe() (io.WriteCloser, error)
	// Get a handle to the standard output of the command session.
	StdoutPipe() (io.Reader, error)
	// Get a handle to the standard error output of the command session.
	StderrPipe() (io.Reader, error)

	// Run the session. This will trigger both `Start` and `Wait`.
	Run() error
	// Start the session.
	Start() error
	// Wait for the session to finish.
	Wait() error
}

Session provides the interface for a command execution session.

Jump to

Keyboard shortcuts

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