Skip to content

Commit

Permalink
fix: fallback to asm secret provider in cluster (#3242)
Browse files Browse the repository at this point in the history
We need to proeprly define a defaul secret manager, but for now, fall
back to ASM manager if inline is not available. This will unblock DB
provisioning in dev

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jvmakine and github-actions[bot] authored Oct 30, 2024
1 parent fea8ae8 commit d89b592
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"net/http"
"net/url"
goslices "slices"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -59,7 +60,6 @@ import (
frontend "github.com/TBD54566975/ftl/frontend/console"
"github.com/TBD54566975/ftl/internal/configuration"
cf "github.com/TBD54566975/ftl/internal/configuration/manager"
"github.com/TBD54566975/ftl/internal/configuration/providers"
"github.com/TBD54566975/ftl/internal/cors"
ftlhttp "github.com/TBD54566975/ftl/internal/http"
"github.com/TBD54566975/ftl/internal/log"
Expand Down Expand Up @@ -1047,8 +1047,18 @@ func (s *Service) CreateDeployment(ctx context.Context, req *connect.Request[ftl
for _, d := range module.Decls {
if db, ok := d.(*schema.Database); ok && db.Runtime != nil {
key := dsnSecretKey(module.Name, db.Name)

// TODO: Use a cluster specific default provider
if err := sm.Set(ctx, providers.InlineProviderKey, configuration.NewRef(module.Name, key), db.Runtime.DSN); err != nil {
allKeys := sm.ProviderKeys()
var providerKey configuration.ProviderKey
for _, key := range []configuration.ProviderKey{"inline", "asm"} {
if goslices.Contains(allKeys, key) {
providerKey = key
break
}
}

if err := sm.Set(ctx, providerKey, configuration.NewRef(module.Name, key), db.Runtime.DSN); err != nil {
return nil, fmt.Errorf("could not set database secret %s: %w", key, err)
}
logger.Infof("Database declaration: %s -> %s", db.Name, db.Runtime.DSN)
Expand Down
9 changes: 9 additions & 0 deletions internal/configuration/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ func (m *Manager[R]) availableProviderKeys() []string {
return keys
}

// ProviderKeys returns the keys of the available providers.
func (m *Manager[R]) ProviderKeys() []configuration.ProviderKey {
keys := make([]configuration.ProviderKey, 0, len(m.providers))
for k := range m.providers {
keys = append(keys, k)
}
return keys
}

// Set a configuration value, encoding "value" as JSON before storing it.
func (m *Manager[R]) Set(ctx context.Context, pkey configuration.ProviderKey, ref configuration.Ref, value any) error {
data, err := json.Marshal(value)
Expand Down

0 comments on commit d89b592

Please sign in to comment.