Files
archie/internal/secret/secret.go
T
sam 2b1045c0ad feat: secrets-engine registry with yaegi extension interface (archie-core-xec)
Adds internal/secret: a pluggable Engine interface (Name/Version/Resolve)
resolved through a Registry, so secrets backends (sops, Bitwarden Secrets
Manager, Vault/OpenBao) aren't hard-coded into the binary. Only the "env"
engine is compiled in; custom engines are Yaegi-interpreted .go plugins
loaded via Registry.LoadDir, mirroring internal/plugin's conventions
(secretextract provides the generated, nil-guarded symbol table for the
Yaegi/Go interface boundary).

config.Forge.TokenEnv is replaced end-to-end with config.Forge.Token
(secret.SecretRef{Engine, Key}) -- finalize() defaulting, forge token
resolution in cmd/archied/main.go, and per-identity validation that now
requires an explicit token instead of silently resolving to "". No
backwards-compat shim.

Provider.APIKeyEnv, NATSConfig.TokenEnv, and TelegramConfig.TokenEnv are
deliberately not migrated here -- they're forwarded by name to
ai-sdk/runtime and subprocess workers rather than resolved centrally,
which needs its own eager-resolve-then-inject design pass
(archie-core-xec.4). The three shipped engine plugins (sops, bws,
vault/openbao) are tracked separately as archie-core-xec.1-3.

Adversarially reviewed by a fresh agent with no implementation context;
fixed the two findings that survived (missing per-identity token
validation, underdocumented nil-wrapper Resolve edge case).
2026-07-26 14:49:32 +10:00

31 lines
951 B
Go

package secret
// SecretRef references a secret stored in a named engine. It replaces
// the previous TokenEnv/APIKeyEnv string fields throughout config.
//
// Format in TOML/YAML:
//
// [forge]
// token = {engine = "env", key = "GITEA_TOKEN"}
//
// [providers.deepseek]
// api_key = {engine = "bws", key = "DEEPSEEK_API_KEY"}
//
// The zero value (empty engine, empty key) resolves to "" with no error,
// for config fields where the secret is optional (e.g. an unconfigured
// channel token).
type SecretRef struct {
Engine string `toml:"engine" yaml:"engine" json:"engine"`
Key string `toml:"key" yaml:"key" json:"key"`
}
// Resolve resolves this reference through reg. Returns "" with no error
// when the reference is empty (engine and key both empty — the zero
// value means "not configured").
func (s SecretRef) Resolve(reg *Registry) (string, error) {
if s.Engine == "" && s.Key == "" {
return "", nil
}
return reg.Resolve(s)
}