Documentation
¶
Index ¶
- Constants
- type BaseCommand
- func (b *BaseCommand) CreateErrorResult(ctx *ExecutionContext, err error) *pb.CommandResult
- func (b *BaseCommand) CreateErrorResultWithCode(ctx *ExecutionContext, err error, exitCode int32) *pb.CommandResult
- func (b *BaseCommand) CreateSuccessResult(ctx *ExecutionContext, output string) *pb.CommandResult
- func (b *BaseCommand) Metadata() Definition
- func (b *BaseCommand) WithExamples(examples ...Example) *BaseCommand
- func (b *BaseCommand) WithNotes(notes ...string) *BaseCommand
- func (b *BaseCommand) WithParameters(params ...Param) *BaseCommand
- type CopyMoveResponse
- type Definition
- type DockerComposeCommand
- type DockerComposeDownCommand
- type DockerComposeFindCommand
- type DockerComposePSCommand
- type DockerComposeRequest
- type DockerComposeUpCommand
- type DockerComposeViewCommand
- type Example
- type ExecutableCommand
- type ExecutionContext
- type FileCommandType
- type FileCopyCommand
- type FileGetCommand
- type FileInfo
- type FileInfoCommand
- type FileMoveCommand
- type FileOptions
- type FileRequest
- type GetResponse
- type InfoResponse
- type LoggingDecreaseCommand
- type LoggingIncreaseCommand
- type LoggingLevelCommand
- type Param
- type Registry
- func (r *Registry) Execute(ctx *ExecutionContext, command *pb.Command) (*pb.CommandResult, error)
- func (r *Registry) FormatCommandHelp(commandName string) string
- func (r *Registry) FormatHelp() string
- func (r *Registry) GetAllCommands() map[string]ExecutableCommand
- func (r *Registry) GetCommand(name string) (ExecutableCommand, bool)
- func (r *Registry) GetCommandsByCategory() map[string][]ExecutableCommand
- func (r *Registry) Register(cmd ExecutableCommand)
- type ShellCommand
- type ShellExecutor
- type ShellRequest
- type ShellResponse
- type SystemCommand
- type SystemInfoCommand
- type SystemOSCommand
- type UnifiedFileCommand
Constants ¶
const ( MaxPreviewSize = 1024 * 1024 // 1MB MaxFileSize = 100 * 1024 * 1024 // 100MB )
File operation constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseCommand ¶
type BaseCommand struct {
// contains filtered or unexported fields
}
BaseCommand provides common functionality for all commands
func NewBaseCommand ¶
func NewBaseCommand(name, category, description, usage string) *BaseCommand
NewBaseCommand creates a new base command with metadata
func (*BaseCommand) CreateErrorResult ¶
func (b *BaseCommand) CreateErrorResult(ctx *ExecutionContext, err error) *pb.CommandResult
CreateErrorResult creates a standardized error result
func (*BaseCommand) CreateErrorResultWithCode ¶
func (b *BaseCommand) CreateErrorResultWithCode(ctx *ExecutionContext, err error, exitCode int32) *pb.CommandResult
CreateErrorResultWithCode creates an error result with custom exit code
func (*BaseCommand) CreateSuccessResult ¶
func (b *BaseCommand) CreateSuccessResult(ctx *ExecutionContext, output string) *pb.CommandResult
CreateSuccessResult creates a standardized success result
func (*BaseCommand) Metadata ¶
func (b *BaseCommand) Metadata() Definition
Metadata returns the command's definition
func (*BaseCommand) WithExamples ¶
func (b *BaseCommand) WithExamples(examples ...Example) *BaseCommand
WithExamples adds examples to the command
func (*BaseCommand) WithNotes ¶
func (b *BaseCommand) WithNotes(notes ...string) *BaseCommand
WithNotes adds notes to the command
func (*BaseCommand) WithParameters ¶
func (b *BaseCommand) WithParameters(params ...Param) *BaseCommand
WithParameters adds parameters to the command
type CopyMoveResponse ¶
type CopyMoveResponse struct {
Source string `json:"source"`
Destination string `json:"destination"`
FilesCount int `json:"files_count"`
BytesCopied int64 `json:"bytes_copied"`
Duration string `json:"duration"`
}
CopyMoveResponse represents the response for copy/move commands
type Definition ¶
type Definition struct {
Name string `json:"name"`
Category string `json:"category"`
Description string `json:"description"`
Usage string `json:"usage"`
Examples []Example `json:"examples,omitempty"`
Parameters []Param `json:"parameters,omitempty"`
Notes []string `json:"notes,omitempty"`
}
Definition represents information about a command that can be sent to minions
type DockerComposeCommand ¶
type DockerComposeCommand struct {
*BaseCommand
}
DockerComposeCommand is a unified command that routes to specific docker-compose operations
func NewDockerComposeCommand ¶
func NewDockerComposeCommand() *DockerComposeCommand
NewDockerComposeCommand creates a new unified docker-compose command
func (*DockerComposeCommand) Execute ¶
func (c *DockerComposeCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface (should not be called directly)
type DockerComposeDownCommand ¶
type DockerComposeDownCommand struct {
*BaseCommand
}
DockerComposeDownCommand stops docker-compose services
func NewDockerComposeDownCommand ¶
func NewDockerComposeDownCommand() *DockerComposeDownCommand
NewDockerComposeDownCommand creates a new docker-compose down command
func (*DockerComposeDownCommand) Execute ¶
func (c *DockerComposeDownCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type DockerComposeFindCommand ¶ added in v1.1.3
type DockerComposeFindCommand struct {
*BaseCommand
}
DockerComposeFindCommand finds all directories containing docker-compose.yml files
func NewDockerComposeFindCommand ¶ added in v1.1.3
func NewDockerComposeFindCommand() *DockerComposeFindCommand
NewDockerComposeFindCommand creates a new docker-compose find command
func (*DockerComposeFindCommand) Execute ¶ added in v1.1.3
func (c *DockerComposeFindCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type DockerComposePSCommand ¶
type DockerComposePSCommand struct {
*BaseCommand
}
DockerComposePSCommand lists docker-compose services
func NewDockerComposePSCommand ¶
func NewDockerComposePSCommand() *DockerComposePSCommand
NewDockerComposePSCommand creates a new docker-compose ps command
func (*DockerComposePSCommand) Execute ¶
func (c *DockerComposePSCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type DockerComposeRequest ¶
type DockerComposeRequest struct {
Command string `json:"command"`
Path string `json:"path"`
Service string `json:"service,omitempty"`
Build bool `json:"build,omitempty"`
}
DockerComposeRequest represents the JSON structure for docker-compose commands
type DockerComposeUpCommand ¶
type DockerComposeUpCommand struct {
*BaseCommand
}
DockerComposeUpCommand starts docker-compose services
func NewDockerComposeUpCommand ¶
func NewDockerComposeUpCommand() *DockerComposeUpCommand
NewDockerComposeUpCommand creates a new docker-compose up command
func (*DockerComposeUpCommand) Execute ¶
func (c *DockerComposeUpCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type DockerComposeViewCommand ¶ added in v1.1.3
type DockerComposeViewCommand struct {
*BaseCommand
}
DockerComposeViewCommand displays the content of docker-compose.yml file in the specified path
func NewDockerComposeViewCommand ¶ added in v1.1.3
func NewDockerComposeViewCommand() *DockerComposeViewCommand
NewDockerComposeViewCommand creates a new docker-compose view command
func (*DockerComposeViewCommand) Execute ¶ added in v1.1.3
func (c *DockerComposeViewCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type Example ¶
type Example struct {
Description string `json:"description"`
Command string `json:"command"`
Expected string `json:"expected,omitempty"`
}
Example represents an example of how to use a command
type ExecutableCommand ¶
type ExecutableCommand interface {
Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Metadata() Definition
}
ExecutableCommand represents a simplified command that can execute and provides metadata
type ExecutionContext ¶
type ExecutionContext struct {
Context context.Context
Logger *zap.Logger
AtomicLevel *zap.AtomicLevel
MinionID string
CommandID string
Timestamp int64
}
ExecutionContext provides common context for all command executions
func NewExecutionContext ¶
func NewExecutionContext(ctx context.Context, logger *zap.Logger, atom *zap.AtomicLevel, minionID, commandID string) *ExecutionContext
NewExecutionContext creates a new execution context
type FileCommandType ¶
type FileCommandType string
FileCommandType represents the type of file operation to perform
const ( CmdGet FileCommandType = "get" CmdCopy FileCommandType = "copy" CmdMove FileCommandType = "move" CmdInfo FileCommandType = "info" )
type FileCopyCommand ¶
type FileCopyCommand struct {
*BaseCommand
}
FileCopyCommand copies files or directories
func NewFileCopyCommand ¶
func NewFileCopyCommand() *FileCopyCommand
NewFileCopyCommand creates a new file copy command
func (*FileCopyCommand) Execute ¶
func (c *FileCopyCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type FileGetCommand ¶
type FileGetCommand struct {
*BaseCommand
}
FileGetCommand retrieves file content or information
func NewFileGetCommand ¶
func NewFileGetCommand() *FileGetCommand
NewFileGetCommand creates a new file get command
func (*FileGetCommand) Execute ¶
func (c *FileGetCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type FileInfo ¶
type FileInfo struct {
Path string `json:"path"`
Name string `json:"name"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
ModTime time.Time `json:"mod_time"`
IsDir bool `json:"is_dir"`
Permissions string `json:"permissions"`
Owner string `json:"owner,omitempty"`
Group string `json:"group,omitempty"`
ContentType string `json:"content_type,omitempty"`
Checksum string `json:"checksum,omitempty"`
}
FileInfo represents information about a file or directory
type FileInfoCommand ¶
type FileInfoCommand struct {
*BaseCommand
}
FileInfoCommand gets detailed information about files or directories
func NewFileInfoCommand ¶
func NewFileInfoCommand() *FileInfoCommand
NewFileInfoCommand creates a new file info command
func (*FileInfoCommand) Execute ¶
func (c *FileInfoCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type FileMoveCommand ¶
type FileMoveCommand struct {
*BaseCommand
}
FileMoveCommand moves/renames files or directories
func NewFileMoveCommand ¶
func NewFileMoveCommand() *FileMoveCommand
NewFileMoveCommand creates a new file move command
func (*FileMoveCommand) Execute ¶
func (c *FileMoveCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type FileOptions ¶
type FileOptions struct {
CreateDirs bool `json:"create_dirs,omitempty"` // Create destination directories if they don't exist
Overwrite bool `json:"overwrite,omitempty"` // Overwrite existing files
PreservePerm bool `json:"preserve_perm,omitempty"` // Preserve file permissions
MaxSize int64 `json:"max_size,omitempty"` // Maximum file size to process (bytes)
}
FileOptions contains additional options for file operations
type FileRequest ¶
type FileRequest struct {
Command FileCommandType `json:"command"`
Source string `json:"source"`
Destination string `json:"destination,omitempty"` // Used for copy/move operations
Recursive bool `json:"recursive,omitempty"` // For directory operations
Options FileOptions `json:"options,omitempty"`
}
FileRequest represents a file operation request
type GetResponse ¶
type GetResponse struct {
FileInfo FileInfo `json:"file_info"`
Content []byte `json:"content,omitempty"` // File content (for text files or small files)
ContentB64 string `json:"content_b64,omitempty"` // Base64 encoded content (for binary files)
Truncated bool `json:"truncated,omitempty"` // Whether content was truncated due to size
PreviewOnly bool `json:"preview_only,omitempty"` // Whether only a preview was returned
}
GetResponse represents the response for a get command
type InfoResponse ¶
type InfoResponse struct {
FileInfo FileInfo `json:"file_info"`
Children []FileInfo `json:"children,omitempty"` // For directories
}
InfoResponse represents the response for an info command
type LoggingDecreaseCommand ¶
type LoggingDecreaseCommand struct {
*BaseCommand
}
LoggingDecreaseCommand decreases the logging level
func NewLoggingDecreaseCommand ¶
func NewLoggingDecreaseCommand() *LoggingDecreaseCommand
NewLoggingDecreaseCommand creates a new logging decrease command
func (*LoggingDecreaseCommand) Execute ¶
func (c *LoggingDecreaseCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type LoggingIncreaseCommand ¶
type LoggingIncreaseCommand struct {
*BaseCommand
}
LoggingIncreaseCommand increases the logging level
func NewLoggingIncreaseCommand ¶
func NewLoggingIncreaseCommand() *LoggingIncreaseCommand
NewLoggingIncreaseCommand creates a new logging increase command
func (*LoggingIncreaseCommand) Execute ¶
func (c *LoggingIncreaseCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type LoggingLevelCommand ¶
type LoggingLevelCommand struct {
*BaseCommand
}
LoggingLevelCommand gets the current logging level
func NewLoggingLevelCommand ¶
func NewLoggingLevelCommand() *LoggingLevelCommand
NewLoggingLevelCommand creates a new logging level command
func (*LoggingLevelCommand) Execute ¶
func (c *LoggingLevelCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type Param ¶
type Param struct {
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Description string `json:"description"`
Default string `json:"default,omitempty"`
}
Param represents a command parameter
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry provides a cleaner, self-registering command system
func SetupCommands ¶
SetupCommands creates and registers all commands in the registry
func (*Registry) Execute ¶
func (r *Registry) Execute(ctx *ExecutionContext, command *pb.Command) (*pb.CommandResult, error)
Execute executes a command by name
func (*Registry) FormatCommandHelp ¶
FormatCommandHelp returns detailed help for a specific command
func (*Registry) FormatHelp ¶
FormatHelp returns formatted help for all commands
func (*Registry) GetAllCommands ¶
func (r *Registry) GetAllCommands() map[string]ExecutableCommand
GetAllCommands returns all registered commands
func (*Registry) GetCommand ¶
func (r *Registry) GetCommand(name string) (ExecutableCommand, bool)
GetCommand returns a command by name
func (*Registry) GetCommandsByCategory ¶
func (r *Registry) GetCommandsByCategory() map[string][]ExecutableCommand
GetCommandsByCategory returns commands grouped by category
func (*Registry) Register ¶
func (r *Registry) Register(cmd ExecutableCommand)
Register adds a command to the registry
type ShellCommand ¶
type ShellCommand struct {
*BaseCommand
// contains filtered or unexported fields
}
ShellCommand provides a unified shell command interface
func NewShellCommand ¶
func NewShellCommand(defaultTimeout time.Duration) *ShellCommand
NewShellCommand creates a new unified shell command
func (*ShellCommand) Execute ¶
func (c *ShellCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements Command interface for shell commands
type ShellExecutor ¶
type ShellExecutor struct {
// contains filtered or unexported fields
}
ShellExecutor handles shell command execution
func NewShellExecutor ¶
func NewShellExecutor(defaultTimeout time.Duration) *ShellExecutor
NewShellExecutor creates a new shell executor
func (*ShellExecutor) Execute ¶
func (se *ShellExecutor) Execute(ctx context.Context, request *ShellRequest) *ShellResponse
Execute processes a shell command and returns the response
type ShellRequest ¶
type ShellRequest struct {
Command string `json:"command"`
Shell string `json:"shell,omitempty"` // Optional: specify shell (sh, bash, cmd, powershell)
Timeout int `json:"timeout,omitempty"` // Optional: timeout in seconds
}
ShellRequest represents a shell command request
func ParseShellRequest ¶
func ParseShellRequest(payload string) (*ShellRequest, error)
ParseShellRequest parses a shell command request from various formats
type ShellResponse ¶
type ShellResponse struct {
Command string `json:"command"`
Shell string `json:"shell"`
ExitCode int32 `json:"exit_code"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
Duration string `json:"duration"`
TimedOut bool `json:"timed_out,omitempty"`
Timestamp int64 `json:"timestamp"`
}
ShellResponse represents the response from a shell command
type SystemCommand ¶
type SystemCommand struct {
*BaseCommand
// contains filtered or unexported fields
}
SystemCommand provides backwards compatibility for system commands
func NewSystemCommand ¶
func NewSystemCommand(defaultTimeout time.Duration) *SystemCommand
NewSystemCommand creates a system command (for backwards compatibility)
func (*SystemCommand) Execute ¶
func (c *SystemCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements Command interface for system commands
type SystemInfoCommand ¶
type SystemInfoCommand struct {
*BaseCommand
}
SystemInfoCommand provides system information
func NewSystemInfoCommand ¶
func NewSystemInfoCommand() *SystemInfoCommand
NewSystemInfoCommand creates a new system info command
func (*SystemInfoCommand) Execute ¶
func (c *SystemInfoCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type SystemOSCommand ¶
type SystemOSCommand struct {
*BaseCommand
}
SystemOSCommand provides OS information
func NewSystemOSCommand ¶
func NewSystemOSCommand() *SystemOSCommand
NewSystemOSCommand creates a new system OS command
func (*SystemOSCommand) Execute ¶
func (c *SystemOSCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface
type UnifiedFileCommand ¶
type UnifiedFileCommand struct {
*BaseCommand
}
UnifiedFileCommand provides a unified file command that routes to specific operations
func NewFileCommand ¶
func NewFileCommand() *UnifiedFileCommand
NewFileCommand creates a new unified file command
func (*UnifiedFileCommand) Execute ¶
func (c *UnifiedFileCommand) Execute(ctx *ExecutionContext, payload string) (*pb.CommandResult, error)
Execute implements ExecutableCommand interface and routes to appropriate file operation