Commit b3f2cf30 authored by Adhityaa Chandrasekar's avatar Adhityaa Chandrasekar

database_connect.go: redact password before log message

parent bbea9df8
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"database/sql" "database/sql"
"net/url"
_ "github.com/lib/pq" _ "github.com/lib/pq"
"os" "os"
"strconv" "strconv"
...@@ -10,9 +11,14 @@ import ( ...@@ -10,9 +11,14 @@ import (
func dbConnect(retriesLeft int) error { func dbConnect(retriesLeft int) error {
con := os.Getenv("POSTGRES") 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) db, err = sql.Open("postgres", con)
if err != nil { if err != nil {
logger.Errorf("cannot open connection to postgres: %v", err) logger.Errorf("cannot open connection to postgres: %v", err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment