Documentation
¶
Overview ¶
Package config stores the per-profile configuration and credentials of the CLI in two TOML files under the XDG config home.
config.toml holds non-secret data and is readable by everyone. credentials.toml holds the login token, the account metadata and, when the owner opted in, the password; it is private to the user, written atomically and guarded by a file lock so concurrent agent runs never lose an update.
Index ¶
- Constants
- func ResolveProfile(flag, env string, cfg Config) (string, error)
- func WriteAtomic(path string, perm fs.FileMode, data []byte) error
- type Config
- type Credentials
- type Paths
- type Profile
- type Store
- func (s Store) DeleteCredentials(profile string) (bool, error)
- func (s Store) LoadConfig() (Config, error)
- func (s Store) LoadCredentials(profile string) (Credentials, bool, error)
- func (s Store) TryLockOrder(profile string) (func(), bool, error)
- func (s Store) UpdateConfig(fn func(*Config) error) error
- func (s Store) UpdateCredentials(profile string, fn func(*Credentials) error) error
Constants ¶
const AppDir = "repsol-cli"
AppDir is the application directory below the XDG config home.
Variables ¶
This section is empty.
Functions ¶
func ResolveProfile ¶
ResolveProfile picks a profile name by precedence: flag, environment, configured default, then "default". Invalid names are a usage error.
func WriteAtomic ¶
WriteAtomic writes data to path through a temporary file in the same directory, then renames it into place, so a reader never sees a partial file. The temporary file is created 0600 and chmodded to perm before the rename, so the destination is never visible with wider permissions.
Types ¶
type Config ¶
type Config struct {
DefaultProfile string `toml:"default_profile,omitempty"`
Profiles map[string]Profile `toml:"profiles,omitempty"`
}
Config is the content of config.toml.
type Credentials ¶
type Credentials struct {
LoginToken string `toml:"login_token,omitempty"`
GMID string `toml:"gmid,omitempty"`
Email string `toml:"email,omitempty"`
Password string `toml:"password,omitempty"`
UID string `toml:"uid,omitempty"`
FirstName string `toml:"first_name,omitempty"`
UpdatedAt time.Time `toml:"updated_at,omitempty"`
}
Credentials is the secret content of one profile in credentials.toml.
type Paths ¶
type Paths struct {
// Config is config.toml, world-readable and free of secrets.
Config string
// Credentials is credentials.toml, private to the user.
Credentials string
// Lock serialises updates to both files across processes.
Lock string
}
Paths holds the absolute paths of the files the store reads and writes.
func DefaultPaths ¶
func DefaultPaths() Paths
DefaultPaths returns the XDG paths of the application files. It creates nothing; the store creates the directory on the first write.
type Store ¶
type Store struct {
Paths Paths
}
Store reads and writes the config and credential files at the given paths. Use Store{Paths: DefaultPaths()} for the real files.
func (Store) DeleteCredentials ¶
DeleteCredentials removes one profile under the lock. It reports whether the profile existed.
func (Store) LoadConfig ¶
LoadConfig reads config.toml. A missing file loads as the zero Config.
func (Store) LoadCredentials ¶
func (s Store) LoadCredentials(profile string) (Credentials, bool, error)
LoadCredentials reads the entry of one profile. found is false when the profile is absent, including when credentials.toml does not exist yet.
func (Store) TryLockOrder ¶
TryLockOrder takes the order lock of a profile without waiting. It reports false when another process or goroutine already holds it. The lock is a file of its own next to the store lock, because a re-login during an order takes the store lock and a second lock on the same file would wait for itself.
func (Store) UpdateConfig ¶
UpdateConfig applies fn to the config under the lock and writes the result atomically. A missing file starts from the zero Config.
func (Store) UpdateCredentials ¶
func (s Store) UpdateCredentials(profile string, fn func(*Credentials) error) error
UpdateCredentials applies fn to one profile's credentials under the lock and writes the file atomically. A missing profile starts from the zero value.