config

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config manages cflio's on-disk configuration (registered Confluence site profiles and their API tokens) and resolves which credentials an invocation should use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the directory cflio's config file lives in, honoring XDG_CONFIG_HOME.

func Path

func Path() (string, error)

Path returns the full path to the config file.

func ProfileNames

func ProfileNames(f *File) string

ProfileNames returns the registered profile names, sorted and comma-joined, for use in error messages. Returns "(none)" if none are registered.

func SortedProfileNames

func SortedProfileNames(f *File) []string

SortedProfileNames returns the registered profile names in a stable order. Every listing and lookup that walks the profiles goes through it, so error messages, `profile list` and the host-matching scan can never disagree about ordering the way raw map iteration would.

Types

type Credentials

type Credentials struct {
	Profile string
	SiteURL string
	Email   string
	Token   string
}

Credentials is the resolved outcome of Resolve: everything a single invocation needs to authenticate, plus the name of the profile it came from (needed for error messages and status output).

func Resolve

func Resolve(f *File, flagProfile, urlHost string, getenv func(string) string) (Credentials, error)

Resolve implements cflio's credential precedence for a single invocation:

  1. --profile flag (flagProfile): uses that profile. Errors if the profile doesn't exist, or if urlHost is set and doesn't match the profile's host — talking to the wrong site would yield an indistinguishable "page not found".
  2. urlHost auto-selection: the profile whose host matches urlHost. Errors if no profile is registered for that host; there is deliberately no fallback to the default profile, for the same reason as above.
  3. CFLIO_PROFILE, which stands in for the default profile. It does not override URL-host auto-selection, and it is not checked for host conflicts — only an explicit --profile is.
  4. The default profile.

CFLIO_TOKEN, if set, then replaces the resolved profile's token; the site and email still come from the profile, so a profile must resolve either way. Shared-namespace variables such as ATLASSIAN_API_TOKEN are deliberately never read.

type File

type File struct {
	DefaultProfile string             `json:"default_profile"`
	Profiles       map[string]Profile `json:"profiles"`
}

File is the on-disk representation of ~/.config/cflio/config.json.

func Load

func Load() (*File, error)

Load reads the config file. A missing file is not an error: it returns an empty File, since that's the normal state before the first `auth login`.

func (*File) Save

func (f *File) Save() error

Save writes the config file, creating its directory if needed. The directory and file permissions are restricted (0700/0600) since the file holds plaintext API tokens.

type Profile

type Profile struct {
	// SiteURL is the Confluence base URL including the /wiki path, e.g.
	// "https://example.atlassian.net/wiki". The host is derived from it
	// rather than stored separately, so there is no second copy to drift.
	SiteURL string `json:"site_url"`
	Email   string `json:"email"`
	Token   string `json:"token"`
}

Profile holds the stored credentials for a single registered site.

func (Profile) Host

func (p Profile) Host() string

Host returns the profile's site host, or "" if SiteURL cannot be parsed. `auth login` validates SiteURL before storing it, so an unparseable value means a hand-edited config; the empty host then simply fails to match any URL, which surfaces as the regular unregistered-host error.

Jump to

Keyboard shortcuts

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