Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): support scram-sha-256 authentication #5690

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions engine/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down