Documentation
¶
Overview ¶
Package config loads and saves the CLI's configuration: named contexts in config.yaml (shareable) and secrets in credentials.yaml (0600), both under $XDG_CONFIG_HOME/webtor (~/.config/webtor by default). The WEBTOR_* env vars override everything, so CI can run without any files.
Index ¶
- func CredentialSource(name string, fileCreds Credentials) string
- func Dir() string
- func Exists() bool
- func Load() (*Config, Credentials, error)
- func Save(cfg *Config, creds Credentials) error
- func SetCredentials(name string, c ContextCredentials) error
- type BackendName
- type Config
- type Context
- type ContextCredentials
- type Credentials
- type Resolved
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CredentialSource ¶ added in v1.1.0
func CredentialSource(name string, fileCreds Credentials) string
CredentialSource reports where a context's secrets currently live: "keyring", "file", or "" when nothing is stored.
func Load ¶
func Load() (*Config, Credentials, error)
Load reads config.yaml and credentials.yaml. A missing config is an error; missing credentials are not (an empty set is returned).
func Save ¶
func Save(cfg *Config, creds Credentials) error
Save writes both files, creating the directory as needed. credentials.yaml is written 0600 — it holds keys.
func SetCredentials ¶
func SetCredentials(name string, c ContextCredentials) error
SetCredentials stores one context's secrets: in the OS keyring when available (scrubbing any legacy file entry so the plaintext copy does not linger), in credentials.yaml otherwise. Empty credentials delete the entry everywhere.
Types ¶
type BackendName ¶
type BackendName string
BackendName is the config-file spelling of a backend kind.
const ( BackendWebUI BackendName = "webui" BackendRapidAPI BackendName = "rapidapi" BackendDirect BackendName = "direct" )
type Config ¶
type Config struct {
Current string `yaml:"current"`
Contexts map[string]Context `yaml:"contexts"`
}
Config is config.yaml: the contexts and which one is current.
type Context ¶
type Context struct {
Backend BackendName `yaml:"backend"`
// BaseURL overrides the backend's default endpoint. Required for direct.
BaseURL string `yaml:"base_url,omitempty"`
}
Context is one named backend configuration.
type ContextCredentials ¶
type ContextCredentials struct {
// APIKey is the web-ui API key, the RapidAPI key, or direct's
// pass-through api-key, depending on the context's backend.
APIKey string `yaml:"api_key,omitempty" json:"api_key,omitempty"`
// Token is direct's pass-through JWT.
Token string `yaml:"token,omitempty" json:"token,omitempty"`
}
ContextCredentials are the secrets of one context. The json tags fix the keyring entry's wire format; the yaml tags fix credentials.yaml's.
type Credentials ¶
type Credentials map[string]*ContextCredentials
Credentials is credentials.yaml: per-context secrets, kept out of the shareable config file.
type Resolved ¶
type Resolved struct {
Name string
Context Context
Creds ContextCredentials
// FromEnv marks the config-less WEBTOR_BACKEND mode: nothing is stored
// on disk for this configuration.
FromEnv bool
}
Resolved is a fully resolved runtime configuration: the chosen context plus its secrets, after env overrides.