From 39cbdf789d3448c56ba394557e8100a143694c56 Mon Sep 17 00:00:00 2001 From: Artemiy Ryabinkov Date: Thu, 11 Jul 2019 20:56:44 +0300 Subject: [PATCH] Support of PGTARGETSESSIONATTRS ENV variable Signed-off-by: Artemiy Ryabinkov --- conn.go | 8 +++++++- pgpass.go | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index fd134461..76e09e73 100644 --- a/conn.go +++ b/conn.go @@ -1016,6 +1016,7 @@ func ParseURI(uri string) (ConnConfig, error) { if cp.Password == "" { pgpass(&cp) } + return cp, nil } @@ -1181,7 +1182,7 @@ func ParseConnectionString(s string) (ConnConfig, error) { // PGSSLROOTCERT // PGAPPNAME // PGCONNECT_TIMEOUT -// TODO: PGTARGETSESSIONATTRS support +// PGTARGETSESSIONATTRS // @see: https://www.postgresql.org/docs/10/libpq-envars.html // // Important TLS Security Notes: @@ -1228,6 +1229,11 @@ func ParseEnvLibpq() (ConnConfig, error) { } } + cc.TargetSessionAttrs = TargetSessionType(os.Getenv("PGTARGETSESSIONATTRS")) + if err := cc.TargetSessionAttrs.isValid(); err != nil { + return cc, err + } + tlsArgs := configTLSArgs{ sslMode: os.Getenv("PGSSLMODE"), sslKey: os.Getenv("PGSSLKEY"), diff --git a/pgpass.go b/pgpass.go index ff97e5f0..34b9bdf5 100644 --- a/pgpass.go +++ b/pgpass.go @@ -57,7 +57,6 @@ func parsepgpass(line, cfgHost, cfgPort, cfgDatabase, cfgUsername string) *strin return &parts[4] } -// TODO: Multi-host support func pgpass(cfg *ConnConfig) (found bool) { passfile := os.Getenv("PGPASSFILE") if passfile == "" {