Documentation
¶
Overview ¶
Package config provides configuration management for harvest.
Index ¶
- Constants
- func ClientCredentialsExist(client string) bool
- func ClientCredentialsPath(client string) string
- func ClientsDir() string
- func ConfigExists() bool
- func ConfigPath() string
- func DeleteAccountAlias(alias string) error
- func DeleteClientCredentials(client string) error
- func Dir() (string, error)
- func DomainFromEmail(email string) string
- func EnsureClientsDir() error
- func EnsureDir() error
- func EnsureKeyringDir() error
- func EnsureStateDir() error
- func ExpandPath(path string) string
- func KeyringDir() string
- func ListAccountAliases() map[string]string
- func ListClients() ([]string, error)
- func NormalizeClientNameOrDefault(raw string) (string, error)
- func NormalizeDomain(domain string) string
- func ResolveAccount(flagAccount string) (string, error)
- func ResolveClientForAccount(email, override string) (string, error)
- func SetAccountAlias(alias, email string) error
- func SetAccountClient(email, client string) error
- func SetClientDomain(domain, client string) error
- func SetDefaultAccount(account string) error
- func StateDir() string
- func WriteClientCredentials(client string, creds *ClientCredentials) error
- func WriteConfig(cfg *File) error
- type ClientCredentials
- type File
Constants ¶
const AppName = "harvest"
AppName is the application name used for config directories.
const DefaultClientName = "default"
DefaultClientName is the name of the default OAuth client.
const EnvAccount = "HARVEST_ACCOUNT"
EnvAccount is the environment variable for specifying the account.
Variables ¶
This section is empty.
Functions ¶
func ClientCredentialsExist ¶
ClientCredentialsExist returns true if credentials exist for the client.
func ClientCredentialsPath ¶
ClientCredentialsPath returns the path for a client's credentials file.
func DeleteAccountAlias ¶
DeleteAccountAlias removes an account alias.
func DeleteClientCredentials ¶
DeleteClientCredentials removes credentials for the specified client.
func Dir ¶
Dir returns the XDG config directory for harvest. Falls back to ~/.config/harvest/ if XDG_CONFIG_HOME is not set.
func DomainFromEmail ¶
DomainFromEmail extracts the domain from an email address.
func EnsureClientsDir ¶
func EnsureClientsDir() error
EnsureClientsDir creates the clients directory with 0700 permissions.
func EnsureDir ¶
func EnsureDir() error
EnsureDir creates the config directory with 0700 permissions if it doesn't exist.
func EnsureKeyringDir ¶
func EnsureKeyringDir() error
EnsureKeyringDir creates the keyring directory with 0700 permissions.
func EnsureStateDir ¶
func EnsureStateDir() error
EnsureStateDir creates the state directory with 0700 permissions.
func ExpandPath ¶
ExpandPath expands ~ to the user's home directory.
func KeyringDir ¶
func KeyringDir() string
KeyringDir returns the path to the keyring fallback directory.
func ListAccountAliases ¶
ListAccountAliases returns all configured aliases.
func ListClients ¶
ListClients returns a list of configured client names.
func NormalizeClientNameOrDefault ¶
NormalizeClientNameOrDefault normalizes a client name, defaulting to "default" if empty.
func NormalizeDomain ¶
NormalizeDomain normalizes a domain for comparison.
func ResolveAccount ¶
ResolveAccount determines which account to use. Priority: flag > env > config default.
func ResolveClientForAccount ¶
ResolveClientForAccount determines which OAuth client to use for an account. Priority: override > account mapping > domain mapping > default.
func SetAccountAlias ¶
SetAccountAlias creates or updates an account alias.
func SetAccountClient ¶
SetAccountClient maps an account to a specific OAuth client.
func SetClientDomain ¶
SetClientDomain maps a domain to a specific OAuth client.
func SetDefaultAccount ¶
SetDefaultAccount sets the default account in config.
func WriteClientCredentials ¶
func WriteClientCredentials(client string, creds *ClientCredentials) error
WriteClientCredentials writes credentials for the specified client.
func WriteConfig ¶
WriteConfig writes the config to disk atomically.
Types ¶
type ClientCredentials ¶
type ClientCredentials struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
RedirectURI string `json:"redirect_uri,omitempty"`
}
ClientCredentials holds OAuth client credentials.
func ReadClientCredentials ¶
func ReadClientCredentials(client string) (*ClientCredentials, error)
ReadClientCredentials reads credentials for the specified client.
type File ¶
type File struct {
DefaultAccount string `json:"default_account,omitempty"`
AccountAliases map[string]string `json:"account_aliases,omitempty"`
AccountClients map[string]string `json:"account_clients,omitempty"`
ClientDomains map[string]string `json:"client_domains,omitempty"`
DefaultTimezone string `json:"default_timezone,omitempty"`
WeekStart string `json:"week_start,omitempty"`
Color string `json:"color,omitempty"`
KeyringBackend string `json:"keyring_backend,omitempty"`
ContactEmail string `json:"contact_email,omitempty"`
}
File represents the main configuration file structure.
func ReadConfig ¶
ReadConfig reads and parses the config file. Returns an empty config if the file doesn't exist.