config

package
v1.0.4 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 slio's on-disk configuration (registered workspace profiles and their 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 slio'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 (e.g. "profile %q not found; registered profiles: %s"). Returns "(none)" if none are registered.

Types

type Credentials

type Credentials struct {
	Token string
	// Host is the profile's stored workspace host. Empty when the token
	// came from SLIO_TOKEN, since no profile was resolved in that case.
	Host string
	// Profile is the resolved profile name. Empty when the token came from
	// SLIO_TOKEN.
	Profile string
	// ViaEnvToken is true when SLIO_TOKEN supplied the token, bypassing
	// profile resolution entirely.
	ViaEnvToken bool
}

Credentials is the resolved outcome of Resolve: the token to use for a single invocation, plus the profile metadata behind it when one was resolved.

func Resolve

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

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

  1. --profile flag (flagProfile): uses that profile's stored token, ignoring SLIO_TOKEN. Errors if the profile doesn't exist, or if urlHost is set and doesn't match the profile's host (calling the wrong workspace would yield an indistinguishable channel_not_found).
  2. SLIO_TOKEN: bypasses profile resolution and the unregistered-host check entirely — the caller takes responsibility for the token.
  3. urlHost auto-selection: the profile whose host matches urlHost. Errors if no profile is registered for that host (no fallback to the default profile, for the same channel_not_found reason as above).
  4. SLIO_PROFILE.
  5. The default profile.

SLACK_TOKEN is deliberately never read here.

type File

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

File is the on-disk representation of ~/.config/slio/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 tokens.

type Profile

type Profile struct {
	Token  string `json:"token"`
	Host   string `json:"host"`
	TeamID string `json:"team_id"`
}

Profile holds the stored credentials for a single registered workspace.

Jump to

Keyboard shortcuts

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