Mask DB password in logs (#1072)

This commit is contained in:
Owen Cliffe
2018-06-19 18:59:28 +01:00
committed by GitHub
parent 4bf23d8c1b
commit 229353051f
2 changed files with 15 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"strings"
)
func SetLogLevel(ll string) {
@@ -80,3 +81,14 @@ func SetLogDest(to, prefix string) {
logrus.WithFields(logrus.Fields{"scheme": parsed.Scheme, "to": to}).Error("unknown logging location scheme, defaulting to stderr")
}
}
// MaskPassword returns a stringified URL without its password visible
func MaskPassword(u *url.URL) string {
if u.User != nil {
p, set := u.User.Password()
if set {
return strings.Replace(u.String(), p+"@", "***@", 1)
}
}
return u.String()
}