Redact sensitive values before logging them (#33829)

* use a common way to redact sensitive values before logging them

* fix panic on missing testCase.err, simplify require checks

* fix a silly typo

* combine readConfig and buildConnectionString methods, as they are closely related
This commit is contained in:
Serge Zaitsev
2021-05-10 17:03:10 +02:00
committed by GitHub
parent 5c13820bba
commit da13f88862
6 changed files with 77 additions and 94 deletions
+10 -4
View File
@@ -74,8 +74,6 @@ func (ss *SQLStore) Register() {
func (ss *SQLStore) Init() error {
ss.log = log.New("sqlstore")
ss.readConfig()
if err := ss.initEngine(); err != nil {
return errutil.Wrap("failed to connect to database", err)
}
@@ -204,6 +202,10 @@ func (ss *SQLStore) buildExtraConnectionString(sep rune) string {
}
func (ss *SQLStore) buildConnectionString() (string, error) {
if err := ss.readConfig(); err != nil {
return "", err
}
cnnstr := ss.dbCfg.ConnectionString
// special case used by integration tests
@@ -339,12 +341,15 @@ func (ss *SQLStore) initEngine() error {
}
// readConfig initializes the SQLStore from its configuration.
func (ss *SQLStore) readConfig() {
func (ss *SQLStore) readConfig() error {
sec := ss.Cfg.Raw.Section("database")
cfgURL := sec.Key("url").String()
if len(cfgURL) != 0 {
dbURL, _ := url.Parse(cfgURL)
dbURL, err := url.Parse(cfgURL)
if err != nil {
return err
}
ss.dbCfg.Type = dbURL.Scheme
ss.dbCfg.Host = dbURL.Host
@@ -382,6 +387,7 @@ func (ss *SQLStore) readConfig() {
ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
ss.dbCfg.SkipMigrations = sec.Key("skip_migrations").MustBool()
return nil
}
// ITestDB is an interface of arguments for testing db