Documentation
¶
Overview ¶
Package config provides configuration management for the Proxmox TUI application.
This package handles loading configuration from multiple sources with proper precedence ordering:
- Command-line flags (highest priority)
- Environment variables
- Configuration files (YAML format)
- Default values (lowest priority)
The package follows XDG Base Directory Specification for configuration and cache file locations, providing a clean and predictable user experience.
Configuration Sources:
Environment Variables:
- PROXMOX_ADDR: Proxmox server URL
- PROXMOX_USER: Username for authentication
- PROXMOX_PASSWORD: Password for password-based auth
- PROXMOX_TOKEN_ID: API token ID for token-based auth
- PROXMOX_TOKEN_SECRET: API token secret
- PROXMOX_REALM: Authentication realm (default: "pam")
- PROXMOX_INSECURE: Skip TLS verification ("true"/"false")
- PROXMOX_DEBUG: Enable debug logging ("true"/"false")
- PROXMOX_CACHE_DIR: Custom cache directory path
Configuration File Format (YAML):
addr: "https://pve.example.com:8006" user: "root" password: "secret" realm: "pam" insecure: false debug: true cache_dir: "/custom/cache/path"
XDG Directory Support:
The package automatically determines appropriate directories for configuration and cache files based on XDG specifications:
- Config: $XDG_CONFIG_HOME/proxmox-tui or ~/.config/proxmox-tui
- Cache: $XDG_CACHE_HOME/proxmox-tui or ~/.cache/proxmox-tui
Authentication Methods:
The package supports both password and API token authentication:
- Password: Requires user + password + realm
- API Token: Requires user + token_id + token_secret + realm
Example usage:
// Load configuration with automatic source detection
config := NewConfig()
config.ParseFlags()
// Merge with config file if specified
if configPath != "" {
err := config.MergeWithFile(configPath)
if err != nil {
log.Fatal("Failed to load config file:", err)
}
}
// Set defaults and validate
config.SetDefaults()
if err := config.Validate(); err != nil {
log.Fatal("Invalid configuration:", err)
}
Index ¶
- Variables
- func FindDefaultConfigPath() (string, bool)
- func ParseConfigFlags()
- func ValidateKeyBindings(kb KeyBindings) error
- type Config
- func (c *Config) GetAPIToken() string
- func (c *Config) GetAddr() string
- func (c *Config) GetInsecure() bool
- func (c *Config) GetPassword() string
- func (c *Config) GetRealm() string
- func (c *Config) GetTokenID() string
- func (c *Config) GetTokenSecret() string
- func (c *Config) GetUser() string
- func (c *Config) IsUsingTokenAuth() bool
- func (c *Config) MergeWithFile(path string) error
- func (c *Config) ParseFlags()
- func (c *Config) SetDefaults()
- func (c *Config) Validate() error
- type KeyBindings
Constants ¶
This section is empty.
Variables ¶
var DebugEnabled bool
DebugEnabled is a global flag to enable debug logging throughout the application.
This variable is set during configuration parsing and used by various components to determine whether to emit debug-level log messages.
Functions ¶
func FindDefaultConfigPath ¶ added in v0.8.1
FindDefaultConfigPath searches for the default configuration file in the XDG config directory, checking for "config.yml" and "config.yaml".
It follows the XDG Base Directory Specification to locate the configuration directory. If a configuration file is found, its path and `true` are returned. Otherwise, an empty string and `false` are returned.
Returns the path to the found configuration file and a boolean indicating whether it was found.
func ParseConfigFlags ¶
func ParseConfigFlags()
func ValidateKeyBindings ¶ added in v0.8.0
func ValidateKeyBindings(kb KeyBindings) error
ValidateKeyBindings checks if all key specifications are valid.
Types ¶
type Config ¶
type Config struct {
Addr string `yaml:"addr"` // Proxmox server URL (e.g., "https://pve.example.com:8006")
User string `yaml:"user"` // Username for authentication (without realm)
Password string `yaml:"password"` // Password for password-based authentication
TokenID string `yaml:"token_id"` // API token ID for token-based authentication
TokenSecret string `yaml:"token_secret"` // API token secret for token-based authentication
Realm string `yaml:"realm"` // Authentication realm (e.g., "pam", "pve")
ApiPath string `yaml:"api_path"` // API base path (default: "/api2/json")
Insecure bool `yaml:"insecure"` // Skip TLS certificate verification
SSHUser string `yaml:"ssh_user"` // SSH username for shell connections
Debug bool `yaml:"debug"` // Enable debug logging
CacheDir string `yaml:"cache_dir"` // Custom cache directory path
KeyBindings KeyBindings `yaml:"key_bindings"` // Customizable key bindings
}
Config represents the complete application configuration with support for multiple authentication methods and XDG-compliant directory handling.
The configuration supports both password-based and API token authentication for Proxmox VE. All fields can be populated from environment variables, command-line flags, or YAML configuration files.
Authentication Methods:
- Password: Use User + Password + Realm
- API Token: Use User + TokenID + TokenSecret + Realm
Example configuration:
config := &Config{
Addr: "https://pve.example.com:8006",
User: "root",
Password: "secret",
Realm: "pam",
Insecure: false,
Debug: true,
}
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new Config instance populated with values from environment variables.
This function reads all supported environment variables and creates a Config with those values. Environment variables that are not set will result in zero values for the corresponding fields.
Environment variables read:
- PROXMOX_ADDR: Server URL
- PROXMOX_USER: Username
- PROXMOX_PASSWORD: Password for password auth
- PROXMOX_TOKEN_ID: Token ID for token auth
- PROXMOX_TOKEN_SECRET: Token secret for token auth
- PROXMOX_REALM: Authentication realm (default: "pam")
- PROXMOX_API_PATH: API base path (default: "/api2/json")
- PROXMOX_INSECURE: Skip TLS verification ("true"/"false")
- PROXMOX_SSH_USER: SSH username
- PROXMOX_DEBUG: Enable debug logging ("true"/"false")
- PROXMOX_CACHE_DIR: Custom cache directory
The returned Config should typically be further configured with command-line flags and/or configuration files before validation.
Returns a new Config instance with environment variable values.
Example usage:
config := NewConfig()
config.ParseFlags()
config.SetDefaults()
if err := config.Validate(); err != nil {
log.Fatal("Invalid config:", err)
}
func (*Config) GetAPIToken ¶
GetAPIToken returns the full API token string in the format required by Proxmox Format: PVEAPIToken=USER@REALM!TOKENID=SECRET
func (*Config) GetInsecure ¶
func (*Config) GetPassword ¶
func (*Config) GetTokenID ¶
func (*Config) GetTokenSecret ¶
func (*Config) IsUsingTokenAuth ¶
IsUsingTokenAuth returns true if the configuration is set up for API token authentication
func (*Config) MergeWithFile ¶
func (*Config) ParseFlags ¶
func (c *Config) ParseFlags()
ParseFlags adds command-line flag definitions to a Config object
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults sets default values for unspecified configuration options
type KeyBindings ¶ added in v0.8.0
type KeyBindings struct {
SwitchView string `yaml:"switch_view"` // Switch between pages
SwitchViewReverse string `yaml:"switch_view_reverse"`
NodesPage string `yaml:"nodes_page"` // Jump to Nodes page
GuestsPage string `yaml:"guests_page"` // Jump to Guests page
TasksPage string `yaml:"tasks_page"` // Jump to Tasks page
Menu string `yaml:"menu"` // Open context menu
Shell string `yaml:"shell"` // Open shell session
VNC string `yaml:"vnc"` // Open VNC console
Scripts string `yaml:"scripts"` // Install community scripts
Refresh string `yaml:"refresh"` // Manual refresh
AutoRefresh string `yaml:"auto_refresh"` // Toggle auto-refresh
Search string `yaml:"search"` // Activate search
Help string `yaml:"help"` // Toggle help modal
Quit string `yaml:"quit"` // Quit application
}
KeyBindings defines customizable key mappings for common actions. Each field represents a single keyboard key that triggers the action. Only single characters and function keys (e.g. "F1") are supported.
func DefaultKeyBindings ¶ added in v0.8.0
func DefaultKeyBindings() KeyBindings
DefaultKeyBindings returns a KeyBindings struct with the default key mappings.