Documentation
¶
Overview ¶
Package config provides configuration management for the pvetui 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 platform-appropriate standards for configuration and cache file locations, providing a clean and predictable user experience across Windows, macOS, and Linux.
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 (overrides platform defaults)
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" # Optional: overrides platform defaults
Platform Directory Support:
The package automatically determines appropriate directories for configuration and cache files based on platform standards:
- Windows: Config in %APPDATA%/pvetui, Cache in %LOCALAPPDATA%/pvetui
- macOS: Config in $XDG_CONFIG_HOME/pvetui or ~/.config/pvetui, Cache in $XDG_CACHE_HOME/pvetui or ~/.cache/pvetui
- Linux: Config in $XDG_CONFIG_HOME/pvetui or ~/.config/pvetui, Cache in $XDG_CACHE_HOME/pvetui or ~/.cache/pvetui
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)
}
Package config provides file operations for configuration management.
This file contains file-related functions that were previously part of the main config.go file.
Package config provides profile management functionality.
This file contains profile-related types and functions that were previously part of the main config.go file.
Index ¶
- Variables
- func CreateDefaultConfigFile() (string, error)
- func FindDefaultConfigPath() (string, bool)
- func FindSOPSRule(startDir string) bool
- func GetDefaultConfigPath() string
- func IsSOPSEncrypted(path string, data []byte) bool
- func ParseConfigFlags()
- func ValidateKeyBindings(kb KeyBindings) error
- type Config
- func (c *Config) ApplyProfile(profileName string) error
- func (c *Config) GetAPIToken() string
- func (c *Config) GetActiveProfile() string
- func (c *Config) GetAddr() string
- func (c *Config) GetInsecure() bool
- func (c *Config) GetPassword() string
- func (c *Config) GetProfileNames() []string
- func (c *Config) GetRealm() string
- func (c *Config) GetTokenID() string
- func (c *Config) GetTokenSecret() string
- func (c *Config) GetUser() string
- func (c *Config) HasProfiles() bool
- func (c *Config) IsUsingTokenAuth() bool
- func (c *Config) MergeWithFile(path string) error
- func (c *Config) MigrateLegacyToProfiles() bool
- func (c *Config) SetDefaults()
- func (c *Config) Validate() error
- type KeyBindings
- type ProfileConfig
- type ThemeConfig
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 CreateDefaultConfigFile ¶
CreateDefaultConfigFile creates a default configuration file and returns its path.
func FindDefaultConfigPath ¶
FindDefaultConfigPath finds the default configuration file path.
func FindSOPSRule ¶
FindSOPSRule checks if a SOPS rule file exists in the given directory or its parents.
func GetDefaultConfigPath ¶
func GetDefaultConfigPath() string
GetDefaultConfigPath returns the default configuration file path.
func IsSOPSEncrypted ¶
IsSOPSEncrypted checks if a file is SOPS-encrypted.
func ParseConfigFlags ¶
func ParseConfigFlags()
func ValidateKeyBindings ¶
func ValidateKeyBindings(kb KeyBindings) error
ValidateKeyBindings checks if all key specifications are valid.
Types ¶
type Config ¶
type Config struct {
Profiles map[string]ProfileConfig `yaml:"profiles"`
DefaultProfile string `yaml:"default_profile"`
// ActiveProfile holds the currently active profile at runtime.
// It is not persisted to disk and is used to resolve getters when set.
ActiveProfile string `yaml:"-"`
// The following fields are global settings, not per-profile
Debug bool `yaml:"debug"`
CacheDir string `yaml:"cache_dir"`
KeyBindings KeyBindings `yaml:"key_bindings"`
Theme ThemeConfig `yaml:"theme"`
// Deprecated: legacy single-profile fields for migration
Addr string `yaml:"addr"`
User string `yaml:"user"`
Password string `yaml:"password"`
TokenID string `yaml:"token_id"`
TokenSecret string `yaml:"token_secret"`
Realm string `yaml:"realm"`
ApiPath string `yaml:"api_path"`
Insecure bool `yaml:"insecure"`
SSHUser string `yaml:"ssh_user"`
}
Config represents the complete application configuration, including multiple profiles.
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 (overrides platform defaults)
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) ApplyProfile ¶
ApplyProfile applies the settings from a named profile to the main config.
func (*Config) GetAPIToken ¶
GetAPIToken returns the full API token string in the format required by Proxmox Format: PVEAPIToken=USER@REALM!TOKENID=SECRET.
func (*Config) GetActiveProfile ¶
GetActiveProfile returns the name of the currently active profile.
func (*Config) GetInsecure ¶
GetInsecure returns the configured insecure flag.
func (*Config) GetPassword ¶
GetPassword returns the configured password.
func (*Config) GetProfileNames ¶
GetProfileNames returns a list of available profile names.
func (*Config) GetTokenID ¶
GetTokenID returns the configured token ID.
func (*Config) GetTokenSecret ¶
GetTokenSecret returns the configured token secret.
func (*Config) HasProfiles ¶
HasProfiles returns true if the configuration has any profiles defined.
func (*Config) IsUsingTokenAuth ¶
IsUsingTokenAuth returns true if the configuration is set up for API token authentication.
func (*Config) MergeWithFile ¶
func (*Config) MigrateLegacyToProfiles ¶
MigrateLegacyToProfiles migrates legacy configuration fields to the new profile system.
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults sets default values for unspecified configuration options.
type KeyBindings ¶
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
GlobalMenu string `yaml:"global_menu"` // Open global context menu
Shell string `yaml:"shell"` // Open shell session
VNC string `yaml:"vnc"` // Open VNC console
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 ¶
func DefaultKeyBindings() KeyBindings
DefaultKeyBindings returns a KeyBindings struct with the default key mappings.
type ProfileConfig ¶
type ProfileConfig struct {
Addr string `yaml:"addr"`
User string `yaml:"user"`
Password string `yaml:"password"`
TokenID string `yaml:"token_id"`
TokenSecret string `yaml:"token_secret"`
Realm string `yaml:"realm"`
ApiPath string `yaml:"api_path"`
Insecure bool `yaml:"insecure"`
SSHUser string `yaml:"ssh_user"`
}
ProfileConfig holds a single connection profile's settings.
func (*ProfileConfig) Validate ¶
func (p *ProfileConfig) Validate() error
Validate validates a single profile configuration.
type ThemeConfig ¶
type ThemeConfig struct {
// Name specifies the built-in theme to use as a base (e.g., "default", "catppuccin-mocha").
// If empty, defaults to "default".
Name string `yaml:"name"`
// Colors specifies the color overrides for theme elements.
// Users can use any tcell-supported color value (ANSI name, W3C name, or hex code).
Colors map[string]string `yaml:"colors"`
}
ThemeConfig defines theme-related configuration options.