Define time zone explicitly in postgresql connection string.

This commit is contained in:
Lassi Pölönen
2015-09-14 13:41:29 +03:00
parent ea2a6361eb
commit 1a6f778623

View File

@@ -6,6 +6,7 @@ import (
"strings"
"sync"
"github.com/lib/pq"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
@@ -74,6 +75,16 @@ func (b *backend) DB(s logical.Storage) (*sql.DB, error) {
return nil, err
}
// 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
}
}
conn += " timezone=utc"
b.db, err = sql.Open("postgres", conn)
if err != nil {
return nil, err