config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config provides configuration management for harvest.

Index

Constants

View Source
const AppName = "harvest"

AppName is the application name used for config directories.

View Source
const DefaultClientName = "default"

DefaultClientName is the name of the default OAuth client.

View Source
const EnvAccount = "HARVEST_ACCOUNT"

EnvAccount is the environment variable for specifying the account.

Variables

This section is empty.

Functions

func ClientCredentialsExist

func ClientCredentialsExist(client string) bool

ClientCredentialsExist returns true if credentials exist for the client.

func ClientCredentialsPath

func ClientCredentialsPath(client string) string

ClientCredentialsPath returns the path for a client's credentials file.

func ClientsDir

func ClientsDir() string

ClientsDir returns the path to the clients subdirectory.

func ConfigExists

func ConfigExists() bool

ConfigExists returns true if the config file exists.

func ConfigPath

func ConfigPath() string

ConfigPath returns the path to the main config file.

func DeleteAccountAlias

func DeleteAccountAlias(alias string) error

DeleteAccountAlias removes an account alias.

func DeleteClientCredentials

func DeleteClientCredentials(client string) error

DeleteClientCredentials removes credentials for the specified client.

func Dir

func Dir() (string, error)

Dir returns the XDG config directory for harvest. Falls back to ~/.config/harvest/ if XDG_CONFIG_HOME is not set.

func DomainFromEmail

func DomainFromEmail(email string) string

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

func ExpandPath(path string) string

ExpandPath expands ~ to the user's home directory.

func KeyringDir

func KeyringDir() string

KeyringDir returns the path to the keyring fallback directory.

func ListAccountAliases

func ListAccountAliases() map[string]string

ListAccountAliases returns all configured aliases.

func ListClients

func ListClients() ([]string, error)

ListClients returns a list of configured client names.

func NormalizeClientNameOrDefault

func NormalizeClientNameOrDefault(raw string) (string, error)

NormalizeClientNameOrDefault normalizes a client name, defaulting to "default" if empty.

func NormalizeDomain

func NormalizeDomain(domain string) string

NormalizeDomain normalizes a domain for comparison.

func ResolveAccount

func ResolveAccount(flagAccount string) (string, error)

ResolveAccount determines which account to use. Priority: flag > env > config default.

func ResolveClientForAccount

func ResolveClientForAccount(email, override string) (string, error)

ResolveClientForAccount determines which OAuth client to use for an account. Priority: override > account mapping > domain mapping > default.

func SetAccountAlias

func SetAccountAlias(alias, email string) error

SetAccountAlias creates or updates an account alias.

func SetAccountClient

func SetAccountClient(email, client string) error

SetAccountClient maps an account to a specific OAuth client.

func SetClientDomain

func SetClientDomain(domain, client string) error

SetClientDomain maps a domain to a specific OAuth client.

func SetDefaultAccount

func SetDefaultAccount(account string) error

SetDefaultAccount sets the default account in config.

func StateDir

func StateDir() string

StateDir returns the path to the state subdirectory.

func WriteClientCredentials

func WriteClientCredentials(client string, creds *ClientCredentials) error

WriteClientCredentials writes credentials for the specified client.

func WriteConfig

func WriteConfig(cfg *File) error

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

func ReadConfig() (*File, error)

ReadConfig reads and parses the config file. Returns an empty config if the file doesn't exist.

Jump to

Keyboard shortcuts

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