From b3f2cf306451d4237b23d0eb352de966042631dc Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Thu, 13 Feb 2020 19:12:52 -0500 Subject: [PATCH] database_connect.go: redact password before log message --- api/database_connect.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/database_connect.go b/api/database_connect.go index f2441d0..a23b90c 100644 --- a/api/database_connect.go +++ b/api/database_connect.go @@ -2,6 +2,7 @@ package main import ( "database/sql" + "net/url" _ "github.com/lib/pq" "os" "strconv" @@ -10,9 +11,14 @@ import ( func dbConnect(retriesLeft int) error { con := os.Getenv("POSTGRES") - logger.Infof("opening connection to postgres: %s", con) + u, err := url.Parse(con) + if err != nil { + logger.Errorf("invalid postgres connection URI: %v", err) + return err + } + u.User = url.UserPassword(u.User.Username(), "redacted") + logger.Infof("opening connection to postgres: %s", u.String()) - var err error db, err = sql.Open("postgres", con) if err != nil { logger.Errorf("cannot open connection to postgres: %v", err)