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).
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package secretextract
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSymbolsContainsExpectedEngineEntries(t *testing.T) {
|
|
pkgKey := "github.com/samcharles93/archie-core/internal/secret/secret"
|
|
pkg, ok := Symbols[pkgKey]
|
|
if !ok {
|
|
t.Fatalf("Symbols missing key %q", pkgKey)
|
|
}
|
|
|
|
if v, ok := pkg["NewRegistry"]; !ok {
|
|
t.Error("NewRegistry missing from Symbols")
|
|
} else if v.Kind() != reflect.Func {
|
|
t.Errorf("NewRegistry kind = %v, want Func", v.Kind())
|
|
}
|
|
|
|
if v, ok := pkg["Registry"]; !ok {
|
|
t.Error("Registry missing from Symbols")
|
|
} else if v.Kind() != reflect.Pointer {
|
|
t.Errorf("Registry kind = %v, want Ptr", v.Kind())
|
|
}
|
|
|
|
if v, ok := pkg["Engine"]; !ok {
|
|
t.Error("Engine missing from Symbols")
|
|
} else if v.Kind() != reflect.Pointer {
|
|
t.Errorf("Engine kind = %v, want Ptr", v.Kind())
|
|
}
|
|
|
|
if v, ok := pkg["SecretRef"]; !ok {
|
|
t.Error("SecretRef missing from Symbols")
|
|
} else if v.Kind() != reflect.Pointer {
|
|
t.Errorf("SecretRef kind = %v, want Ptr", v.Kind())
|
|
}
|
|
}
|
|
|
|
func TestGeneratedWrapperHasNilGuards(t *testing.T) {
|
|
pkgKey := "github.com/samcharles93/archie-core/internal/secret/secret"
|
|
pkg := Symbols[pkgKey]
|
|
|
|
engineType, ok := pkg["Engine"]
|
|
if !ok {
|
|
t.Fatal("Engine missing from Symbols")
|
|
}
|
|
|
|
kind := engineType.Kind()
|
|
if kind != reflect.Interface && kind != reflect.Pointer {
|
|
t.Errorf("Engine type kind = %v, want Interface or Ptr", kind)
|
|
}
|
|
if kind == reflect.Interface {
|
|
methodCount := engineType.Type().NumMethod()
|
|
if methodCount < 3 {
|
|
t.Errorf("Engine interface has %d methods, expected at least 3 (Name, Version, Resolve)", methodCount)
|
|
}
|
|
}
|
|
}
|