cmdexec

package
v0.0.0-...-4be731d Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2020 The Platform9 Systems Inc.

Index

Constants

This section is empty.

Variables

View Source
var StdErrSudoPassword string

To fetch the stderr after executing command

Functions

func CheckRemote

func CheckRemote(nc objects.NodeConfig) bool

func ConfidentialInfoRemover

func ConfidentialInfoRemover(cmd string) string

Avoid confidential information from getting logged

func ExitCodeChecker

func ExitCodeChecker(err error) (string, int)

Types

type Executor

type Executor interface {
	Run(name string, args ...string) error
	RunWithStdout(name string, args ...string) (string, error)
	RunCommandWait(command string) string
	RunWithProgressStages(name string, args ...string) (string, error)
}

Executor interface abstracts us from local or remote execution

func GetExecutor

func GetExecutor(proxyURL string, nc objects.NodeConfig) (Executor, error)

func NewRemoteExecutor

func NewRemoteExecutor(host string, port int, username string, privateKey []byte, password, proxyURL string) (Executor, error)

NewRemoteExecutor create an Executor interface to execute commands remotely

type LocalExecutor

type LocalExecutor struct {
	ProxyUrl string
}

LocalExecutor as the name implies executes commands locally

func (LocalExecutor) Run

func (c LocalExecutor) Run(name string, args ...string) error

Run runs a command locally returning just success or failure

func (LocalExecutor) RunCommandWait

func (c LocalExecutor) RunCommandWait(command string) string

func (LocalExecutor) RunWithProgressStages

func (c LocalExecutor) RunWithProgressStages(name string, args ...string) (string, error)

RunWithProgressBar runs a command locally displaying the progress status along with stdout and err

func (LocalExecutor) RunWithStdout

func (c LocalExecutor) RunWithStdout(name string, args ...string) (string, error)

RunWithStdout runs a command locally returning stdout and err

type MockExecutor

type MockExecutor struct {
	MockRun                   func(name string, args ...string) error
	MockRunWithStdout         func(name string, args ...string) (string, error)
	MockRunCommandWait        func(name string) string
	MockRunWithProgressStages func(name string, args ...string) (string, error)
}

func (*MockExecutor) Run

func (m *MockExecutor) Run(name string, args ...string) error

func (*MockExecutor) RunCommandWait

func (m *MockExecutor) RunCommandWait(name string) string

func (*MockExecutor) RunWithProgressStages

func (m *MockExecutor) RunWithProgressStages(name string, args ...string) (string, error)

func (*MockExecutor) RunWithStdout

func (m *MockExecutor) RunWithStdout(name string, args ...string) (string, error)

type RemoteExecutor

type RemoteExecutor struct {
	Client ssh.Client
	// contains filtered or unexported fields
}

RemoteExecutor as the name implies runs commands usign SSH on remote host

func (*RemoteExecutor) Run

func (r *RemoteExecutor) Run(name string, args ...string) error

Run runs a command locally returning just success or failure

func (*RemoteExecutor) RunCommandWait

func (r *RemoteExecutor) RunCommandWait(command string) string

func (*RemoteExecutor) RunWithProgressStages

func (r *RemoteExecutor) RunWithProgressStages(name string, args ...string) (string, error)

RunWithProgressBar runs a command remote host displaying the progress status along with stdout

func (*RemoteExecutor) RunWithStdout

func (r *RemoteExecutor) RunWithStdout(name string, args ...string) (string, error)

RunWithStdout runs a command locally returning stdout and err

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳