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 environment the user already keeps it in, and only then in Flockdeck's own store; 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 Env ¶
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 KeyEnv names has nowhere to put a stored key, and gets nothing rather than an invented variable name.
func Names ¶
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.
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 ¶
Resolve finds the key for a Spec: each name in API.KeyEnv from the environment, in the order the Spec lists them, then Flockdeck's own store under the Spec's id, 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.
func (Key) GoString ¶
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 ¶
Secret returns the key itself. Every call is a place the value can escape to, so there should be very few of them.
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"`
// 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 ¶
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.