state

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package state manages runtime data that changes frequently and must not be managed declaratively: JWT tokens, current project selection, and the active profile pointer. It mirrors the XDG Base Directory Specification by storing data under XDG_STATE_HOME (default: $HOME/.local/state).

Index

Constants

View Source
const (
	KindPassword = "password"
	KindDevice   = "device"
	KindPAT      = "pat"
)

Credential kinds stored on ProfileState.CredentialKind. An empty value is treated as a legacy password login (non-refreshable).

Variables

This section is empty.

Functions

This section is empty.

Types

type ProfileState

type ProfileState struct {
	JWT              string `json:"jwt"`
	RefreshToken     string `json:"refresh_token,omitempty"`
	TokenExpiresAt   int64  `json:"token_expires_at,omitempty"`
	CredentialKind   string `json:"credential_kind,omitempty"`
	CurrentProjectID string `json:"current_project_id,omitempty"`
}

ProfileState holds runtime state for a single Traceway profile.

type State

type State struct {
	CurrentProfile string                  `json:"current_profile"`
	Profiles       map[string]ProfileState `json:"profiles"`
}

State is the on-disk runtime state file.

func Load

func Load() (*State, error)

Load reads the state file from disk. A missing file yields an empty State (not an error) — the caller treats absence of credentials as an auth error only when an actual command needs them.

func (*State) Active

func (s *State) Active(name string) string

Active resolves the effective profile name by precedence:

explicit name > s.CurrentProfile > "default"

It returns the resolved name only. Callers should index into s.Profiles themselves; the profile may not exist in state yet (e.g., before first login).

func (*State) Save

func (s *State) Save() error

Save atomically writes the state to disk. Creates parent dirs (0700) and the file (0600). Atomicity is achieved by writing to a tempfile in the same directory and renaming over the destination.

Jump to

Keyboard shortcuts

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