Skip to content

Commit 365a17a

Browse files
authored
feat(engine): support scram-sha-256 authentication (#5690)
Signed-off-by: francois samin <francois.samin@corp.ovh.com>
1 parent a2cf555 commit 365a17a

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

engine/database/database.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
// DBConnectionFactory is a database connection factory on postgres with gorp
1919
type DBConnectionFactory struct {
20-
DBDriver string
2120
DBRole string
2221
DBUser string
2322
DBPassword string
@@ -75,7 +74,6 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
7574
}
7675

7776
f := &DBConnectionFactory{
78-
DBDriver: "postgres",
7977
DBRole: role,
8078
DBUser: user,
8179
DBPassword: password,
@@ -121,7 +119,13 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
121119
// connect_timeout in seconds
122120
// statement_timeout in milliseconds
123121
dsn := f.dsn()
124-
f.Database, err = sql.Open(f.DBDriver, dsn)
122+
connector, err := pq.NewConnector(dsn)
123+
if err != nil {
124+
log.Error(ctx, "cannot open database: %s", err)
125+
return nil, sdk.WithStack(err)
126+
}
127+
f.Database = sql.OpenDB(connector)
128+
125129
if err != nil {
126130
f.Database = nil
127131
log.Error(ctx, "cannot open database: %s", err)
@@ -154,7 +158,7 @@ func Init(ctx context.Context, user, role, password, name, schema, host string,
154158
}
155159

156160
func (f *DBConnectionFactory) dsn() string {
157-
dsn := fmt.Sprintf("user=%s password=%s dbname=%s host=%s port=%d sslmode=%s connect_timeout=%d", f.DBUser, f.DBPassword, f.DBName, f.DBHost, f.DBPort, f.DBSSLMode, f.DBConnectTimeout)
161+
dsn := fmt.Sprintf("user=%s password='%s' dbname=%s host=%s port=%d sslmode=%s connect_timeout=%d", f.DBUser, f.DBPassword, f.DBName, f.DBHost, f.DBPort, f.DBSSLMode, f.DBConnectTimeout)
158162
if f.DBSchema != "public" {
159163
dsn += fmt.Sprintf(" search_path=%s", f.DBSchema)
160164
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ require (
6666
github.com/keybase/go.dbus v0.0.0-20190710215703-a33a09c8a604
6767
github.com/kr/pty v1.1.8 // indirect
6868
github.com/kylelemons/godebug v1.1.0 // indirect
69-
github.com/lib/pq v1.0.0
69+
github.com/lib/pq v1.9.0
7070
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect
7171
github.com/maruel/panicparse v1.3.0
7272
github.com/mattn/go-runewidth v0.0.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
343343
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
344344
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
345345
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
346-
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
347-
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
346+
github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
347+
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
348348
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
349349
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
350350
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d h1:bM4HYnlVXPgUKmzl7o3drEaVfOk+sTBiADAQOWjU+8I=

0 commit comments

Comments
 (0)