fix(archied): resolve stored provider credentials at boot
This commit is contained in:
1 parent
093e677ad8
commit
419334dfa2
2 files changed
+27
No files matched your search
@@ -29,6 +29,13 @@ func (b *boot) runtimeConfig(ctx context.Context, base config.Config) (config.Co
|
||||
b.reportApplied(ctx, versions, wrapped)
|
||||
return config.Config{}, wrapped
|
||||
}
|
||||
// The State Store persists source references, while openStores resolved
|
||||
// only the file snapshot. Layering provider-settings restores the source
|
||||
// references, so resolve the effective map before any runtime consumes it.
|
||||
if err := resolveProviderSecrets(&cfg, b.secrets, b.log); err != nil {
|
||||
b.reportApplied(ctx, versions, err)
|
||||
return config.Config{}, err
|
||||
}
|
||||
b.reportApplied(ctx, versions, nil)
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// controlPlaneStub answers Query from a fixed resource map. queryErr, when
|
||||
@@ -111,6 +113,24 @@ func newReloadBoot(t *testing.T, stub *controlPlaneStub) *boot {
|
||||
return b
|
||||
}
|
||||
|
||||
func TestRuntimeConfigResolvesStoredProviderReference(t *testing.T) {
|
||||
t.Setenv("ARCHIE_TEST_STORED_PROVIDER", "provider-secret")
|
||||
resources := databaseOwnedResources()
|
||||
resources[controlplane.ProviderSettingsKind] = map[string]any{"main": map[string]any{
|
||||
"class": "openai", "api_key_ref": map[string]any{"engine": "env", "key": "ARCHIE_TEST_STORED_PROVIDER"},
|
||||
}}
|
||||
b := newReloadBoot(t, &controlPlaneStub{values: resources})
|
||||
b.secrets = secret.NewRegistry()
|
||||
if err := b.loadRuntimeConfig(t.Context()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := b.cfgHolder.Get().Providers["main"]
|
||||
if got.APIKey != (secret.SecretRef{}) || got.APIKeyEnv != providerSecretEnvName("root", "main") {
|
||||
t.Fatalf("effective provider credential = %+v, want a resolved process-local env name", got)
|
||||
}
|
||||
t.Cleanup(func() { _ = os.Unsetenv(got.APIKeyEnv) })
|
||||
}
|
||||
|
||||
// TestReloadConfigKeepsDatabaseOwnedSettings is archie-core-ju85. The SIGHUP
|
||||
// callback re-resolves the file document alone; without re-applying the
|
||||
// control plane over it, every database-owned setting reverts to its file
|
||||
|
||||
Reference in new issue
Block a user