Documentation
¶
Overview ¶
Package config reads and writes ~/.config/audd/config.toml (%APPDATA%\audd\config.toml on Windows) and resolves the API token.
Layout:
active_profile = "default" [profiles.default] format = "json" max_requests = 500
Keys the CLI does not know are kept as they are when the file is saved.
Index ¶
- Constants
- Variables
- func CacheDir() string
- func DataDir() string
- func Dir() string
- func FileSafe(name string) string
- func GetKey(p *Profile, key string) (string, bool)
- func MaskToken(t string) string
- func ProfileName(flag string, c *Config) string
- func SetKey(p *Profile, key, value string) error
- func UnsetKey(p *Profile, key string) error
- type Config
- type Profile
- type TokenSource
Constants ¶
const DefaultProfile = "default"
DefaultProfile is the profile used when none is selected.
Variables ¶
var Keys = []string{"token", "format", "max_requests", "concurrency", "streams.background_recorder"}
Keys are the settings `audd config` accepts. "token" is stored in the secrets store, not in config.toml.
Functions ¶
func FileSafe ¶
FileSafe returns name with every character other than letters, digits, '-' and '_' replaced by '_', for use in file names. A valid profile name is one that FileSafe leaves unchanged.
func ProfileName ¶
ProfileName picks the active profile: --profile > AUDD_PROFILE > the config's active_profile > "default".
Types ¶
type Config ¶
type Config struct {
ActiveProfile string
Profiles map[string]*Profile
Path string
// contains filtered or unexported fields
}
Config is the parsed config file.
func (*Config) ProfileNames ¶
ProfileNames returns profile names, sorted.
func (*Config) Save ¶
Save writes the config atomically with mode 0600, keeping unknown keys. It re-reads the file under a lock that other audd processes also take and writes back only the settings this process changed, so a long-running command (audd login, say) does not undo settings changed meanwhile.
type Profile ¶
type Profile struct {
Name string `toml:"-"`
Format string `toml:"format,omitempty"`
MaxRequests int `toml:"max_requests,omitempty"`
Concurrency int `toml:"concurrency,omitempty"`
BackgroundRecorder *bool `toml:"background_recorder,omitempty"` // streams.background_recorder
OAuthClientID string `toml:"oauth_client_id,omitempty"`
// OAuthIssuer is the authorization server OAuthClientID belongs to.
OAuthIssuer string `toml:"oauth_issuer,omitempty"`
OAuthScopes []string `toml:"oauth_scopes,omitempty"`
Account string `toml:"account,omitempty"` // email, for display only
}
Profile holds per-profile settings. API tokens and OAuth sessions are not here; they live in the secrets store.
func (*Profile) RecorderEnabled ¶
RecorderEnabled reports whether the background stream recorder may start automatically (on unless streams.background_recorder is false).
type TokenSource ¶
type TokenSource string
TokenSource names where the API token came from.
const ( SourceFlag TokenSource = "flag" SourceEnv TokenSource = "env" SourceConfig TokenSource = "config" SourceLogin TokenSource = "login" SourceNone TokenSource = "none" )
func ResolveToken ¶
func ResolveToken(flag string, profile string, sec secrets.Store) (token string, src TokenSource, err error)
ResolveToken applies the precedence --token > AUDD_API_TOKEN > `audd config set token` > the token fetched by `audd login`. With no token it returns "", SourceNone, nil.
func (TokenSource) Describe ¶
func (s TokenSource) Describe() string
Describe returns a human description of the source.