tokens

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tokens manages the local ~/.instant-tokens file that persists provisioned resource tokens between CLI invocations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Token     string    `json:"token"`
	Name      string    `json:"name"`
	Type      string    `json:"type,omitempty"`     // resource_type: postgres|redis|mongodb|queue|storage|webhook|vector
	Env       string    `json:"env,omitempty"`      // environment: development|production|staging|...
	URL       string    `json:"url"`                // connection URL or other primary URL
	Schedule  string    `json:"schedule,omitempty"` // B15-P2-12 — omitempty so phantom `"schedule":""` rows don't bleed into `status --json`
	Source    string    `json:"source"`             // e.g. "provision"
	CreatedAt time.Time `json:"created_at"`
}

Entry represents one saved resource token and metadata.

B15-P1 (7) — Type and Env fields enable anonymous-tier `instant up` idempotency. The anonymous caller can't list resources from the API (no auth), so `up` falls back to this local cache to recognize a previously-provisioned (type, name, env) tuple and skip re-provisioning. Older config files that lack these fields deserialize as empty strings; the up code-path skips them via empty-string checks rather than re-provisioning blind. Tokens written by `instant <type> new` since this release populate Type; Env will only be populated when written by `up`.

type Store

type Store struct {
	Entries []Entry `json:"entries"`
	// contains filtered or unexported fields
}

Store is the in-memory representation of ~/.instant-tokens.

func Load

func Load() (*Store, error)

Load reads the store from disk, creating it if absent.

func (*Store) Add

func (s *Store) Add(e Entry) error

Add appends a new entry and saves.

func (*Store) Find

func (s *Store) Find(token string) *Entry

Find returns the entry for a given token, or nil if not found.

func (*Store) FindByTypeNameEnv

func (s *Store) FindByTypeNameEnv(typ, name, env string) *Entry

FindByTypeNameEnv returns the entry matching (type, name, env) for the local idempotency cache used by anonymous `up`. Match is case-insensitive on type+name. An entry with an empty Type field is never returned (legacy rows from before B15-P1 — we can't safely claim them belong to a given type without a round trip). Returns nil if no entry matches.

func (*Store) Remove

func (s *Store) Remove(token string) bool

Remove drops the entry matching token and saves. Returns true when an entry was actually removed; false when the token was unknown. Callers MUST NOT depend on Remove for security — the source of truth is the API. Used by `instant resource delete` to keep `instant status` honest.

func (*Store) Save

func (s *Store) Save() error

Save writes the store back to disk atomically — temp file + rename — so a crash mid-write can never truncate ~/.instant-tokens and lose every recorded anonymous token. SEC-CLI FINDING-18.

The pattern mirrors cliconfig.Save (already in this repo).

Jump to

Keyboard shortcuts

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