cred

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cred manages the per-context credential store (~/.vibexp/credentials.json, 0600). It is deliberately separate from the config store so credentials never mingle with non-secret settings. The on-disk schema already accommodates OAuth token entries (issue #5).

Index

Constants

View Source
const (
	TypeAPIKey = "api_key"
	TypeOAuth  = "oauth"
)

Credential entry types.

View Source
const EnvAPIKey = "VIBEXP_API_KEY"

EnvAPIKey is the environment variable that overrides stored credentials.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns ~/.vibexp/credentials.json.

func Fingerprint

func Fingerprint(key string) string

Fingerprint returns a non-secret display form of a key: the first 4 and last 4 characters (e.g. "vxk_…1234"). Short keys collapse to a fixed mask.

Types

type Entry

type Entry struct {
	Type         string    `json:"type"`
	APIKey       string    `json:"api_key,omitempty"`
	ClientID     string    `json:"client_id,omitempty"`
	AccessToken  string    `json:"access_token,omitempty"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	// Scopes are the scopes the last successful authorization request for
	// ClientID actually carried — normally the ones declared at RFC 7591
	// registration, but empty when the authorization server refused them and
	// the login only succeeded on the no-scope retry (issue #37). Browser login
	// reuses a stored client only when its scopes cover the scopes it needs to
	// request, so an entry recording a refusal deliberately forces a fresh
	// registration next time rather than replaying a request the server is
	// known to reject. Older entries have none and re-register for the same
	// reason.
	Scopes []string `json:"scopes,omitempty"`
}

Entry is one context's stored credential. API-key entries set Type=api_key and APIKey; OAuth entries (issue #5) set Type=oauth and the token fields.

type Resolved

type Resolved struct {
	Bearer string
	Source Source
	// Type is the stored entry type when Source is "stored" ("api_key" or
	// "oauth"); empty for env.
	Type string
}

Resolved is the effective credential for a context.

type Source

type Source string

Source identifies where a resolved bearer token came from.

const (
	SourceNone   Source = ""
	SourceEnv    Source = "env"
	SourceStored Source = "stored"
)

type Store

type Store struct {
	Path string
}

Store reads and writes the credential file at Path.

func DefaultStore

func DefaultStore() (*Store, error)

DefaultStore returns a Store rooted at the default credentials path.

func (*Store) Delete

func (s *Store) Delete(contextName string) (bool, error)

Delete removes a context's entry. Removing an absent entry is a no-op.

func (*Store) Get

func (s *Store) Get(contextName string) (*Entry, error)

Get returns the entry for a context, or nil if none is stored.

func (*Store) Resolve

func (s *Store) Resolve(contextName string, getenv func(string) string) (Resolved, error)

Resolve computes the effective bearer token for a context using precedence env (VIBEXP_API_KEY) > stored. A nil Getenv is treated as empty. When nothing is available, Source is SourceNone and Bearer is empty.

func (*Store) Save

func (s *Store) Save(contextName string, e Entry) error

Save persists (inserting or replacing) the entry for a context.

Jump to

Keyboard shortcuts

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