command

package
v1.7.3-0...-caeaf44 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxOutputSize is the maximum size of stdout/stderr output (1MB)
	MaxOutputSize = 1 * 1024 * 1024
	// DefaultCommandTimeout is the default timeout for command execution (5 minutes)
	DefaultCommandTimeout = 5 * time.Minute
	// MaxLogOutputLength is the maximum length for log output truncation
	MaxLogOutputLength = 200
)

Variables

View Source
var (
	// ErrCommandNotFound is returned when a command is not found in the allowlist
	ErrCommandNotFound = errors.New("command not found in allowlist")
	// ErrCommandEmpty is returned when a command has no command defined
	ErrCommandEmpty = errors.New("command has no command defined")
	// ErrCommandPathInvalid is returned when a command path is invalid
	ErrCommandPathInvalid = errors.New("command path is invalid")
	// ErrWorkingDirInvalid is returned when a working directory is invalid
	ErrWorkingDirInvalid = errors.New("working directory is invalid")
)

Functions

func Execute

func Execute(req ExecuteRequest, cfg *settings.Settings) error

Execute validates and executes a command asynchronously

func SetServerContext

func SetServerContext(ctx context.Context)

SetServerContext sets the server-level context for command execution. This context will be canceled when the server shuts down, ensuring all running commands are terminated.

func ValidateCommand

func ValidateCommand(commandID string, cfg *settings.Settings) (*settings.SettingsCommandDefinition, error)

ValidateCommand validates that the command exists in the allowlist and has valid paths

Types

type ExecuteRequest

type ExecuteRequest struct {
	CommandID  string `json:"commandID" mapstructure:"commandID"`
	RequestID  string `json:"-"`
	Connection string `json:"-"`
}

ExecuteRequest contains the data for a command execution request

type ExecuteResult

type ExecuteResult struct {
	CommandID string `json:"commandID" mapstructure:"commandID"`
	ExitCode  int    `json:"exitCode" mapstructure:"exitCode"`
	Stdout    string `json:"stdout" mapstructure:"stdout"`
	Stderr    string `json:"stderr" mapstructure:"stderr"`
	Error     string `json:"error,omitempty" mapstructure:"error,omitempty"`
}

ExecuteResult contains the result of a command execution

Jump to

Keyboard shortcuts

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