Documentation
¶
Overview ¶
Package config holds twoctl's per-environment credentials and base URLs.
Each named environment is a "context" with its own base URL and its own API key. Contexts live in ~/.config/twoctl/config.yaml; API keys live in the OS keychain under service=twoctl, account=ctx:<name>.
One context is "current" at any time. Commands resolve their key + URL in this order:
- --api-key flag (key) and --url / --env flags (URL)
- TWO_API_KEY env var
- current context's keychain entry and base URL
Index ¶
- Variables
- func DeleteContext(name string) error
- func DeleteKey(ctxName string) error
- func HasStoredKey(ctxName string) bool
- func SaveFile(f *File) error
- func SetContext(name, baseURL, apiKey string) error
- func StoreKey(ctxName, apiKey string) error
- func UseContext(name string) error
- type Context
- type File
- type Resolved
Constants ¶
This section is empty.
Variables ¶
var ErrNoAPIKey = errors.New("no API key found - set TWO_API_KEY, pass --api-key, or run `twoctl auth login`")
ErrNoAPIKey is returned when no key can be located for the active context.
var ErrNoContext = errors.New("no context configured - run `twoctl config set-context <name> --url <url>` or pass --env / --url")
ErrNoContext is returned when no context is configured and no fallback flags (--url / --env) were supplied.
Functions ¶
func DeleteContext ¶
DeleteContext removes a context and its keychain entry.
func DeleteKey ¶
DeleteKey removes the keychain entry for the given context. A missing entry is not an error.
func HasStoredKey ¶
HasStoredKey reports whether the keychain currently holds a key for the given context.
func SaveFile ¶
SaveFile atomically writes the config file. The config directory is chmod'd to 0o700 and the file itself to 0o600 so other users on shared hosts can't read context URLs (or any future cached state).
Callers that mutate config (SetContext / UseContext / DeleteContext) wrap the load-modify-write cycle in withLock(); SaveFile itself is the final atomic step (CreateTemp + Rename).
func SetContext ¶
SetContext inserts or replaces a context. If apiKey is non-empty it is stored in the keychain under that context's account. The full read- modify-write cycle holds an exclusive flock on config.yaml.lock so two concurrent twoctl runs don't lose each other's updates.
func UseContext ¶
UseContext switches the current context. The context must already exist. Held under config.yaml.lock for the read-modify-write window.
Types ¶
type Context ¶
Context holds the per-environment settings for one named context.
func ListContexts ¶
ListContexts returns contexts sorted by name. The active context's name is also returned for marking in UI output.
type File ¶
type File struct {
CurrentContext string `yaml:"current-context"`
Contexts map[string]Context `yaml:"contexts"`
}
File is the on-disk shape of ~/.config/twoctl/config.yaml.
type Resolved ¶
type Resolved struct {
APIKey string
BaseURL string
ContextName string
Source string // human-readable provenance, used by `whoami`
}
Resolved captures the materialised configuration for a single invocation.