Skip to content

Commit

Permalink
Actually use resolved db password from path (flyteorg#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan authored Mar 2, 2022
1 parent 560d784 commit d5aa1f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/repositories/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getPostgresDsn(ctx context.Context, pgConfig runtimeInterfaces.PostgresConf
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User)
}
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s %s",
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User, pgConfig.Password, pgConfig.ExtraOptions)
pgConfig.Host, pgConfig.Port, pgConfig.DbName, pgConfig.User, password, pgConfig.ExtraOptions)
}

func GetDB(ctx context.Context, dbConfig *runtimeInterfaces.DbConfig, logConfig *logger.Config) (
Expand Down
29 changes: 29 additions & 0 deletions pkg/repositories/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repositories

import (
"context"
"io/ioutil"
"testing"

runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
Expand Down Expand Up @@ -36,6 +37,20 @@ func TestGetGormLogLevel(t *testing.T) {
assert.Equal(t, gormLogger.Error, getGormLogLevel(context.TODO(), nil))
}

func TestResolvePassword(t *testing.T) {
password := "123abc"
tmpFile, err := ioutil.TempFile("", "prefix")
if err != nil {
t.Errorf("Couldn't open temp file: %v", err)
}
defer tmpFile.Close()
if _, err = tmpFile.WriteString(password); err != nil {
t.Errorf("Couldn't write to temp file: %v", err)
}
resolvedPassword := resolvePassword(context.TODO(), "", tmpFile.Name())
assert.Equal(t, resolvedPassword, password)
}

func TestGetPostgresDsn(t *testing.T) {
pgConfig := runtimeInterfaces.PostgresConfig{
Host: "localhost",
Expand All @@ -60,4 +75,18 @@ func TestGetPostgresDsn(t *testing.T) {
dsn := getPostgresDsn(context.TODO(), pgConfig)
assert.Equal(t, "host=localhost port=5432 dbname=postgres user=postgres password=pass ", dsn)
})
t.Run("with password path", func(t *testing.T) {
password := "123abc"
tmpFile, err := ioutil.TempFile("", "prefix")
if err != nil {
t.Errorf("Couldn't open temp file: %v", err)
}
defer tmpFile.Close()
if _, err = tmpFile.WriteString(password); err != nil {
t.Errorf("Couldn't write to temp file: %v", err)
}
pgConfig.PasswordPath = tmpFile.Name()
dsn := getPostgresDsn(context.TODO(), pgConfig)
assert.Equal(t, "host=localhost port=5432 dbname=postgres user=postgres password=123abc ", dsn)
})
}

0 comments on commit d5aa1f4

Please sign in to comment.