Documentation
¶
Overview ¶
Package config provides configuration management for the AhaSend CLI.
This package handles:
- Multi-profile authentication with API keys and account IDs
- Configuration file loading and saving (YAML format)
- Profile switching and management operations
All configuration is stored in ~/.ahasend/config.yaml following standard CLI conventions.
Index ¶
- func EnsureDir() (string, error)
- func ProfileNames() []string
- func Update(stderr io.Writer, change func(*Manager) error) error
- type Config
- type Manager
- func (m *Manager) GetConfig() *Config
- func (m *Manager) GetProfile(name string) (Profile, error)
- func (m *Manager) ListProfiles() []string
- func (m *Manager) Load() error
- func (m *Manager) NewProfileName(name string) (string, error)
- func (m *Manager) ProfileName(name string) (string, error)
- func (m *Manager) ResolveProfile(name string) (string, Profile, error)
- func (m *Manager) Save() error
- func (m *Manager) SetDefaultProfile(name string) error
- func (m *Manager) SetProfile(name string, profile Profile) error
- type Profile
- type ProfileManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureDir ¶ added in v0.3.0
EnsureDir creates the CLI's directory, ~/.ahasend, readable by its owner only, tightens an existing one that other users can read, and returns its path.
func ProfileNames ¶ added in v0.3.0
func ProfileNames() []string
ProfileNames returns the names of the profiles in the configuration file, sorted, or none when there is no file or it cannot be read. It creates nothing and writes nothing, so shell completion can call it.
func Update ¶ added in v0.3.0
Update loads the configuration, calls change with it and saves it when change returns nil, all under the exclusive lock of the configuration directory, so two commands that change the configuration at once never lose each other's changes. When another command holds the lock for more than lockWaitNotice, Update says on stderr that it waits for the lock file. change's error is returned as it is.
Types ¶
type Config ¶
type Config struct {
DefaultProfile string `yaml:"default_profile"`
Profiles map[string]Profile `yaml:"profiles"`
Extra map[string]yaml.Node `yaml:",inline"`
}
Config represents the CLI configuration. Each level keeps the keys the CLI does not know in Extra, so saving the file never drops them; comments are not kept.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles configuration loading and saving
func LoadManager ¶ added in v0.3.0
LoadManager returns a Manager with the configuration file loaded, or the configuration error that stopped it. Commands that change the configuration use Update instead.
func NewManager ¶
NewManager creates a new configuration manager
func (*Manager) GetProfile ¶ added in v0.3.0
GetProfile returns the profile that name refers to, as ProfileName finds it, or the error ProfileName returns.
func (*Manager) ListProfiles ¶
ListProfiles returns all profile names
func (*Manager) Load ¶
Load loads the configuration file. A missing file leaves the defaults. Profile names are kept exactly as written; keys the CLI does not know are kept for Save. A default_profile that names a profile in another case, as v0.2.0, which matched names ignoring case, could save it, becomes the name of that profile, as ProfileName finds it, so every comparison with it is exact, and Save writes it so.
func (*Manager) NewProfileName ¶ added in v0.3.0
NewProfileName returns the name of the profile that name refers to, as ProfileName finds it, or "" when there is none, so a profile of that name can be added. Several profiles that match name ignoring case are ProfileName's configuration error.
func (*Manager) ProfileName ¶ added in v0.3.0
ProfileName returns the name of the profile that name refers to: the profile called name or, when there is none, the one profile whose name matches name ignoring case. v0.2.0 matched profile names ignoring case, so a file it saved with "Prod" was used with --profile prod. Without such a profile, the error is the configuration error "profile '<name>' not found", which lists the profiles that match name ignoring case when there are several.
func (*Manager) ResolveProfile ¶ added in v0.3.0
ResolveProfile returns the name and the profile a command authenticates with: the profile that name refers to, as ProfileName finds it, or the default profile when name is empty. Without any profile, the error is the authentication error that asks to log in; a profile that does not exist, a missing default and a profile whose api_url is not an API URL, whose api_key is empty or whose account_id is not a UUID are configuration errors.
func (*Manager) Save ¶
Save writes the configuration file. The file holds API keys, so it is readable by its owner only, and so is its directory. The new content goes to a temporary file in the same directory that then replaces the file, so a crash never leaves a partly written configuration. When the file is a symlink, the file it points to is replaced, so the symlink stays.
func (*Manager) SetDefaultProfile ¶
SetDefaultProfile sets the default profile. Save writes the change.
type Profile ¶
type Profile struct {
APIKey string `yaml:"api_key"`
APIURL string `yaml:"api_url"`
AccountID string `yaml:"account_id"`
Extra map[string]yaml.Node `yaml:",inline"`
}
Profile represents an AhaSend account profile
type ProfileManager ¶
type ProfileManager struct {
// contains filtered or unexported fields
}
ProfileManager handles profile-specific operations
func (*ProfileManager) ListProfiles ¶
func (pm *ProfileManager) ListProfiles() []string
ListProfiles returns a list of all profile names
func (*ProfileManager) SetDefaultProfile ¶
func (pm *ProfileManager) SetDefaultProfile(name string) error
SetDefaultProfile sets the default profile
func (*ProfileManager) SetProfile ¶
func (pm *ProfileManager) SetProfile(name string, profile Profile) error
SetProfile adds or updates a profile