Documentation ¶
Index ¶
- func CopyFile(client ssh.Client, src, dst string) error
- func CreateDir(ctx context.Context, client ssh.Client, dir string, ow OverwriteDir, sudo Sudo) error
- func DeleteDir(ctx context.Context, client ssh.Client, dir string, sudo Sudo) error
- func DeleteFile(client ssh.Client, file string, sudo Sudo) error
- func ReadFile(ctx context.Context, client ssh.Client, filename string, sudo Sudo) (string, error)
- func Run(client ssh.Client, cmd string) error
- func RunSafeOutput(client ssh.Client, cmd string, args []string) (string, error)
- func RunSafeShell(client ssh.Client, sin io.Reader, sout, serr io.Writer, cmd string, ...) error
- func WriteFile(client ssh.Client, file string, contents string, kind string, sudo Sudo) error
- type DummyClient
- func (s *DummyClient) AddHop(host string, port int) (ssh.Client, error)
- func (s *DummyClient) Output(command string) (string, error)
- func (s *DummyClient) OutputWithTimeout(command string, timeout time.Duration) (string, error)
- func (s *DummyClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error
- func (s *DummyClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)
- func (s *DummyClient) StartPersistentConn(timeout time.Duration) error
- func (s *DummyClient) StopPersistentConn()
- func (s *DummyClient) Wait() error
- type LocalClient
- func (s *LocalClient) AddHop(host string, port int) (ssh.Client, error)
- func (s *LocalClient) Output(command string) (string, error)
- func (s *LocalClient) OutputWithTimeout(command string, timeout time.Duration) (string, error)
- func (s *LocalClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error
- func (s *LocalClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)
- func (nc *LocalClient) StartPersistentConn(timeout time.Duration) error
- func (nc *LocalClient) StopPersistentConn()
- func (s *LocalClient) Wait() error
- type NopReadCloser
- type NopWriteCloser
- type NullWriter
- type OverwriteDir
- type SSHClientOp
- type SSHOptions
- type Sudo
- type TestClient
- func (s *TestClient) AddHop(host string, port int) (ssh.Client, error)
- func (s *TestClient) Output(command string) (string, error)
- func (s *TestClient) OutputWithTimeout(command string, Timeout time.Duration) (string, error)
- func (s *TestClient) Shell(sin io.Reader, sout, serr io.Writer, args ...string) error
- func (s *TestClient) Start(command string) (io.ReadCloser, io.ReadCloser, io.WriteCloser, error)
- func (s *TestClient) StartPersistentConn(timeout time.Duration) error
- func (s *TestClient) StopPersistentConn()
- func (s *TestClient) Wait() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunSafeOutput ¶
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.
Types ¶
type DummyClient ¶
func (*DummyClient) OutputWithTimeout ¶
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) Output ¶
func (s *LocalClient) Output(command string) (string, error)
Output returns the output of the command run on the remote host.
func (*LocalClient) OutputWithTimeout ¶
For local, timeout is irrelevant
func (*LocalClient) Shell ¶
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 ¶
For use with DummyClient Start() method
func (NopReadCloser) Close ¶
func (NopReadCloser) Close() error
type NopWriteCloser ¶
func (NopWriteCloser) Close ¶
func (NopWriteCloser) Close() error
type NullWriter ¶
type NullWriter struct{}
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 ¶
func (*SSHOptions) Apply ¶
func (o *SSHOptions) Apply(ops []SSHClientOp)
type TestClient ¶
TestClient is designed for unit tests to accumulate and check what commands were issues, and optionally provide responses to certain commands.
func (*TestClient) OutputWithTimeout ¶
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