config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const AppDir = "repsol-cli"

AppDir is the application directory below the XDG config home.

Variables

This section is empty.

Functions

func ResolveProfile

func ResolveProfile(flag, env string, cfg Config) (string, error)

ResolveProfile picks a profile name by precedence: flag, environment, configured default, then "default". Invalid names are a usage error.

func WriteAtomic

func WriteAtomic(path string, perm fs.FileMode, data []byte) error

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 Profile

type Profile struct {
	Address *repsolapi.Address `toml:"address,omitempty"`
}

Profile is the non-secret configuration of one profile.

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

func (s Store) DeleteCredentials(profile string) (bool, error)

DeleteCredentials removes one profile under the lock. It reports whether the profile existed.

func (Store) LoadConfig

func (s Store) LoadConfig() (Config, error)

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

func (s Store) TryLockOrder(profile string) (func(), bool, error)

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

func (s Store) UpdateConfig(fn func(*Config) error) error

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.

Jump to

Keyboard shortcuts

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