mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-31 18:48:08 +00:00
postgres: connection_url fix
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user