credential

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 12 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 credential is the one reader every adapter resolves an external credential through, by NAME.

This is the interim source itd-2609061543533170 ruled for `abcd site setup` (its `## Decisions`, 2026-09-25): the credential store proper, with its three homes and its walkthrough, is itd-2609221017023290, which is planned and not built. Until it lands, a credential is read from one machine-scoped file, ~/.abcd/credentials.json, a JSON object mapping a credential name to its value. The successor replaces the source behind Source; no reader changes.

The file is refused, loudly and never treated as absent, unless it is a regular file (not a symlink), owned by the caller, and readable and writable by the owner alone (mode 0600 or tighter): a secret that group or other can read is not kept, and one that somebody else wrote is not the caller's.

The value never leaves Resolve except as its return: no error formats it, nothing logs it, and nothing here writes to the repository. The one write is SetMachine, into this same file, for the setup of the OpenAI-compatible API adapter (itd-2609081951381895). A malformed file is refused without echoing a byte of it.

Index

Constants

View Source
const MaxValueBytes = 4096

MaxValueBytes bounds one credential's value.

View Source
const StoreFileName = "credentials.json"

StoreFileName is the interim store's file under ~/.abcd/.

View Source
const StorePath = "~/.abcd/" + StoreFileName

StorePath is where the interim store lives, displayed with ~ so no developer-identity path reaches output.

Variables

View Source
var ErrNotSet = errors.New("credential not set")

ErrNotSet is a credential that resolves to nothing: no store, no entry, or an empty value. It is the one error a caller may treat as "carry on without it".

Functions

func CheckValue

func CheckValue(v string) error

CheckValue refuses a value SetMachine would refuse, without echoing it, so a caller can refuse before any other work.

func SetMachine

func SetMachine(home, name, value string) (changed bool, err error)

SetMachine writes value under name in the interim store at home (~/.abcd/credentials.json): the one write this package makes, for the one home it reads (itd-2609081951381895's setup; the credential store, itd-2609221017023290, brings the other homes and replaces this backing).

It refuses, before writing anything and without echoing either value: a name that is not plain; a value that is empty, longer than MaxValueBytes, padded with white space or carrying a control, bidirectional or zero-width character; a store Resolve would refuse (a symlink, group- or other- readable, not owned by the caller, malformed), so a write never launders an unsafe file; and a name already holding a different value, because a stored secret is never replaced by a second one unasked. The same value already stored is no change (changed is false). The file is written atomically at mode 0600, and ~/.abcd is created owner-only when it is absent. The read, the change and the write hold the store's lock (fsutil.WithFileLock, beside the store), so concurrent writers never lose each other's entries.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a plain credential name, the shape every source resolves, so a configuration that names a credential is checked when it is read rather than at the first call.

Types

type Source

type Source interface {
	Resolve(name string) (string, error)
}

Source resolves a credential by name.

func Machine

func Machine(home string) Source

Machine is the interim machine-scoped source rooted at home (the caller's home directory). An empty home resolves every name to ErrNotSet.

func UserMachine

func UserMachine() Source

UserMachine is Machine at the caller's home directory.

Jump to

Keyboard shortcuts

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