commandexecutor

package
v0.392.0 Latest Latest
Warning

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

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

README

commandexector

CommandExecutors have an important role in this library since they allow us to:

  • Execute commands on remote systems like (jump-)hosts reachable over the SSH.
  • Execute the same command on the local machine, inside a container (no matter if docker, kubernetes, ...)
  • Can be used to short cut the amount of development time since we already know how to do things with redirects in bash or a specific tool...

But it has downsides:

  • It's not real programming, it's abusing golang for scripting automation.
  • It's a security risk. Calling exce (especially with unchecked user input as parameter) leads to security issues.

Avoid exec calls.

To avoid exec calls on the local machine set the env var accordingly:

export ASCIICHGOLANGPUBLIC_AVOID_EXEC=1

For developers

To run all tests use:

bash -c "cd commandexecutor && go test -v ./..."

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLiveOutputOnStdoutEnabled

func IsLiveOutputOnStdoutEnabled(ctx context.Context) bool

func WithLiveOutputOnStdout

func WithLiveOutputOnStdout(ctx context.Context) context.Context

func WithLiveOutputOnStdoutEnabled

func WithLiveOutputOnStdoutEnabled(ctx context.Context, enabled bool) context.Context

func WithLiveOutputOnStdoutIfVerbose

func WithLiveOutputOnStdoutIfVerbose(ctx context.Context) context.Context

Types

type BashService

type BashService struct {
	CommandExecutorBase
}

func Bash

func Bash() (b *BashService)

Can be used to run commands in bash on localhost.

func NewBashService

func NewBashService() (b *BashService)

func (*BashService) GetDeepCopy

func (b *BashService) GetDeepCopy() (deepCopy commandexecutorinterfaces.CommandExecutor)

func (*BashService) GetHostDescription

func (b *BashService) GetHostDescription() (hostDescription string, err error)

func (*BashService) RunCommand

func (b *BashService) RunCommand(ctx context.Context, options *parameteroptions.RunCommandOptions) (commandOutput *commandexecutorgeneric.CommandOutput, err error)

func (*BashService) RunOneLiner

func (b *BashService) RunOneLiner(ctx context.Context, oneLiner string) (output *commandexecutorgeneric.CommandOutput, err error)

func (*BashService) RunOneLinerAndGetStdoutAsLines

func (b *BashService) RunOneLinerAndGetStdoutAsLines(ctx context.Context, oneLiner string) (stdoutLines []string, err error)

func (*BashService) RunOneLinerAndGetStdoutAsString

func (b *BashService) RunOneLinerAndGetStdoutAsString(ctx context.Context, oneLiner string) (stdout string, err error)

type CommandExecutorBase

type CommandExecutorBase struct {
	// contains filtered or unexported fields
}

func NewCommandExecutorBase

func NewCommandExecutorBase() (c *CommandExecutorBase)

func (*CommandExecutorBase) GetParentCommandExecutorForBaseClass

func (c *CommandExecutorBase) GetParentCommandExecutorForBaseClass() (parentCommandExecutorForBaseClass commandexecutorinterfaces.CommandExecutor, err error)

func (*CommandExecutorBase) IsRunningOnLocalhost

func (c *CommandExecutorBase) IsRunningOnLocalhost() (isRunningOnLocalhost bool, err error)

func (*CommandExecutorBase) RunCommandAndGetStdoutAsBytes

func (c *CommandExecutorBase) RunCommandAndGetStdoutAsBytes(ctx context.Context, options *parameteroptions.RunCommandOptions) (stdout []byte, err error)

func (*CommandExecutorBase) RunCommandAndGetStdoutAsFloat64

func (c *CommandExecutorBase) RunCommandAndGetStdoutAsFloat64(ctx context.Context, options *parameteroptions.RunCommandOptions) (stdout float64, err error)

func (*CommandExecutorBase) RunCommandAndGetStdoutAsInt64

func (c *CommandExecutorBase) RunCommandAndGetStdoutAsInt64(ctx context.Context, options *parameteroptions.RunCommandOptions) (stdout int64, err error)

func (*CommandExecutorBase) RunCommandAndGetStdoutAsLines

func (c *CommandExecutorBase) RunCommandAndGetStdoutAsLines(ctx context.Context, options *parameteroptions.RunCommandOptions) (stdoutLines []string, err error)

func (*CommandExecutorBase) RunCommandAndGetStdoutAsString

func (c *CommandExecutorBase) RunCommandAndGetStdoutAsString(ctx context.Context, options *parameteroptions.RunCommandOptions) (stdout string, err error)

func (*CommandExecutorBase) SetParentCommandExecutorForBaseClass

func (c *CommandExecutorBase) SetParentCommandExecutorForBaseClass(parentCommandExecutorForBaseClass commandexecutorinterfaces.CommandExecutor) (err error)

type ContextKeyLiveOutputOnStdout

type ContextKeyLiveOutputOnStdout struct{}

type ExecService

type ExecService struct {
	CommandExecutorBase
}

func Exec

func Exec() (e *ExecService)

func NewExec

func NewExec() (e *ExecService)

func NewExecService

func NewExecService() (e *ExecService)

func (*ExecService) GetDeepCopy

func (e *ExecService) GetDeepCopy() (deepCopy commandexecutorinterfaces.CommandExecutor)

func (*ExecService) GetHostDescription

func (e *ExecService) GetHostDescription() (hostDescription string, err error)

func (*ExecService) RunCommand

func (e *ExecService) RunCommand(ctx context.Context, options *parameteroptions.RunCommandOptions) (commandOutput *commandexecutorgeneric.CommandOutput, err error)

type PowerShellService

type PowerShellService struct {
	CommandExecutorBase
}

func NewPowerShell

func NewPowerShell() (p *PowerShellService)

func NewPowerShellService

func NewPowerShellService() (p *PowerShellService)

func PowerShell

func PowerShell() (p *PowerShellService)

func (*PowerShellService) RunCommand

func (*PowerShellService) RunOneLiner

func (p *PowerShellService) RunOneLiner(ctx context.Context, oneLiner string) (output *commandexecutorgeneric.CommandOutput, err error)

func (*PowerShellService) RunOneLinerAndGetStdoutAsString

func (p *PowerShellService) RunOneLinerAndGetStdoutAsString(ctx context.Context, oneLiner string) (stdout string, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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