Skip to content

Commit

Permalink
Support postgres extra options [gcp] (#27)
Browse files Browse the repository at this point in the history
* Support postgres extra options [gcp]

Right now it is enforced to use sslmode when flyte admin is connecting to postgres and password provided.
The PR make it possible to connect to postgres when disabling sslmode.

* Add test

* Add test for case with pwd but no extra option
  • Loading branch information
tnsetting authored and Ketan Umare committed Nov 6, 2019
1 parent 42cd02d commit ec40b1d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flyteadmin/pkg/repositories/config/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (p *PostgresConfigProvider) GetArgs() string {
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s sslmode=disable",
p.config.Host, p.config.Port, p.config.DbName, p.config.User)
}
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s",
p.config.Host, p.config.Port, p.config.DbName, p.config.User, p.config.Password)
return fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s %s",
p.config.Host, p.config.Port, p.config.DbName, p.config.User, p.config.Password, p.config.ExtraOptions)
}

func (p *PostgresConfigProvider) WithDebugModeEnabled() {
Expand Down
25 changes: 25 additions & 0 deletions flyteadmin/pkg/repositories/config/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,28 @@ func TestConstructGormArgs(t *testing.T) {

assert.Equal(t, "host=localhost port=5432 dbname=postgres user=postgres sslmode=disable", postgresConfigProvider.GetArgs())
}

func TestConstructGormArgsWithPassword(t *testing.T) {
postgresConfigProvider := NewPostgresConfigProvider(DbConfig{
Host: "localhost",
Port: 5432,
DbName: "postgres",
User: "postgres",
Password: "pass",
ExtraOptions: "sslmode=enable",
}, mockScope.NewTestScope())

assert.Equal(t, "host=localhost port=5432 dbname=postgres user=postgres password=pass sslmode=enable", postgresConfigProvider.GetArgs())
}

func TestConstructGormArgsWithPasswordNoExtra(t *testing.T) {
postgresConfigProvider := NewPostgresConfigProvider(DbConfig{
Host: "localhost",
Port: 5432,
DbName: "postgres",
User: "postgres",
Password: "pass",
}, mockScope.NewTestScope())

assert.Equal(t, "host=localhost port=5432 dbname=postgres user=postgres password=pass ", postgresConfigProvider.GetArgs())
}

0 comments on commit ec40b1d

Please sign in to comment.