From 365a17abf76c48846358437d738a72326cdcff75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Wed, 17 Feb 2021 09:19:04 +0100 Subject: [PATCH] feat(engine): support scram-sha-256 authentication (#5690) Signed-off-by: francois samin --- engine/database/database.go | 12 ++++++++---- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/engine/database/database.go b/engine/database/database.go index a1536b9560..4969c58d6d 100644 --- a/engine/database/database.go +++ b/engine/database/database.go @@ -17,7 +17,6 @@ import ( // DBConnectionFactory is a database connection factory on postgres with gorp type DBConnectionFactory struct { - DBDriver string DBRole string DBUser string DBPassword string @@ -75,7 +74,6 @@ func Init(ctx context.Context, user, role, password, name, schema, host string, } f := &DBConnectionFactory{ - DBDriver: "postgres", DBRole: role, DBUser: user, DBPassword: password, @@ -121,7 +119,13 @@ func Init(ctx context.Context, user, role, password, name, schema, host string, // connect_timeout in seconds // statement_timeout in milliseconds dsn := f.dsn() - f.Database, err = sql.Open(f.DBDriver, dsn) + connector, err := pq.NewConnector(dsn) + if err != nil { + log.Error(ctx, "cannot open database: %s", err) + return nil, sdk.WithStack(err) + } + f.Database = sql.OpenDB(connector) + if err != nil { f.Database = nil log.Error(ctx, "cannot open database: %s", err) @@ -154,7 +158,7 @@ func Init(ctx context.Context, user, role, password, name, schema, host string, } func (f *DBConnectionFactory) dsn() string { - 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) + 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) if f.DBSchema != "public" { dsn += fmt.Sprintf(" search_path=%s", f.DBSchema) } diff --git a/go.mod b/go.mod index c295bea421..52272b6129 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,7 @@ require ( github.com/keybase/go.dbus v0.0.0-20190710215703-a33a09c8a604 github.com/kr/pty v1.1.8 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/lib/pq v1.0.0 + github.com/lib/pq v1.9.0 github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d // indirect github.com/maruel/panicparse v1.3.0 github.com/mattn/go-runewidth v0.0.1 // indirect diff --git a/go.sum b/go.sum index ebf55a398d..52586a1c80 100644 --- a/go.sum +++ b/go.sum @@ -343,8 +343,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= -github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8= +github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d h1:bM4HYnlVXPgUKmzl7o3drEaVfOk+sTBiADAQOWjU+8I=