[MM-18625] Make config.DatabaseStore.String() more robust (#12309)

Этот коммит содержится в:
Ben Schumacher
2019-09-26 07:17:39 +02:00
коммит произвёл GitHub
родитель b8f0546c19
Коммит 9a363f559e
3 изменённых файлов: 77 добавлений и 14 удалений

Просмотреть файл

@@ -7,8 +7,6 @@ import (
"bytes"
"database/sql"
"io/ioutil"
"net/url"
"regexp"
"strings"
"github.com/jmoiron/sqlx"
@@ -23,8 +21,6 @@ import (
_ "github.com/lib/pq"
)
var tcpStripper = regexp.MustCompile(`@tcp\((.*)\)`)
// DatabaseStore is a config store backed by a database.
type DatabaseStore struct {
commonStore
@@ -295,16 +291,7 @@ func (ds *DatabaseStore) RemoveFile(name string) error {
// String returns the path to the database backing the config, masking the password.
func (ds *DatabaseStore) String() string {
// Remove @tcp and the parentheses from the host and parse the rest as a URL
u, err := url.Parse(tcpStripper.ReplaceAllString(ds.originalDsn, `@$1`))
if err != nil {
return "(omitted due to error parsing the DSN)"
}
// Strip out the password to avoid leaking in logs.
u.User = url.User(u.User.Username())
return u.String()
return stripPassword(ds.originalDsn, ds.driverName)
}
// Close cleans up resources associated with the store.