creds

package
v0.10.13 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package creds is ~/.atmee/credentials.json: the saved Avatar API key, or the session of a user who signed in with the browser. It holds one or the other; saving either replaces the file.

Index

Constants

View Source
const (
	DefaultHomeEnv = "ATMEE_HOME"
	DefaultKeyEnv  = "ATMEE_API_KEY"
)

The environment variables of the default store: the folder that replaces ~/.atmee, and an API key.

Variables

This section is empty.

Functions

func WriteSecretFile

func WriteSecretFile(path string, b []byte) error

WriteSecretFile writes b to path whole: a fresh file at mode 600 renamed into place, so a secret is never readable by others (even over an older, wider file) and a reader never sees half of it.

Types

type Session

type Session struct {
	BaseURL       string `json:"base_url"`
	TokenEndpoint string `json:"token_endpoint"`
	ClientID      string `json:"client_id"`
	// Resource is the protected resource the tokens are bound to (RFC 8707);
	// a refresh names it again.
	Resource    string `json:"resource,omitempty"`
	AccessToken string `json:"access_token"`
	// RefreshToken is empty when the server issued none: the sign-in then
	// lasts as long as its access token.
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at"`
	Email        string    `json:"email,omitempty"`
	// AccountID is sent as X-Account-Id: which account a user of several
	// acts for. Empty for a user of one account.
	AccountID string `json:"account_id,omitempty"`
}

Session is a browser sign-in: the user's OAuth tokens and what refreshing them needs. BaseURL is the Avatar API it was made for; the tokens come from that deployment's sign-in and are useless anywhere else.

type Store

type Store struct {
	Dir    string
	KeyEnv string
}

Store is one credentials file. KeyEnv names the variable whose key wins over the file (DefaultKeyEnv when empty).

func Default

func Default() Store

Default is ~/.atmee (ATMEE_HOME overrides).

func In

func In(folder, homeEnv, keyEnv string) Store

In is the store in the folder of that name under the home directory (homeEnv overrides), with its API key read from keyEnv. Each variant passes its own variables, so one never reads another's saved key.

func (Store) APIKey

func (s Store) APIKey() string

APIKey is the key in KeyEnv, else the saved key ("" when none).

func (Store) Remove

func (s Store) Remove() error

Remove deletes the saved key or sign-in (and the file).

func (Store) SaveAPIKey

func (s Store) SaveAPIKey(key string) error

SaveAPIKey writes the key, dropping a saved sign-in.

func (Store) SaveSession

func (s Store) SaveSession(sess Session) error

SaveSession writes the sign-in, dropping a saved key.

func (Store) Session

func (s Store) Session() *Session

Session is the saved browser sign-in, nil when none.

Jump to

Keyboard shortcuts

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