From 2fff161e0944583d71cf6aaf8e005260eeb9dff4 Mon Sep 17 00:00:00 2001 From: a le <101848970+1aal@users.noreply.github.com> Date: Sat, 18 Nov 2023 15:47:54 +0800 Subject: [PATCH] fix: pg cluster connect fail (#5862) --- pkg/lorry/engines/foxlake/commands.go | 2 +- pkg/lorry/engines/mongodb/commands.go | 2 +- pkg/lorry/engines/mysql/commands.go | 2 +- pkg/lorry/engines/nebula/commands.go | 2 +- pkg/lorry/engines/oceanbase/commands.go | 2 +- pkg/lorry/engines/postgres/commands.go | 2 +- pkg/lorry/engines/redis/commands.go | 4 ++-- pkg/lorry/engines/util.go | 4 ++++ 8 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/lorry/engines/foxlake/commands.go b/pkg/lorry/engines/foxlake/commands.go index 060af62e7c0..24cfe84c94d 100644 --- a/pkg/lorry/engines/foxlake/commands.go +++ b/pkg/lorry/engines/foxlake/commands.go @@ -63,7 +63,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { userPass = connectInfo.UserPasswd } - foxlakeCmd := []string{fmt.Sprintf("%s mysql://%s:%s@:${serverPort}", r.info.Client, userName, userPass)} + foxlakeCmd := []string{fmt.Sprintf("%s %s", r.info.Client, engines.AddSingleQuote(fmt.Sprintf("mysql://%s:%s@:${serverPort}", userName, userPass)))} return []string{"sh", "-c", strings.Join(foxlakeCmd, " ")} } diff --git a/pkg/lorry/engines/mongodb/commands.go b/pkg/lorry/engines/mongodb/commands.go index 77d1f070d76..980c766b661 100644 --- a/pkg/lorry/engines/mongodb/commands.go +++ b/pkg/lorry/engines/mongodb/commands.go @@ -64,7 +64,7 @@ func (r Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { userPass = connectInfo.UserPasswd } - mongodbCmd := []string{fmt.Sprintf("export CLIENT=`which mongosh>/dev/null&&echo %s||echo mongo`; $CLIENT mongodb://%s:%s@$KB_POD_FQDN:27017/admin?replicaSet=$KB_CLUSTER_COMP_NAME", r.info.Client, userName, userPass)} + mongodbCmd := []string{fmt.Sprintf("export CLIENT=`which mongosh>/dev/null&&echo %s||echo mongo`; $CLIENT %s", r.info.Client, engines.AddSingleQuote(fmt.Sprintf("mongodb://%s:%s@$KB_POD_FQDN:27017/admin?replicaSet=$KB_CLUSTER_COMP_NAME", userName, userPass)))} return []string{"sh", "-c", strings.Join(mongodbCmd, " ")} } diff --git a/pkg/lorry/engines/mysql/commands.go b/pkg/lorry/engines/mysql/commands.go index a405f723d0a..0a5abf95e42 100644 --- a/pkg/lorry/engines/mysql/commands.go +++ b/pkg/lorry/engines/mysql/commands.go @@ -268,7 +268,7 @@ func (m *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { // MYSQL_PWD is deprecated as of MySQL 8.0; expect it to be removed in a future version of MySQL. // ref to mysql manual for more details. // https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html - mysqlCmd := []string{fmt.Sprintf("%s -u%s -p%s", m.info.Client, userName, userPass)} + mysqlCmd := []string{fmt.Sprintf("%s -u%s -p%s", m.info.Client, engines.AddSingleQuote(userName), engines.AddSingleQuote(userPass))} return []string{"sh", "-c", strings.Join(mysqlCmd, " ")} } diff --git a/pkg/lorry/engines/nebula/commands.go b/pkg/lorry/engines/nebula/commands.go index 9f1d18344a4..1909ca3c83b 100644 --- a/pkg/lorry/engines/nebula/commands.go +++ b/pkg/lorry/engines/nebula/commands.go @@ -61,7 +61,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { userPass = connectInfo.UserPasswd } - nebulaCmd := []string{fmt.Sprintf("%s --addr $GRAPHD_SVC_NAME --port $GRAPHD_SVC_PORT --user %s --password %s", r.info.Client, userName, userPass)} + nebulaCmd := []string{fmt.Sprintf("%s --addr $GRAPHD_SVC_NAME --port $GRAPHD_SVC_PORT --user %s --password %s", r.info.Client, userName, engines.AddSingleQuote(userPass))} return []string{"sh", "-c", strings.Join(nebulaCmd, " ")} } diff --git a/pkg/lorry/engines/oceanbase/commands.go b/pkg/lorry/engines/oceanbase/commands.go index cec219a6a80..978f4c59b92 100644 --- a/pkg/lorry/engines/oceanbase/commands.go +++ b/pkg/lorry/engines/oceanbase/commands.go @@ -64,7 +64,7 @@ func (r *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { var obCmd []string if userPass != "" { - obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A -p%s", r.info.Client, userName, userPass)} + obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A -p%s", r.info.Client, userName, engines.AddSingleQuote(userPass))} } else { obCmd = []string{fmt.Sprintf("%s -h127.0.0.1 -P2881 -u%s -A", r.info.Client, userName)} } diff --git a/pkg/lorry/engines/postgres/commands.go b/pkg/lorry/engines/postgres/commands.go index 2fc4bb99dd6..57c1ae0c4d1 100644 --- a/pkg/lorry/engines/postgres/commands.go +++ b/pkg/lorry/engines/postgres/commands.go @@ -248,7 +248,7 @@ func (m *Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { // please refer to PostgreSQL documentation for more details // https://www.postgresql.org/docs/current/libpq-envars.html - cmd := []string{fmt.Sprintf("PGUSER=%s PGPASSWORD=%s PGDATABASE=%s %s", userName, userPass, m.info.Database, m.info.Client)} + cmd := []string{fmt.Sprintf("PGUSER=%s PGPASSWORD=%s PGDATABASE=%s %s", engines.AddSingleQuote(userName), engines.AddSingleQuote(userPass), m.info.Database, m.info.Client)} return []string{"sh", "-c", strings.Join(cmd, " ")} } diff --git a/pkg/lorry/engines/redis/commands.go b/pkg/lorry/engines/redis/commands.go index 826b43858d8..8448f104e16 100644 --- a/pkg/lorry/engines/redis/commands.go +++ b/pkg/lorry/engines/redis/commands.go @@ -58,8 +58,8 @@ func (r Commands) ConnectCommand(connectInfo *engines.AuthInfo) []string { } if connectInfo != nil { - redisCmd = append(redisCmd, "--user", connectInfo.UserName) - redisCmd = append(redisCmd, "--pass", connectInfo.UserPasswd) + redisCmd = append(redisCmd, "--user", engines.AddSingleQuote(connectInfo.UserName)) + redisCmd = append(redisCmd, "--pass", engines.AddSingleQuote(connectInfo.UserPasswd)) } return []string{"sh", "-c", strings.Join(redisCmd, " ")} } diff --git a/pkg/lorry/engines/util.go b/pkg/lorry/engines/util.go index ffae4f40987..4907bd36a48 100644 --- a/pkg/lorry/engines/util.go +++ b/pkg/lorry/engines/util.go @@ -47,4 +47,8 @@ func GetIndex(memberName string) (int, error) { return strconv.Atoi(memberName[i+1:]) } +func AddSingleQuote(str string) string { + return "'" + str + "'" +} + type Properties map[string]string