Documentation
¶
Overview ¶
Package config provides CLI-specific configuration management.
This package wraps the stackeye-go-sdk/config package to add CLI-specific functionality such as environment variable overrides and authentication validation helpers. The SDK package handles persistence and context management; this package adds runtime configuration concerns.
Environment variables (override config file values):
STACKEYE_API_KEY - API key for authentication STACKEYE_API_URL - API server URL STACKEYE_CONFIG - Path to config file STACKEYE_CONTEXT - Context name to use
Usage:
cfg, err := config.Load()
if err != nil {
return err
}
// Get API key with env override
apiKey := config.GetAPIKey(cfg)
// Require valid authentication
if err := config.RequireAuth(cfg); err != nil {
return err
}
Index ¶
- Constants
- Variables
- func ConfigDir() string
- func ConfigPath() string
- func EnsureConfigDir() (string, error)
- func GetAPIKey(cfg *Config) string
- func GetAPIURL(cfg *Config) string
- func IsAuthenticated(cfg *Config) bool
- func RequireAuth(cfg *Config) error
- func Save() error
- func ValidateContextName(name string) error
- type ColorMode
- type Config
- type Context
- type ContextInfo
- type Manager
- type OutputFormat
- type Preferences
Constants ¶
const ( // EnvAPIKey overrides the API key from config. EnvAPIKey = "STACKEYE_API_KEY" // EnvAPIURL overrides the API URL from config. EnvAPIURL = "STACKEYE_API_URL" // EnvConfig specifies a custom config file path. EnvConfig = "STACKEYE_CONFIG" // EnvContext overrides the current context. EnvContext = "STACKEYE_CONTEXT" )
Environment variable names for configuration overrides.
const ( // Output formats OutputFormatTable = sdkconfig.OutputFormatTable OutputFormatJSON = sdkconfig.OutputFormatJSON OutputFormatYAML = sdkconfig.OutputFormatYAML OutputFormatWide = sdkconfig.OutputFormatWide // Color modes ColorModeAuto = sdkconfig.ColorModeAuto ColorModeAlways = sdkconfig.ColorModeAlways ColorModeNever = sdkconfig.ColorModeNever // Default values DefaultAPIURL = sdkconfig.DefaultAPIURL )
Re-export SDK constants.
Variables ¶
var ( ErrNoCurrentContext = sdkconfig.ErrNoCurrentContext ErrContextNotFound = sdkconfig.ErrContextNotFound ErrContextExists = sdkconfig.ErrContextExists )
Re-export SDK errors.
var ( // ErrNotAuthenticated is returned when authentication is required but not configured. ErrNotAuthenticated = errors.New("not authenticated: run 'stackeye login' to authenticate") // ErrInvalidAPIKey is returned when the API key format is invalid. ErrInvalidAPIKey = errors.New("invalid API key format") )
CLI-specific errors.
Functions ¶
func ConfigPath ¶
func ConfigPath() string
ConfigPath returns the path to the configuration file. If STACKEYE_CONFIG is set, returns that path; otherwise returns default.
func EnsureConfigDir ¶
EnsureConfigDir creates the configuration directory if it doesn't exist. Returns the path to the config directory.
func GetAPIKey ¶
GetAPIKey returns the effective API key, checking environment first. Returns empty string if no API key is configured.
func GetAPIURL ¶
GetAPIURL returns the effective API URL, checking environment first. Returns DefaultAPIURL if no URL is configured.
func IsAuthenticated ¶
IsAuthenticated returns true if valid authentication is configured. Checks both environment variables and config file.
func RequireAuth ¶
RequireAuth returns an error if no valid authentication is configured. Use this at the start of commands that require authentication.
func ValidateContextName ¶
ValidateContextName checks if a context name is valid.
Types ¶
type Config ¶
Config is the root configuration structure.
type ContextInfo ¶
type ContextInfo = sdkconfig.ContextInfo
ContextInfo provides display information about a context.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides thread-safe access to configuration. Use GetManager() to obtain the singleton instance.
func GetManager ¶
func GetManager() *Manager
GetManager returns the singleton configuration manager.
func (*Manager) Get ¶
Get returns the loaded configuration. Returns nil if Load() hasn't been called.
func (*Manager) Load ¶
Load loads the configuration, applying environment variable overrides. If STACKEYE_CONFIG is set, loads from that path; otherwise uses default location.
type OutputFormat ¶
type OutputFormat = sdkconfig.OutputFormat
OutputFormat specifies the output format for commands.
type Preferences ¶
type Preferences = sdkconfig.Preferences
Preferences holds user preferences for CLI behavior.
func NewPreferences ¶
func NewPreferences() *Preferences
NewPreferences creates new preferences with default values.