Documentation
¶
Overview ¶
Package config handles loading, saving, and resolving configuration values for the melange CLI. Credential resolution follows this order: environment > environment file > explicitly selected config storage > keyring > legacy config fallback.
Index ¶
- Constants
- func ConfigDir() string
- func Save(cfg *Config) error
- func SaveTo(cfg *Config, path string) error
- type Config
- func (c *Config) DeleteHostAPIKey(host string) error
- func (c *Config) ResolveHost(flagValue string) Resolved
- func (c *Config) ResolveToken(host string) (Resolved, error)
- func (c *Config) ResolveTokenWith(host string, lookup func(host string) (string, bool, error)) (Resolved, error)
- func (c *Config) SetHostAPIKey(host, key string) error
- type HostEntry
- type Resolved
Constants ¶
const ( EnvHost = "MELANGE_HOST" EnvAPIKey = "MELANGE_API_KEY" EnvAPIKeyFile = "MELANGE_API_KEY_FILE" DefaultHost = "https://api.zetic.ai" // CredentialStorageConfig marks a host whose token was explicitly stored // in the mode-0600 config file after the user opted into // --insecure-storage. Resolution skips the unavailable keyring only for // this explicit per-host selection. CredentialStorageConfig = "config" )
Env variable names — centralized so callers don't hard-code strings.
Variables ¶
This section is empty.
Functions ¶
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns the platform-appropriate directory for the config file.
- Linux/macOS: ${XDG_CONFIG_HOME:-$HOME/.config}/melange
- Windows: %AppData%\melange
Types ¶
type Config ¶
type Config struct {
Host string `yaml:"host"`
DefaultRepo string `yaml:"default_repo"`
Hosts map[string]HostEntry `yaml:"hosts"`
}
Config is the top-level config file schema.
func Load ¶
Load loads the config from the default config path. A missing file is not an error — it returns an empty Config. A corrupted YAML file returns an error.
func LoadFrom ¶
LoadFrom loads config from the specified path. A missing file returns an empty Config without error.
func (*Config) DeleteHostAPIKey ¶
DeleteHostAPIKey removes the API key for host from the config file and saves it. Removing an absent host is not an error.
func (*Config) ResolveHost ¶
ResolveHost returns the API host following the precedence chain:
flag > env:MELANGE_HOST > config.host > default
func (*Config) ResolveToken ¶
ResolveToken returns the API token for the given host without consulting a keyring. Call ResolveTokenWith for the full CLI credential resolution path. A set-but-unreadable MELANGE_API_KEY_FILE is a hard error.
func (*Config) ResolveTokenWith ¶
func (c *Config) ResolveTokenWith(host string, lookup func(host string) (string, bool, error)) (Resolved, error)
ResolveTokenWith is ResolveToken with an injected keyring lookup (nil = no keyring). The lookup is a plain func so this package does not import internal/keyring; commands pass keyring.Lookup. Precedence:
env:MELANGE_API_KEY > env:MELANGE_API_KEY_FILE > explicitly selected config storage > keyring > legacy config > empty
A keyring lookup failure remains a hard error unless this host explicitly selected config storage. This prevents an unavailable keyring from silently switching credentials.
func (*Config) SetHostAPIKey ¶
SetHostAPIKey stores an API key for host in the config file and saves it.