store

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package store persists the Hadron access token, preferring the OS keychain and falling back to a 0600 file when no keychain is available (CI containers, headless boxes).

Index

Constants

View Source
const EnvToken = "HADRON_TOKEN"

EnvToken is the environment variable that overrides any stored token (CI and scripting; same role as GH_TOKEN for gh).

Variables

View Source
var ErrNotFound = errors.New("no stored token")

ErrNotFound is returned when no token is stored for a host.

Functions

func ClearExcept added in v0.6.0

func ClearExcept(keep Store, host string) error

ClearExcept removes host's token from every backend EXCEPT keep, so a login that writes to one store doesn't leave a stale duplicate readable in the other (#116). It returns a non-nil error when a stale token could NOT be removed from another backend (so the caller can warn) — a silent failure would preserve exactly the cross-backend stale credential this is meant to eliminate. An unavailable keychain is skipped.

func Purge added in v0.6.0

func Purge(host string) (removed bool, err error)

Purge removes host's token from EVERY backend, so a token persisted in one store during an earlier login can't survive a logout that resolved to the other (#116). A delete failure against an UNAVAILABLE keychain (headless box) is skipped — nothing can be deleted there and the user can't act on it — but a genuine file error, or a delete that fails against an AVAILABLE keychain (the token is still stored), propagates so logout can't falsely report success. Returns whether any backend actually held a token.

Types

type File

type File struct{}

File stores tokens in ~/.config/hadron/auth.json with 0600 perms.

func (File) Delete

func (File) Delete(host string) error

func (File) Get

func (File) Get(host string) (string, error)

func (File) Name

func (File) Name() string

func (File) Set

func (File) Set(host, token string) error

type Keyring

type Keyring struct{}

Keyring stores tokens in the OS keychain (macOS Keychain, libsecret, Windows Credential Manager).

func (Keyring) Delete

func (Keyring) Delete(host string) error

func (Keyring) Get

func (Keyring) Get(host string) (string, error)

func (Keyring) Name

func (Keyring) Name() string

func (Keyring) Set

func (Keyring) Set(host, token string) error

type Store

type Store interface {
	// Name identifies the backend ("keychain" or "file") for
	// `hadron auth status` output.
	Name() string
	Get(host string) (string, error)
	Set(host, token string) error
	Delete(host string) error
}

Store persists tokens keyed by server host.

func Resolve

func Resolve() Store

Resolve picks the keychain backend when one is usable, otherwise the 0600-file fallback.

Jump to

Keyboard shortcuts

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