Skip to content

Commit

Permalink
fix: don't expose sql interface in dal
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Jul 3, 2024
1 parent a4e05af commit 2fd4fd6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
13 changes: 11 additions & 2 deletions common/configuration/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ func (d *DAL) UnsetModuleSecret(ctx context.Context, module optional.Option[stri
return nil
}

func (d *DAL) ListModuleSecrets(ctx context.Context) ([]sql.ModuleSecret, error) {
type ModuleSecret sql.ModuleSecret

func (d *DAL) ListModuleSecrets(ctx context.Context) ([]ModuleSecret, error) {
l, err := d.db.ListModuleSecrets(ctx)
if err != nil {
return nil, fmt.Errorf("could not list secrets: %w", dalerrs.TranslatePGError(err))
}
return l, nil

// Convert []sql.ModuleSecret to []ModuleSecret
ms := make([]ModuleSecret, len(l))
for i, secret := range l {
ms[i] = ModuleSecret(secret)
}

return ms, nil
}
4 changes: 2 additions & 2 deletions common/configuration/db_secret_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"net/url"

"github.com/TBD54566975/ftl/common/configuration/sql"
"github.com/TBD54566975/ftl/common/configuration/dal"
"github.com/alecthomas/types/optional"
)

Expand All @@ -16,7 +16,7 @@ type DBSecretResolver struct {

type DBSecretResolverDAL interface {
GetModuleSecretURL(ctx context.Context, module optional.Option[string], name string) (string, error)
ListModuleSecrets(ctx context.Context) ([]sql.ModuleSecret, error)
ListModuleSecrets(ctx context.Context) ([]dal.ModuleSecret, error)
SetModuleSecretURL(ctx context.Context, module optional.Option[string], name string, url string) error
UnsetModuleSecret(ctx context.Context, module optional.Option[string], name string) error
}
Expand Down
12 changes: 6 additions & 6 deletions common/configuration/db_secret_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import (
"net/url"
"testing"

"github.com/TBD54566975/ftl/common/configuration/sql"
"github.com/TBD54566975/ftl/common/configuration/dal"
"github.com/alecthomas/assert/v2"
. "github.com/alecthomas/types/optional"
)

type mockDBSecretResolverDAL struct {
entries []sql.ModuleSecret
entries []dal.ModuleSecret
}

func (d *mockDBSecretResolverDAL) findEntry(module Option[string], name string) (Option[sql.ModuleSecret], int) {
func (d *mockDBSecretResolverDAL) findEntry(module Option[string], name string) (Option[dal.ModuleSecret], int) {
for i := range d.entries {
if d.entries[i].Module.Default("") == module.Default("") && d.entries[i].Name == name {
return Some(d.entries[i]), i
}
}
return None[sql.ModuleSecret](), -1
return None[dal.ModuleSecret](), -1
}

func (d *mockDBSecretResolverDAL) GetModuleSecretURL(ctx context.Context, module Option[string], name string) (string, error) {
Expand All @@ -32,7 +32,7 @@ func (d *mockDBSecretResolverDAL) GetModuleSecretURL(ctx context.Context, module
return "", fmt.Errorf("secret not found")
}

func (d *mockDBSecretResolverDAL) ListModuleSecrets(ctx context.Context) ([]sql.ModuleSecret, error) {
func (d *mockDBSecretResolverDAL) ListModuleSecrets(ctx context.Context) ([]dal.ModuleSecret, error) {
return d.entries, nil
}

Expand All @@ -41,7 +41,7 @@ func (d *mockDBSecretResolverDAL) SetModuleSecretURL(ctx context.Context, module
if err != nil {
return fmt.Errorf("could not unset secret %w", err)
}
d.entries = append(d.entries, sql.ModuleSecret{Module: module, Name: name, Url: url})
d.entries = append(d.entries, dal.ModuleSecret{Module: module, Name: name, Url: url})
return nil
}

Expand Down

0 comments on commit 2fd4fd6

Please sign in to comment.