postgres: connection_url fix

This commit is contained in:
vishalnayak
2016-02-18 21:03:47 -05:00
parent 2be9a34a83
commit 046d7f87b4
7 changed files with 128 additions and 32 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
"github.com/lib/pq"
)
func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
@@ -76,20 +75,21 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
return nil, err
}
conn := connConfig.ConnectionString
conn := connConfig.ConnectionURL
if len(conn) == 0 {
conn = connConfig.ConnectionURL
conn = connConfig.ConnectionString
}
// Ensure timezone is set to UTC for all the conenctions
if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") {
var err error
conn, err = pq.ParseURL(conn)
if err != nil {
return nil, err
if strings.Contains(conn, "?") {
conn += "&timezone=utc"
} else {
conn += "?timezone=utc"
}
} else {
conn += " timezone=utc"
}
conn += " timezone=utc"
b.db, err = sql.Open("postgres", conn)
if err != nil {