From 3f8b0da6772ea99b600303bb1ad3f6430a45290a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 17 Feb 2021 02:13:50 -0800 Subject: [PATCH] filer: do not print password on error fix https://github.com/chrislusf/seaweedfs/issues/1809 --- weed/filer/mysql/mysql_store.go | 4 +++- weed/filer/mysql2/mysql2_store.go | 4 +++- weed/filer/postgres/postgres_store.go | 8 ++++++-- weed/filer/postgres2/postgres2_store.go | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.go index 23b3bef11..022a8d72d 100644 --- a/weed/filer/mysql/mysql_store.go +++ b/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) + adaptedSqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, "", hostname, port, database) if interpolateParams { sqlUrl += "&interpolateParams=true" + adaptedSqlUrl += "&interpolateParams=true" } var dbErr error @@ -60,7 +62,7 @@ func (store *MysqlStore) initialize(user, password, hostname string, port int, d if dbErr != nil { store.DB.Close() 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) diff --git a/weed/filer/mysql2/mysql2_store.go b/weed/filer/mysql2/mysql2_store.go index 2db7a820d..c796cd6aa 100644 --- a/weed/filer/mysql2/mysql2_store.go +++ b/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) + adaptedSqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, "", hostname, port, database) if interpolateParams { sqlUrl += "&interpolateParams=true" + adaptedSqlUrl += "&interpolateParams=true" } var dbErr error @@ -63,7 +65,7 @@ func (store *MysqlStore2) initialize(createTable, user, password, hostname strin if dbErr != nil { store.DB.Close() 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) diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 75d80e44a..9e4ff7c32 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -47,28 +47,32 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int store.SupportBucketTable = false store.SqlGenerator = &SqlGenPostgres{ CreateTableSqlTemplate: "", - DropTableSqlTemplate: `drop table "%s"`, + DropTableSqlTemplate: `drop table "%s"`, } sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) if user != "" { sqlUrl += " user=" + user } + adaptedSqlUrl := sqlUrl if password != "" { sqlUrl += " password=" + password + adaptedSqlUrl += " password=ADAPTED" } if database != "" { sqlUrl += " dbname=" + database + adaptedSqlUrl += " dbname=" + database } if schema != "" { sqlUrl += " search_path=" + schema + adaptedSqlUrl += " search_path=" + schema } var dbErr error store.DB, dbErr = sql.Open("postgres", sqlUrl) if dbErr != nil { store.DB.Close() 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) diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index 44487fd0e..4b5fbc8cf 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -57,21 +57,25 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st if user != "" { sqlUrl += " user=" + user } + adaptedSqlUrl := sqlUrl if password != "" { sqlUrl += " password=" + password + adaptedSqlUrl += " password=ADAPTED" } if database != "" { sqlUrl += " dbname=" + database + adaptedSqlUrl += " dbname=" + database } if schema != "" { sqlUrl += " search_path=" + schema + adaptedSqlUrl += " search_path=" + schema } var dbErr error store.DB, dbErr = sql.Open("postgres", sqlUrl) if dbErr != nil { store.DB.Close() 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)