config

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
const DefaultProfile = "default"

DefaultProfile is the profile used when none is selected.

Variables

View Source
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 CacheDir

func CacheDir() string

CacheDir is the user cache dir for audd.

func DataDir

func DataDir() string

DataDir is the user data dir for audd.

func Dir

func Dir() string

Dir is the user config dir for audd.

func FileSafe

func FileSafe(name string) string

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 GetKey

func GetKey(p *Profile, key string) (string, bool)

GetKey returns a profile setting (not "token") and whether it is set.

func MaskToken

func MaskToken(t string) string

MaskToken shows the first and last four characters: "0123…cdef".

func ProfileName

func ProfileName(flag string, c *Config) string

ProfileName picks the active profile: --profile > AUDD_PROFILE > the config's active_profile > "default".

func SetKey

func SetKey(p *Profile, key, value string) error

SetKey validates and stores a profile setting (not "token").

func UnsetKey

func UnsetKey(p *Profile, key string) error

UnsetKey clears a profile setting (not "token").

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 Defaults

func Defaults(path string) *Config

Defaults returns the configuration used when there is no config file at path.

func Load

func Load() (*Config, error)

Load reads Dir()/config.toml. A missing file gives defaults with a "default" profile.

func LoadFrom

func LoadFrom(path string) (*Config, error)

LoadFrom reads the config file at path.

func (*Config) Profile

func (c *Config) Profile(name string) *Profile

Profile returns the named profile, creating it if missing.

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns profile names, sorted.

func (*Config) Save

func (c *Config) Save() error

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

func (p *Profile) RecorderEnabled() bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL