creds

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 11 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 creds resolves the API key an agent needs to talk to a model API.

A key is the one piece of state Flockdeck holds that is worth stealing, so this package is built around keeping it in as few places as possible. A key is looked for in the variables the user already keeps it in, then in Flockdeck's own store, and last in FLOCKDECK_API_KEY; whatever is found reaches exactly one place, the environment of the `flockdeck chat` process for the pane that needs it. Nothing else in the application is ever handed the value. The interface, the CLI and the snapshot code are given a Status instead, which says that there is a key and where it came from and never what it is.

Keeping to that is the reason Key hides its value behind a method rather than exposing a field: a struct with a secret in an exported field ends up in a log line, a JSON snapshot or a wrapped error eventually, and no amount of care at the call sites prevents it. Here there is nothing to leak — fmt prints the redacted form, encoding/json sees no value to write, and the only way to the secret is to ask for it by name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(agentID string) (bool, error)

Clear removes an agent's key and reports whether there was one to remove.

func Env

func Env(spec agent.Spec) []string

Env returns the environment entries that carry the key to the one process that needs it, ready to append to that process's environment.

A key already in the environment needs no entry: the pane inherits it, and writing it out again would only put a second copy of the value somewhere. A stored key is exported under the first name the Spec lists, which is the vendor's own conventional variable, so `flockdeck chat` finds it by resolving the same Spec at the other end rather than by learning a second convention.

A Spec with no names of its own has nowhere to put a stored key, and gets nothing rather than an invented variable name; its chat reads the store itself. Nor is a stored key put under the vendor's variable for a Spec talking to somebody else, where it would be read as the key for the vendor.

func Has

func Has(agentID string) bool

Has reports whether a key is stored for an agent id, without reading it.

func Names

func Names() ([]string, error)

Names lists the agent ids that have a stored key, sorted. It is what lets the interface show a key it has no Spec for — an agent removed from agents.json leaves its key behind, and a key nobody can see is a key nobody can clear.

func Set

func Set(agentID, key string) error

Set stores a key for an agent id, replacing whatever was there.

A store that cannot be parsed is refused rather than replaced: rewriting it would throw away every other key in it, and a hand-edited file with a trailing comma is a much better problem to have than a silently emptied one.

Types

type Key

type Key struct {

	// Source says where it came from, and is empty when there is no key.
	Source Source
	// Env names the environment variable it was read from, for SourceEnv. It
	// is the variable's name, never its value.
	Env string
	// contains filtered or unexported fields
}

Key is a resolved API key.

The value is unexported on purpose; see the package comment. Secret is the only way to it, and the two formatting methods make sure that a Key printed by accident says how it was found rather than what it is.

func Resolve

func Resolve(spec agent.Spec) Key

Resolve finds the key for a Spec in the one order everything goes by (agent.KeyNames): the Spec's own variables from the environment, less its vendor's where it talks to somebody else, and the vendor's usual one where it talks to the vendor; then Flockdeck's own store under the Spec's id; then FLOCKDECK_API_KEY; then nothing.

The environment comes first because a key already exported there is the user's own arrangement — a secrets manager, a shell profile, a CI runner — and Flockdeck quietly preferring its own stale copy of it is a debugging session nobody enjoys. FLOCKDECK_API_KEY is the exception, being every agent's: a key stored for this one is the more particular answer.

It is the chat client's own order, so what the keys dialog and `flockdeck keys` say is in use is what a pane sends.

func (Key) GoString

func (k Key) GoString() string

GoString covers the one verb String does not: %#v prints a struct field by field, unexported fields included, which would otherwise put the secret in the debug output of anything holding a Key.

func (Key) Secret

func (k Key) Secret() string

Secret returns the key itself. Every call is a place the value can escape to, so there should be very few of them.

func (Key) Set

func (k Key) Set() bool

Set reports whether a key was found at all, which is what availability and the interface are actually asking.

func (Key) String

func (k Key) String() string

String is what a Key looks like anywhere it is printed. It is deliberately the same thing Status shows.

type Source

type Source string

Source says where a key was found, which is the only thing about a key that is safe to show.

const (
	// SourceNone means no key was found.
	SourceNone Source = ""
	// SourceEnv means the key was already in the environment Flockdeck was
	// started from, under one of the Spec's own KeyEnv names.
	SourceEnv Source = "env"
	// SourceStore means the key came from Flockdeck's own keys.json.
	SourceStore Source = "store"
)

type Status

type Status struct {
	// Agent is the Spec id the key belongs to, which is also the name
	// `flockdeck keys set` takes and the key in keys.json.
	Agent string `json:"agent"`
	// Name is what the agent is called, for an interface that has the Spec to
	// hand.
	Name string `json:"name,omitempty"`
	Set  bool   `json:"set"`
	// Source and Env are where it was found. Env is a variable's name.
	Source Source `json:"source,omitempty"`
	Env    string `json:"env,omitempty"`
	// Stored says Flockdeck holds a key for this agent, whether or not it is
	// the one in use. A key stored before a variable was exported is shadowed
	// by it, and without this the keys dialog offered no way to clear it.
	Stored bool `json:"stored,omitempty"`
	// Vars lists the environment variables this agent's key may arrive in, so
	// somebody without one can be told where to put it instead of being sent
	// to the documentation.
	Vars []string `json:"vars,omitempty"`
	// NotNeeded is set for an agent that talks to a model on this machine,
	// which wants no key: "not set" would say something was missing.
	NotNeeded bool `json:"notNeeded,omitempty"`
}

Status is everything about a key that may be shown, sent to the front end or written to a file: that there is one, and where it came from.

func StatusAll

func StatusAll(specs []agent.Spec) []Status

StatusAll reports on every Spec that could want a key, in the order given. A Spec that is not an API runner is skipped: a CLI keeps its own credentials and Flockdeck has no business offering to hold them.

func StatusOf

func StatusOf(spec agent.Spec) Status

StatusOf reports on one Spec's key without reading it back.

func (Status) Describe

func (s Status) Describe() string

Describe is the one-line form used by `flockdeck keys list` and by the notice the interface shows. It never contains a key.

Jump to

Keyboard shortcuts

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