Documentation
¶
Index ¶
- func GetCommandDescription(cmd string) string
- type APIClientAdapter
- type AllowedCommands
- type CommandInfo
- type CommandTemplate
- type Config
- type ExecutionResult
- type Executor
- func (e *Executor) ExecuteContainerCommand(ctx context.Context, host string, containerID int, command string) ExecutionResult
- func (e *Executor) ExecuteHostCommand(ctx context.Context, host, command string) ExecutionResult
- func (e *Executor) ExecuteTemplatedCommand(ctx context.Context, targetType TargetType, host string, templateCmd string, ...) ExecutionResult
- func (e *Executor) ExecuteTemplatedContainerCommand(ctx context.Context, host string, containerID int, templateCmd string, ...) ExecutionResult
- func (e *Executor) ExecuteTemplatedVMCommand(ctx context.Context, vm VM, templateCmd string, params map[string]string) ExecutionResult
- func (e *Executor) ExecuteVMCommand(ctx context.Context, vm VM, command string) ExecutionResult
- func (e *Executor) GetAllowedCommands(targetType TargetType) []string
- func (e *Executor) GetAllowedVMCommands(vm VM) []string
- type MockSSHClient
- type OSFamily
- type Plugin
- func (p *Plugin) Enabled() bool
- func (p *Plugin) ExecuteHostCommand(ctx context.Context, host, command string) ExecutionResult
- func (p *Plugin) GetAllowedHostCommands() []string
- func (p *Plugin) Name() string
- func (p *Plugin) ShowContainerCommandMenu(node string, vmid int, onClose func())
- func (p *Plugin) ShowHostCommandMenu(host string, onClose func())
- func (p *Plugin) ShowVMCommandMenu(vm VM, onClose func())
- type ProxmoxAPIClient
- type SSHClient
- type SSHClientConfig
- type SSHClientImpl
- type TargetType
- type UIApp
- type UIManager
- func (u *UIManager) ShowCommandMenu(targetType TargetType, target string, onClose func())
- func (u *UIManager) ShowErrorModal(title, message string, onClose func())
- func (u *UIManager) ShowResultModal(result ExecutionResult, onClose func())
- func (u *UIManager) ShowVMCommandMenu(vm VM, onClose func())
- type VM
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCommandDescription ¶ added in v1.0.15
GetCommandDescription returns a user-friendly description for a command. If no description is found, returns a generic description based on the command.
Types ¶
type APIClientAdapter ¶
type APIClientAdapter struct {
// contains filtered or unexported fields
}
APIClientAdapter adapts pkg/api.Client to the ProxmoxAPIClient interface
func NewAPIClientAdapter ¶
func NewAPIClientAdapter(client *api.Client) *APIClientAdapter
NewAPIClientAdapter creates a new API client adapter
type AllowedCommands ¶
type AllowedCommands struct {
Host []string `yaml:"host"`
Container []string `yaml:"container"`
VM []string `yaml:"vm"`
VMLinux []string `yaml:"vm_linux,omitempty"`
VMWindows []string `yaml:"vm_windows,omitempty"`
}
AllowedCommands defines whitelisted commands for different target types
type CommandInfo ¶ added in v1.0.15
CommandInfo holds a command and its user-friendly description
type CommandTemplate ¶
CommandTemplate represents a command with parameter placeholders
func ParseTemplate ¶
func ParseTemplate(cmd string) CommandTemplate
ParseTemplate extracts parameter names from a command template e.g., "systemctl status {service}" -> ["service"]
func (*CommandTemplate) FillTemplate ¶
func (t *CommandTemplate) FillTemplate(values map[string]string) (string, error)
FillTemplate replaces placeholders with actual values e.g., "systemctl status {service}" + {"service": "nginx"} -> "systemctl status nginx"
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
Timeout time.Duration `yaml:"timeout"`
MaxOutputSize int `yaml:"max_output_size"`
AllowedCommands AllowedCommands `yaml:"allowed_commands"`
}
Config holds the configuration for the command runner plugin
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration for the command runner plugin
type ExecutionResult ¶
type ExecutionResult struct {
Command string
Output string
Error error
ExitCode int
Duration time.Duration
Truncated bool
}
ExecutionResult represents the result of a command execution
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles command execution on various targets
func NewExecutor ¶
func NewExecutor(config Config, sshClient SSHClient, apiClient ProxmoxAPIClient) *Executor
NewExecutor creates a new command executor
func (*Executor) ExecuteContainerCommand ¶
func (e *Executor) ExecuteContainerCommand(ctx context.Context, host string, containerID int, command string) ExecutionResult
ExecuteContainerCommand executes a command in an LXC container via SSH to the host. It uses 'pct exec' to run the command inside the container.
func (*Executor) ExecuteHostCommand ¶
func (e *Executor) ExecuteHostCommand(ctx context.Context, host, command string) ExecutionResult
ExecuteHostCommand executes a command on a Proxmox host via SSH
func (*Executor) ExecuteTemplatedCommand ¶
func (e *Executor) ExecuteTemplatedCommand(ctx context.Context, targetType TargetType, host string, templateCmd string, params map[string]string) ExecutionResult
ExecuteTemplatedCommand executes a command with parameters filled in
func (*Executor) ExecuteTemplatedContainerCommand ¶
func (e *Executor) ExecuteTemplatedContainerCommand(ctx context.Context, host string, containerID int, templateCmd string, params map[string]string) ExecutionResult
ExecuteTemplatedContainerCommand executes a templated command in an LXC container.
func (*Executor) ExecuteTemplatedVMCommand ¶
func (e *Executor) ExecuteTemplatedVMCommand(ctx context.Context, vm VM, templateCmd string, params map[string]string) ExecutionResult
ExecuteTemplatedVMCommand executes a templated command in a QEMU VM via guest agent.
func (*Executor) ExecuteVMCommand ¶
ExecuteVMCommand executes a command in a QEMU VM via guest agent
func (*Executor) GetAllowedCommands ¶
func (e *Executor) GetAllowedCommands(targetType TargetType) []string
GetAllowedCommands returns the whitelist for a target type
func (*Executor) GetAllowedVMCommands ¶
GetAllowedVMCommands returns the whitelist for the provided VM context.
type MockSSHClient ¶
type MockSSHClient struct {
ExecuteFunc func(ctx context.Context, host, command string) (string, error)
ExecuteContainerFunc func(ctx context.Context, host string, containerID int, command string) (string, error)
}
MockSSHClient is a mock implementation for testing
func (*MockSSHClient) ExecuteCommand ¶
ExecuteCommand calls the mock function
func (*MockSSHClient) ExecuteContainerCommand ¶
func (m *MockSSHClient) ExecuteContainerCommand(ctx context.Context, host string, containerID int, command string) (string, error)
ExecuteContainerCommand calls the mock container function
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the command runner plugin
func NewPlugin ¶
func NewPlugin(config Config, sshClient SSHClient, apiClient ProxmoxAPIClient, app UIApp) (*Plugin, error)
NewPlugin creates a new command runner plugin
func (*Plugin) ExecuteHostCommand ¶
func (p *Plugin) ExecuteHostCommand(ctx context.Context, host, command string) ExecutionResult
ExecuteHostCommand executes a command on a host and returns the result
func (*Plugin) GetAllowedHostCommands ¶
GetAllowedHostCommands returns the list of allowed host commands
func (*Plugin) ShowContainerCommandMenu ¶
ShowContainerCommandMenu displays the command menu for a container
func (*Plugin) ShowHostCommandMenu ¶
ShowHostCommandMenu displays the command menu for a host
func (*Plugin) ShowVMCommandMenu ¶
ShowVMCommandMenu displays the command menu for a VM
type ProxmoxAPIClient ¶
type ProxmoxAPIClient interface {
ExecuteGuestAgentCommand(ctx context.Context, vm VM, command []string, timeout time.Duration) (stdout, stderr string, exitCode int, err error)
}
ProxmoxAPIClient interface for Proxmox API operations (abstraction for testing)
type SSHClient ¶
type SSHClient interface {
ExecuteCommand(ctx context.Context, host, command string) (output string, err error)
ExecuteContainerCommand(ctx context.Context, host string, containerID int, command string) (output string, err error)
}
SSHClient interface for SSH command execution (abstraction for testing)
type SSHClientConfig ¶
type SSHClientConfig struct {
Username string
Password string
KeyPath string
Timeout time.Duration
Port int
}
SSHClientConfig holds configuration for SSH connections
type SSHClientImpl ¶
type SSHClientImpl struct {
// contains filtered or unexported fields
}
SSHClientImpl implements SSH command execution using Go's crypto/ssh library
func NewSSHClient ¶
func NewSSHClient(config SSHClientConfig) *SSHClientImpl
NewSSHClient creates a new SSH client with the given configuration
func (*SSHClientImpl) ExecuteCommand ¶
ExecuteCommand executes a command on a host via SSH
func (*SSHClientImpl) ExecuteContainerCommand ¶
func (c *SSHClientImpl) ExecuteContainerCommand(ctx context.Context, host string, containerID int, command string) (string, error)
ExecuteContainerCommand executes a command in an LXC container via SSH to the host. It uses 'pct exec' to run the command inside the container.
Parameters:
- ctx: Context for timeout and cancellation
- host: Proxmox node hostname or IP
- containerID: LXC container ID (VMID)
- command: Command to execute inside the container
Returns the command output and any error encountered.
type TargetType ¶
type TargetType string
TargetType represents where the command will be executed
const ( TargetHost TargetType = "host" TargetContainer TargetType = "container" TargetVM TargetType = "vm" )
type UIApp ¶
type UIApp interface {
Pages() *tview.Pages
SetFocus(p tview.Primitive) *tview.Application
QueueUpdateDraw(func()) *tview.Application
}
UIApp interface defines the minimal app methods needed by UIManager
type UIManager ¶
type UIManager struct {
// contains filtered or unexported fields
}
UIManager handles UI interactions for the command runner plugin
func NewUIManager ¶
NewUIManager creates a new UI manager
func (*UIManager) ShowCommandMenu ¶
func (u *UIManager) ShowCommandMenu(targetType TargetType, target string, onClose func())
ShowCommandMenu displays a list of available commands for selection
func (*UIManager) ShowErrorModal ¶
ShowErrorModal displays an error message in a modal
func (*UIManager) ShowResultModal ¶
func (u *UIManager) ShowResultModal(result ExecutionResult, onClose func())
ShowResultModal displays the command execution result in a modal
func (*UIManager) ShowVMCommandMenu ¶
ShowVMCommandMenu displays a list of commands tailored to a VM's OS.
type VM ¶
type VM struct {
ID int
Node string
Type string
Status string
AgentEnabled bool
AgentRunning bool
OSType string
}
VM represents a minimal VM structure needed for guest agent execution
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles command whitelist validation
func NewValidator ¶
NewValidator creates a new command validator
func (*Validator) GetAllowedCommands ¶
func (v *Validator) GetAllowedCommands(targetType TargetType) []string
GetAllowedCommands returns the list of allowed commands for a target type
func (*Validator) GetAllowedVMCommands ¶
GetAllowedVMCommands returns the whitelist for a VM after considering its OS.
func (*Validator) ValidateCommand ¶
func (v *Validator) ValidateCommand(targetType TargetType, command string) error
ValidateCommand checks if a command is allowed for the given target type