Browse Source

filer: do not print password on error

fix https://github.com/chrislusf/seaweedfs/issues/1809
pull/1811/head
Chris Lu 4 years ago
parent
commit
3f8b0da677
  1. 4
      weed/filer/mysql/mysql_store.go
  2. 4
      weed/filer/mysql2/mysql2_store.go
  3. 6
      weed/filer/postgres/postgres_store.go
  4. 6
      weed/filer/postgres2/postgres2_store.go

4
weed/filer/mysql/mysql_store.go

@ -51,8 +51,10 @@ func (store *MysqlStore) initialize(user, password, hostname string, port int, d
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)
adaptedSqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, "<ADAPTED>", hostname, port, database)
if interpolateParams { if interpolateParams {
sqlUrl += "&interpolateParams=true" sqlUrl += "&interpolateParams=true"
adaptedSqlUrl += "&interpolateParams=true"
} }
var dbErr error var dbErr error
@ -60,7 +62,7 @@ func (store *MysqlStore) initialize(user, password, hostname string, port int, d
if dbErr != nil { if dbErr != nil {
store.DB.Close() store.DB.Close()
store.DB = nil store.DB = nil
return fmt.Errorf("can not connect to %s error:%v", sqlUrl, err)
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
} }
store.DB.SetMaxIdleConns(maxIdle) store.DB.SetMaxIdleConns(maxIdle)

4
weed/filer/mysql2/mysql2_store.go

@ -54,8 +54,10 @@ func (store *MysqlStore2) initialize(createTable, user, password, hostname strin
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)
adaptedSqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, "<ADAPTED>", hostname, port, database)
if interpolateParams { if interpolateParams {
sqlUrl += "&interpolateParams=true" sqlUrl += "&interpolateParams=true"
adaptedSqlUrl += "&interpolateParams=true"
} }
var dbErr error var dbErr error
@ -63,7 +65,7 @@ func (store *MysqlStore2) initialize(createTable, user, password, hostname strin
if dbErr != nil { if dbErr != nil {
store.DB.Close() store.DB.Close()
store.DB = nil store.DB = nil
return fmt.Errorf("can not connect to %s error:%v", sqlUrl, err)
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
} }
store.DB.SetMaxIdleConns(maxIdle) store.DB.SetMaxIdleConns(maxIdle)

6
weed/filer/postgres/postgres_store.go

@ -54,21 +54,25 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int
if user != "" { if user != "" {
sqlUrl += " user=" + user sqlUrl += " user=" + user
} }
adaptedSqlUrl := sqlUrl
if password != "" { if password != "" {
sqlUrl += " password=" + password sqlUrl += " password=" + password
adaptedSqlUrl += " password=ADAPTED"
} }
if database != "" { if database != "" {
sqlUrl += " dbname=" + database sqlUrl += " dbname=" + database
adaptedSqlUrl += " dbname=" + database
} }
if schema != "" { if schema != "" {
sqlUrl += " search_path=" + schema sqlUrl += " search_path=" + schema
adaptedSqlUrl += " search_path=" + schema
} }
var dbErr error var dbErr error
store.DB, dbErr = sql.Open("postgres", sqlUrl) store.DB, dbErr = sql.Open("postgres", sqlUrl)
if dbErr != nil { if dbErr != nil {
store.DB.Close() store.DB.Close()
store.DB = nil store.DB = nil
return fmt.Errorf("can not connect to %s error:%v", sqlUrl, err)
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
} }
store.DB.SetMaxIdleConns(maxIdle) store.DB.SetMaxIdleConns(maxIdle)

6
weed/filer/postgres2/postgres2_store.go

@ -57,21 +57,25 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st
if user != "" { if user != "" {
sqlUrl += " user=" + user sqlUrl += " user=" + user
} }
adaptedSqlUrl := sqlUrl
if password != "" { if password != "" {
sqlUrl += " password=" + password sqlUrl += " password=" + password
adaptedSqlUrl += " password=ADAPTED"
} }
if database != "" { if database != "" {
sqlUrl += " dbname=" + database sqlUrl += " dbname=" + database
adaptedSqlUrl += " dbname=" + database
} }
if schema != "" { if schema != "" {
sqlUrl += " search_path=" + schema sqlUrl += " search_path=" + schema
adaptedSqlUrl += " search_path=" + schema
} }
var dbErr error var dbErr error
store.DB, dbErr = sql.Open("postgres", sqlUrl) store.DB, dbErr = sql.Open("postgres", sqlUrl)
if dbErr != nil { if dbErr != nil {
store.DB.Close() store.DB.Close()
store.DB = nil store.DB = nil
return fmt.Errorf("can not connect to %s error:%v", sqlUrl, err)
return fmt.Errorf("can not connect to %s error:%v", adaptedSqlUrl, err)
} }
store.DB.SetMaxIdleConns(maxIdle) store.DB.SetMaxIdleConns(maxIdle)

Loading…
Cancel
Save