[MM-18625] Make config.DatabaseStore.String() more robust (#12309)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b8f0546c19
Коммит
9a363f559e
@@ -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.
|
||||
|
||||
Ссылка в новой задаче
Block a user