credentials

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 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 credentials stores API keys for hosted providers in ~/.decsr/credentials.json (directory 0700, file 0600). A key is never logged, printed or included in an error; List only returns masked keys.

Index

Constants

View Source
const (
	// Dirname is the directory under the home directory, shared with the config.
	Dirname = ".decsr"
	// Filename is the credentials file inside the directory.
	Filename = "credentials.json"
	// DisplayPath is how the file is shown to the user.
	DisplayPath = "~/.decsr/credentials.json"
)

Variables

This section is empty.

Functions

func Delete

func Delete(name string) error

func Mask

func Mask(key string) string

Mask shows the first 3 and last 4 characters of a key ("sk-…a1b2"). Keys too short to hide anything are fully masked.

func Set

func Set(name string, c Cred) error

Types

type Cred

type Cred struct {
	APIKey  string    `json:"api_key"`
	BaseURL string    `json:"base_url,omitempty"`
	SavedAt time.Time `json:"saved_at"`
}

Cred is one saved provider. BaseURL is only set for custom providers.

func Get

func Get(name string) (Cred, bool, error)

Get, Set, Delete and List use the default store.

type Entry

type Entry struct {
	Name    string
	BaseURL string
	Masked  string
	SavedAt time.Time
}

Entry is the key-free view of a saved provider.

func List

func List() ([]Entry, error)

type PermError

type PermError struct{ Path string }

PermError reports a credentials file that is readable by others.

func (*PermError) Error

func (e *PermError) Error() string

type Store

type Store struct {
	// Dir is the directory holding credentials.json; "" means ~/.decsr.
	Dir string
}

Store is a credentials file location. The zero value uses the home directory.

func Default

func Default() Store

Default returns the store under the current user's home directory.

func (Store) CheckPerms

func (s Store) CheckPerms() error

CheckPerms returns a *PermError when the file exists with a mode broader than 0600 (always nil on Windows and when the file does not exist).

func (Store) Delete

func (s Store) Delete(name string) error

Delete removes name; deleting an unknown name is not an error.

func (Store) Get

func (s Store) Get(name string) (Cred, bool, error)

Get returns the saved entry for name. A file with loose permissions is refused with a *PermError.

func (Store) List

func (s Store) List() ([]Entry, error)

List returns the saved providers sorted by name, with masked keys only.

func (Store) Path

func (s Store) Path() string

Path is the full path of the credentials file ("" when the home is unknown).

func (Store) Set

func (s Store) Set(name string, c Cred) error

Set saves c under name, stamping SavedAt when it is zero.

Jump to

Keyboard shortcuts

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