mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Mask DB password in logs (#1072)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetLogLevel(ll string) {
|
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")
|
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()
|
||||||
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func (sqlLogsProvider) New(ctx context.Context, u *url.URL) (models.LogStore, er
|
|||||||
func newDS(ctx context.Context, url *url.URL) (*SQLStore, error) {
|
func newDS(ctx context.Context, url *url.URL) (*SQLStore, error) {
|
||||||
driver := url.Scheme
|
driver := url.Scheme
|
||||||
|
|
||||||
log := common.Logger(ctx)
|
log := common.Logger(ctx).WithFields(logrus.Fields{"url": common.MaskPassword(url)})
|
||||||
helper, ok := dbhelper.GetHelper(driver)
|
helper, ok := dbhelper.GetHelper(driver)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -160,7 +160,7 @@ func newDS(ctx context.Context, url *url.URL) (*SQLStore, error) {
|
|||||||
|
|
||||||
sqldb, err := sql.Open(driver, uri)
|
sqldb, err := sql.Open(driver, uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{"url": uri}).WithError(err).Error("couldn't open db")
|
log.WithError(err).Error("couldn't open db")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ func newDS(ctx context.Context, url *url.URL) (*SQLStore, error) {
|
|||||||
// force a connection and test that it worked
|
// force a connection and test that it worked
|
||||||
err = pingWithRetry(ctx, db)
|
err = pingWithRetry(ctx, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{"url": uri}).WithError(err).Error("couldn't ping db")
|
log.WithError(err).Error("couldn't ping db")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user