pc

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(client ssh.Client, src, dst string) error

func CreateDir

func CreateDir(ctx context.Context, client ssh.Client, dir string, ow OverwriteDir, sudo Sudo) error

func DeleteDir

func DeleteDir(ctx context.Context, client ssh.Client, dir string, sudo Sudo) error

func DeleteFile

func DeleteFile(client ssh.Client, file string, sudo Sudo) error

func ReadFile

func ReadFile(ctx context.Context, client ssh.Client, filename string, sudo Sudo) (string, error)

func Run

func Run(client ssh.Client, cmd string) error

func RunSafeOutput

func RunSafeOutput(client ssh.Client, cmd string, args []string) (string, error)

RunSafeOutput behaves like client.Output(), but assumes args may come from user-input and may be malicious. See RunSafeShell().

func RunSafeShell

func RunSafeShell(client ssh.Client, sin io.Reader, sout, serr io.Writer, cmd string, args []string) error

RunSafeShell behaves like client.Shell(), but assumes that args may come from user-input, and may intentionally be trying to compromise the security of the system. The ssh remote command always runs in the context of a shell, and therefore user args may try to take advantage of shell interpolation of injected commands, pipes, redirects, and evaluation of ssh shell environment variables. To avoid this, RunSafeShell writes the args to a file, and runs the cmd binary without shell interpretation of the arguments. It is assumed that cmd is not from user-supplied input, and is well-formed and trusted.

func WriteFile

func WriteFile(client ssh.Client, file string, contents string, kind string, sudo Sudo) error

WriteFile writes the file contents optionally in sudo mode

Types

type DummyClient

type DummyClient struct {
	Out string
	Err error
}

func (*DummyClient) AddHop

func (s *DummyClient) AddHop(host string, port int) (ssh.Client, error)

func (*DummyClient) Output

func (s *DummyClient) Output(command string) (string, error)

func (*DummyClient) OutputWithTimeout

func (s *DummyClient) OutputWithTimeout(command string, timeout time.Duration) (string, error)

func (*DummyClient) Shell

func (s *DummyClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error

func (*DummyClient) Start

func (s *DummyClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)

func (*DummyClient) StartPersistentConn

func (s *DummyClient) StartPersistentConn(timeout time.Duration) error

func (*DummyClient) StopPersistentConn

func (s *DummyClient) StopPersistentConn()

func (*DummyClient) Wait

func (s *DummyClient) Wait() error

type LocalClient

type LocalClient struct {
	WorkingDir string
	// contains filtered or unexported fields
}

Implements nanobox-io's ssh.Client interface, but runs commands locally. This is used for kubernetes DIND or other local testing.

func (*LocalClient) AddHop

func (s *LocalClient) AddHop(host string, port int) (ssh.Client, error)

AddHop for LocalClient returns an unmodified LocalClient

func (*LocalClient) Output

func (s *LocalClient) Output(command string) (string, error)

Output returns the output of the command run on the remote host.

func (*LocalClient) OutputWithTimeout

func (s *LocalClient) OutputWithTimeout(command string, timeout time.Duration) (string, error)

For local, timeout is irrelevant

func (*LocalClient) Shell

func (s *LocalClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error

Shell requests a shell from the remote. If an arg is passed, it tries to exec them on the server.

func (*LocalClient) Start

func (s *LocalClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)

Start starts the specified command without waiting for it to finish. You have to call the Wait function for that.

The first two io.ReadCloser are the standard output and the standard error of the executing command respectively. The returned error follows the same logic as in the exec.Cmd.Start function.

func (*LocalClient) StartPersistentConn

func (nc *LocalClient) StartPersistentConn(timeout time.Duration) error

No-op for local client

func (*LocalClient) StopPersistentConn

func (nc *LocalClient) StopPersistentConn()

No-op for local client

func (*LocalClient) Wait

func (s *LocalClient) Wait() error

Wait waits for the command started by the Start function to exit. The returned error follows the same logic as in the exec.Cmd.Wait function.

type NopReadCloser

type NopReadCloser struct {
	io.Reader
}

For use with DummyClient Start() method

func (NopReadCloser) Close

func (NopReadCloser) Close() error

type NopWriteCloser

type NopWriteCloser struct {
	io.Writer
}

func (NopWriteCloser) Close

func (NopWriteCloser) Close() error

type NullWriter

type NullWriter struct{}

func (NullWriter) Write

func (NullWriter) Write(p []byte) (int, error)

type OverwriteDir

type OverwriteDir bool

OverwriteDir is a toggle to indicate overwrite during dir creation

var NoOverwrite OverwriteDir = false
var Overwrite OverwriteDir = true

type SSHClientOp

type SSHClientOp func(sshp *SSHOptions)

func WithCachedIp

func WithCachedIp(cached bool) SSHClientOp

func WithTimeout

func WithTimeout(timeout time.Duration) SSHClientOp

func WithUser

func WithUser(user string) SSHClientOp

type SSHOptions

type SSHOptions struct {
	Timeout  time.Duration
	User     string
	CachedIP bool
}

func (*SSHOptions) Apply

func (o *SSHOptions) Apply(ops []SSHClientOp)

type Sudo

type Sudo bool

Sudo is a toggle for executing as superuser

var NoSudo Sudo = false

NoSudo means dont run in sudo mode

var SudoOn Sudo = true

SudoOn means run in sudo mode

type TestClient

type TestClient struct {
	Cmds            []string
	OutputResponder func(cmd string) (string, error)
}

TestClient is designed for unit tests to accumulate and check what commands were issues, and optionally provide responses to certain commands.

func (*TestClient) AddHop

func (s *TestClient) AddHop(host string, port int) (ssh.Client, error)

func (*TestClient) Output

func (s *TestClient) Output(command string) (string, error)

func (*TestClient) OutputWithTimeout

func (s *TestClient) OutputWithTimeout(command string, Timeout time.Duration) (string, error)

func (*TestClient) Shell

func (s *TestClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error

func (*TestClient) Start

func (s *TestClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)

func (*TestClient) StartPersistentConn

func (s *TestClient) StartPersistentConn(timeout time.Duration) error

func (*TestClient) StopPersistentConn

func (s *TestClient) StopPersistentConn()

func (*TestClient) Wait

func (s *TestClient) Wait() error

Jump to

Keyboard shortcuts

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