From bc8bac5191f6e6bd5a1762ed089a5c48d4b13263 Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Tue, 28 Apr 2020 20:35:37 +0800 Subject: [PATCH 1/7] feat: add support encrypted and unencrypted in config file --- cmd/dm-ctl/main.go | 4 +++- dm/config/source_config.go | 2 +- dm/config/subtask.go | 4 ++-- dm/ctl/common/config.go | 19 ++++++++++++++++--- dm/portal/api.go | 2 +- pkg/utils/encrypt.go | 10 ++++++++++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/cmd/dm-ctl/main.go b/cmd/dm-ctl/main.go index 4b266f3585..4290174ee9 100644 --- a/cmd/dm-ctl/main.go +++ b/cmd/dm-ctl/main.go @@ -74,10 +74,12 @@ func helpUsage(cfg *common.Config) { fmt.Println("Special Commands:") f := cfg.FlagSet.Lookup(common.EncryptCmdName) fmt.Println(fmt.Sprintf(" --%s %s", f.Name, f.Usage)) + f = cfg.FlagSet.Lookup(common.DecryptCmdName) + fmt.Println(fmt.Sprintf(" --%s %s", f.Name, f.Usage)) fmt.Println() fmt.Println("Global Options:") cfg.FlagSet.VisitAll(func(flag2 *flag.Flag) { - if flag2.Name == common.EncryptCmdName { + if flag2.Name == common.EncryptCmdName || flag2.Name == common.DecryptCmdName { return } fmt.Println(fmt.Sprintf(" --%s %s", flag2.Name, flag2.Usage)) diff --git a/dm/config/source_config.go b/dm/config/source_config.go index 84fde3bde9..f408775621 100644 --- a/dm/config/source_config.go +++ b/dm/config/source_config.go @@ -183,7 +183,7 @@ func (c *SourceConfig) DecryptPassword() (*SourceConfig, error) { err error ) if len(clone.From.Password) > 0 { - pswdFrom, err = utils.Decrypt(clone.From.Password) + pswdFrom, err = utils.DecryptOrPlaintext(clone.From.Password) if err != nil { return nil, terror.WithClass(err, terror.ClassDMWorker) } diff --git a/dm/config/subtask.go b/dm/config/subtask.go index 3dc0a8c24a..213e47379d 100644 --- a/dm/config/subtask.go +++ b/dm/config/subtask.go @@ -346,13 +346,13 @@ func (c *SubTaskConfig) DecryptPassword() (*SubTaskConfig, error) { pswdFrom string ) if len(clone.To.Password) > 0 { - pswdTo, err = utils.Decrypt(clone.To.Password) + pswdTo, err = utils.DecryptOrPlaintext(clone.To.Password) if err != nil { return nil, terror.WithScope(terror.ErrConfigDecryptDBPassword.Delegate(err, clone.To.Password), terror.ScopeDownstream) } } if len(clone.From.Password) > 0 { - pswdFrom, err = utils.Decrypt(clone.From.Password) + pswdFrom, err = utils.DecryptOrPlaintext(clone.From.Password) if err != nil { return nil, terror.WithScope(terror.ErrConfigDecryptDBPassword.Delegate(err, clone.From.Password), terror.ScopeUpstream) } diff --git a/dm/ctl/common/config.go b/dm/ctl/common/config.go index c48da639f9..dcde64b294 100644 --- a/dm/ctl/common/config.go +++ b/dm/ctl/common/config.go @@ -31,6 +31,8 @@ const ( // EncryptCmdName is special command EncryptCmdName = "encrypt" + // DecryptCmdName is special command + DecryptCmdName = "decrypt" ) // NewConfig creates a new base config for dmctl. @@ -47,6 +49,7 @@ func NewConfig() *Config { fs.StringVar(&cfg.MasterAddr, "master-addr", "", "master API server addr") fs.StringVar(&cfg.RPCTimeoutStr, "rpc-timeout", defaultRPCTimeout, fmt.Sprintf("rpc timeout, default is %s", defaultRPCTimeout)) fs.StringVar(&cfg.encrypt, EncryptCmdName, "", "encrypt plaintext to ciphertext") + fs.StringVar(&cfg.decrypt, DecryptCmdName, "", "decrypt ciphertext to plaintext") return cfg } @@ -64,6 +67,7 @@ type Config struct { printVersion bool encrypt string // string need to be encrypted + decrypt string // string need to be decrypted } func (c *Config) String() string { @@ -87,14 +91,23 @@ func (c *Config) Parse(arguments []string) (finish bool, err error) { } if len(c.encrypt) > 0 { - ciphertext, err1 := utils.Encrypt(c.encrypt) - if err1 != nil { - return true, err1 + ciphertext, err := utils.Encrypt(c.encrypt) + if err != nil { + return true, err } fmt.Println(ciphertext) return true, nil } + if len(c.decrypt) > 0 { + plaintext, err := utils.Decrypt(c.decrypt) + if err != nil { + return true, err + } + fmt.Println(plaintext) + return true, nil + } + // Load config file if specified. if c.ConfigFile != "" { err = c.configFromFile(c.ConfigFile) diff --git a/dm/portal/api.go b/dm/portal/api.go index 44c572a57e..1c7ffb8a15 100644 --- a/dm/portal/api.go +++ b/dm/portal/api.go @@ -341,7 +341,7 @@ func (p *Handler) AnalyzeConfig(w http.ResponseWriter, req *http.Request) { log.L().Info("analyze config", zap.String("config name", cfg.Name)) // decrypt password - dePwd, err := utils.Decrypt(cfg.TargetDB.Password) + dePwd, err := utils.DecryptOrPlaintext(cfg.TargetDB.Password) log.L().Error("decrypt password failed", zap.Error(err)) if err != nil { p.genJSONResp(w, http.StatusBadRequest, AnalyzeResult{ diff --git a/pkg/utils/encrypt.go b/pkg/utils/encrypt.go index d41ac67513..2e1e899771 100644 --- a/pkg/utils/encrypt.go +++ b/pkg/utils/encrypt.go @@ -43,3 +43,13 @@ func Decrypt(ciphertextB64 string) (string, error) { } return string(plaintext), nil } + + +// DecryptOrPlaintext tries to decrypt base64 encoded ciphertext to plaintext or return plaintext +func DecryptOrPlaintext(ciphertextB64 string) (string, error) { + plaintext, err := Decrypt(ciphertextB64) + if err != nil { + return ciphertextB64, nil + } + return plaintext, nil +} \ No newline at end of file From 53ebb15501c5f9b77c3c4f553e19181229aafd80 Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Wed, 6 May 2020 08:45:45 +0800 Subject: [PATCH 2/7] fix(): --- dm/ctl/common/config.go | 12 ++++++------ pkg/utils/encrypt.go | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dm/ctl/common/config.go b/dm/ctl/common/config.go index dcde64b294..21718a5fee 100644 --- a/dm/ctl/common/config.go +++ b/dm/ctl/common/config.go @@ -91,18 +91,18 @@ func (c *Config) Parse(arguments []string) (finish bool, err error) { } if len(c.encrypt) > 0 { - ciphertext, err := utils.Encrypt(c.encrypt) - if err != nil { - return true, err + ciphertext, err1 := utils.Encrypt(c.encrypt) + if err1 != nil { + return true, err1 } fmt.Println(ciphertext) return true, nil } if len(c.decrypt) > 0 { - plaintext, err := utils.Decrypt(c.decrypt) - if err != nil { - return true, err + plaintext, err1 := utils.Decrypt(c.decrypt) + if err1 != nil { + return true, err1 } fmt.Println(plaintext) return true, nil diff --git a/pkg/utils/encrypt.go b/pkg/utils/encrypt.go index 2e1e899771..cce7bd49f7 100644 --- a/pkg/utils/encrypt.go +++ b/pkg/utils/encrypt.go @@ -44,7 +44,6 @@ func Decrypt(ciphertextB64 string) (string, error) { return string(plaintext), nil } - // DecryptOrPlaintext tries to decrypt base64 encoded ciphertext to plaintext or return plaintext func DecryptOrPlaintext(ciphertextB64 string) (string, error) { plaintext, err := Decrypt(ciphertextB64) @@ -52,4 +51,4 @@ func DecryptOrPlaintext(ciphertextB64 string) (string, error) { return ciphertextB64, nil } return plaintext, nil -} \ No newline at end of file +} From eb8f7e15190f804eee54458e082b9fd94edb0c20 Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Wed, 6 May 2020 09:06:13 +0800 Subject: [PATCH 3/7] fix(test): test case --- tests/dmctl_command/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dmctl_command/run.sh b/tests/dmctl_command/run.sh index c5938bd0fc..8ff2505e96 100644 --- a/tests/dmctl_command/run.sh +++ b/tests/dmctl_command/run.sh @@ -13,7 +13,7 @@ function run() { $PWD/bin/dmctl.test DEVEL > $WORK_DIR/help.log help_msg=$(cat $WORK_DIR/help.log) help_msg_cnt=$(echo "${help_msg}" | wc -l |xargs) - if [ "$help_msg_cnt" != 34 ]; then + if [ "$help_msg_cnt" != 35 ]; then echo "dmctl case 1 help failed: $help_msg" echo $help_msg_cnt exit 1 @@ -24,7 +24,7 @@ function run() { $PWD/bin/dmctl.test DEVEL --help > $WORK_DIR/help.log help_msg=$(cat $WORK_DIR/help.log) help_msg_cnt=$(echo "${help_msg}" | wc -l |xargs) - if [ "$help_msg_cnt" != 34 ]; then + if [ "$help_msg_cnt" != 35 ]; then echo "dmctl case 2 help failed: $help_msg" exit 1 fi From 9f7ad8de2338daadde65b4e0b736247a90f134ba Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Mon, 18 May 2020 13:38:58 +0800 Subject: [PATCH 4/7] fix: test case --- dm/config/source_config_test.go | 12 ++++++++++-- dm/config/subtask_test.go | 4 ++-- dm/master/server_test.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dm/config/source_config_test.go b/dm/config/source_config_test.go index 953b4e3c64..3d20506385 100644 --- a/dm/config/source_config_test.go +++ b/dm/config/source_config_test.go @@ -68,7 +68,7 @@ func (t *testConfig) TestConfig(c *C) { cfg.From.Password = "xxx" _, err = cfg.DecryptPassword() - c.Assert(err, NotNil) + c.Assert(err, IsNil) cfg.From.Password = "" clone3, err := cfg.DecryptPassword() @@ -167,7 +167,15 @@ func (t *testConfig) TestConfigVerify(c *C) { cfg.From.Password = "not-encrypt" return cfg }, - "*decode base64 encoded password.*", + "", + }, + { + func() *SourceConfig { + cfg := newConfig() + cfg.From.Password = "" // password empty + return cfg + }, + "", }, } diff --git a/dm/config/subtask_test.go b/dm/config/subtask_test.go index 39ba09adda..8a9fdb44c3 100644 --- a/dm/config/subtask_test.go +++ b/dm/config/subtask_test.go @@ -52,9 +52,9 @@ func (t *testConfig) TestSubTask(c *C) { cfg.From.Password = "xxx" _, err = cfg.DecryptPassword() - c.Assert(err, NotNil) + c.Assert(err, IsNil) err = cfg.Adjust(true) - c.Assert(err, NotNil) + c.Assert(err, IsNil) err = cfg.Adjust(false) c.Assert(err, IsNil) diff --git a/dm/master/server_test.go b/dm/master/server_test.go index 0ff4d8f110..812de4c977 100644 --- a/dm/master/server_test.go +++ b/dm/master/server_test.go @@ -357,7 +357,7 @@ func (t *testMaster) TestCheckTask(c *check.C) { Task: taskConfig, }) c.Assert(err, check.IsNil) - c.Assert(resp.Result, check.IsFalse) + c.Assert(resp.Result, check.IsTrue) clearSchedulerEnv(c, cancel, &wg) } From 07eabac38ba5cd4de4c699c385e75ccfb1eca335 Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Tue, 19 May 2020 21:54:06 +0800 Subject: [PATCH 5/7] fix(master/server_test): testCase comment --- cmd/dm-ctl/main.go | 1 + dm/master/server_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/dm-ctl/main.go b/cmd/dm-ctl/main.go index 4290174ee9..8efc4d0b75 100644 --- a/cmd/dm-ctl/main.go +++ b/cmd/dm-ctl/main.go @@ -60,6 +60,7 @@ import ( // //Special Commands: // --encrypt encrypt plaintext to ciphertext +// --decrypt decrypt ciphertext to plaintext // //Global Options: // --V prints version and exit diff --git a/dm/master/server_test.go b/dm/master/server_test.go index 812de4c977..71f573f228 100644 --- a/dm/master/server_test.go +++ b/dm/master/server_test.go @@ -350,7 +350,7 @@ func (t *testMaster) TestCheckTask(c *check.C) { c.Assert(resp.Result, check.IsFalse) clearSchedulerEnv(c, cancel, &wg) - // simulate invalid password returned from scheduler, so cfg.SubTaskConfigs will fail + // simulate invalid password returned from scheduler, but config was supported plaintext mysql password, so cfg.SubTaskConfigs will success ctx, cancel = context.WithCancel(context.Background()) server.scheduler, _ = testMockScheduler(ctx, &wg, c, sources, workers, "invalid-encrypt-password", t.workerClients) resp, err = server.CheckTask(context.Background(), &pb.CheckTaskRequest{ From 34778da950603e3ffc670669cede7d6ef31c83eb Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Tue, 19 May 2020 22:33:37 +0800 Subject: [PATCH 6/7] fix(tests): add testcases --- dm/config/source_config_test.go | 8 ++++++++ tests/dm_syncer/conf/source1.toml | 2 +- tests/dmctl_basic/conf/source1.toml | 2 +- tests/dmctl_command/conf/source1.toml | 2 +- tests/dmctl_command/run.sh | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dm/config/source_config_test.go b/dm/config/source_config_test.go index 3d20506385..d2172033bc 100644 --- a/dm/config/source_config_test.go +++ b/dm/config/source_config_test.go @@ -177,6 +177,14 @@ func (t *testConfig) TestConfigVerify(c *C) { }, "", }, + { + func() *SourceConfig { + cfg := newConfig() + cfg.From.Password = "123456" // plaintext password + return cfg + }, + "", + }, } for _, tc := range testCases { diff --git a/tests/dm_syncer/conf/source1.toml b/tests/dm_syncer/conf/source1.toml index e9748fb168..b8ae28a842 100644 --- a/tests/dm_syncer/conf/source1.toml +++ b/tests/dm_syncer/conf/source1.toml @@ -9,5 +9,5 @@ relay-binlog-gtid = "" [from] host = "127.0.0.1" user = "root" -password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs=" +password = "123456" port = 3306 diff --git a/tests/dmctl_basic/conf/source1.toml b/tests/dmctl_basic/conf/source1.toml index 2fa3de8716..6e956ce5e3 100644 --- a/tests/dmctl_basic/conf/source1.toml +++ b/tests/dmctl_basic/conf/source1.toml @@ -10,5 +10,5 @@ enable-relay = true [from] host = "127.0.0.1" user = "root" -password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs=" +password = "123456" port = 3306 diff --git a/tests/dmctl_command/conf/source1.toml b/tests/dmctl_command/conf/source1.toml index 9d4e5d7ac0..513c8c8a55 100644 --- a/tests/dmctl_command/conf/source1.toml +++ b/tests/dmctl_command/conf/source1.toml @@ -9,7 +9,7 @@ relay-binlog-gtid = "" [from] host = "127.0.0.1" user = "root" -password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs=" +password = "123456" port = 3306 [checker] diff --git a/tests/dmctl_command/run.sh b/tests/dmctl_command/run.sh index 3e5aaeb85a..40ecd9b93e 100644 --- a/tests/dmctl_command/run.sh +++ b/tests/dmctl_command/run.sh @@ -6,7 +6,7 @@ cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) source $cur/../_utils/test_prepare WORK_DIR=$TEST_DIR/$TEST_NAME -help_cnt=35 +help_cnt=36 function run() { # check dmctl alone output From bde723bb2c32cce3585e5335c34340426acc61c2 Mon Sep 17 00:00:00 2001 From: Amatist_kurisu Date: Wed, 20 May 2020 14:57:47 +0800 Subject: [PATCH 7/7] fix(descrypt): clean code && add testCase --- dm/config/source_config.go | 24 +++++++----------------- dm/config/source_config_test.go | 17 +++++++++++------ dm/config/subtask.go | 12 +++--------- dm/master/server.go | 10 ++-------- dm/portal/api.go | 23 ++++++----------------- dm/worker/relay.go | 2 +- dm/worker/worker.go | 2 +- pkg/utils/encrypt.go | 6 +++--- 8 files changed, 34 insertions(+), 62 deletions(-) diff --git a/dm/config/source_config.go b/dm/config/source_config.go index f408775621..fd46655194 100644 --- a/dm/config/source_config.go +++ b/dm/config/source_config.go @@ -167,41 +167,31 @@ func (c *SourceConfig) Verify() error { } } - _, err = c.DecryptPassword() - if err != nil { - return err - } + c.DecryptPassword() return nil } // DecryptPassword returns a decrypted config replica in config -func (c *SourceConfig) DecryptPassword() (*SourceConfig, error) { +func (c *SourceConfig) DecryptPassword() *SourceConfig { clone := c.Clone() var ( pswdFrom string - err error ) if len(clone.From.Password) > 0 { - pswdFrom, err = utils.DecryptOrPlaintext(clone.From.Password) - if err != nil { - return nil, terror.WithClass(err, terror.ClassDMWorker) - } + pswdFrom = utils.DecryptOrPlaintext(clone.From.Password) } clone.From.Password = pswdFrom - return clone, nil + return clone } // GenerateDBConfig creates DBConfig for DB -func (c *SourceConfig) GenerateDBConfig() (*DBConfig, error) { +func (c *SourceConfig) GenerateDBConfig() *DBConfig { // decrypt password - clone, err := c.DecryptPassword() - if err != nil { - return nil, err - } + clone := c.DecryptPassword() from := &clone.From from.RawDBCfg = DefaultRawDBConfig().SetReadTimeout(dbReadTimeout) - return from, nil + return from } // Adjust flavor and serverid of SourceConfig diff --git a/dm/config/source_config_test.go b/dm/config/source_config_test.go index d2172033bc..aac284e3ba 100644 --- a/dm/config/source_config_test.go +++ b/dm/config/source_config_test.go @@ -62,17 +62,14 @@ func (t *testConfig) TestConfig(c *C) { // test decrypt password clone1.From.Password = "1234" clone1.ServerID = 101 - clone2, err := cfg.DecryptPassword() - c.Assert(err, IsNil) + clone2 := cfg.DecryptPassword() c.Assert(clone2, DeepEquals, clone1) cfg.From.Password = "xxx" - _, err = cfg.DecryptPassword() - c.Assert(err, IsNil) + cfg.DecryptPassword() cfg.From.Password = "" - clone3, err := cfg.DecryptPassword() - c.Assert(err, IsNil) + clone3 := cfg.DecryptPassword() c.Assert(clone3, DeepEquals, cfg) // test toml and parse again @@ -185,6 +182,14 @@ func (t *testConfig) TestConfigVerify(c *C) { }, "", }, + { + func() *SourceConfig { + cfg := newConfig() + cfg.From.Password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs=" // encrypt password (123456) + return cfg + }, + "", + }, } for _, tc := range testCases { diff --git a/dm/config/subtask.go b/dm/config/subtask.go index 314fef3fe6..f35b7e690f 100644 --- a/dm/config/subtask.go +++ b/dm/config/subtask.go @@ -27,7 +27,7 @@ import ( "github.com/BurntSushi/toml" bf "github.com/pingcap/tidb-tools/pkg/binlog-filter" - column "github.com/pingcap/tidb-tools/pkg/column-mapping" + "github.com/pingcap/tidb-tools/pkg/column-mapping" "github.com/pingcap/tidb-tools/pkg/filter" router "github.com/pingcap/tidb-tools/pkg/table-router" "go.uber.org/zap" @@ -353,16 +353,10 @@ func (c *SubTaskConfig) DecryptPassword() (*SubTaskConfig, error) { pswdFrom string ) if len(clone.To.Password) > 0 { - pswdTo, err = utils.DecryptOrPlaintext(clone.To.Password) - if err != nil { - return nil, terror.WithScope(terror.ErrConfigDecryptDBPassword.Delegate(err, clone.To.Password), terror.ScopeDownstream) - } + pswdTo = utils.DecryptOrPlaintext(clone.To.Password) } if len(clone.From.Password) > 0 { - pswdFrom, err = utils.DecryptOrPlaintext(clone.From.Password) - if err != nil { - return nil, terror.WithScope(terror.ErrConfigDecryptDBPassword.Delegate(err, clone.From.Password), terror.ScopeUpstream) - } + pswdFrom = utils.DecryptOrPlaintext(clone.From.Password) } clone.From.Password = pswdFrom clone.To.Password = pswdTo diff --git a/dm/master/server.go b/dm/master/server.go index e9f4cc58f7..530325edad 100644 --- a/dm/master/server.go +++ b/dm/master/server.go @@ -1150,10 +1150,7 @@ func (s *Server) getSourceConfigs(sources []*config.MySQLInstance) (map[string]c for _, source := range sources { if cfg := s.scheduler.GetSourceCfgByID(source.SourceID); cfg != nil { // check the password - _, err := cfg.DecryptPassword() - if err != nil { - return nil, err - } + cfg.DecryptPassword() cfgs[source.SourceID] = cfg.From } } @@ -1222,10 +1219,7 @@ func parseAndAdjustSourceConfig(cfg *config.SourceConfig, content string) error return err } - dbConfig, err := cfg.GenerateDBConfig() - if err != nil { - return err - } + dbConfig := cfg.GenerateDBConfig() fromDB, err := conn.DefaultDBProvider.Apply(*dbConfig) if err != nil { diff --git a/dm/portal/api.go b/dm/portal/api.go index 1c7ffb8a15..a1e90a0a6b 100644 --- a/dm/portal/api.go +++ b/dm/portal/api.go @@ -17,15 +17,16 @@ import ( // for database _ "github.com/go-sql-driver/mysql" - "github.com/pingcap/dm/dm/config" - "github.com/pingcap/dm/pkg/log" - "github.com/pingcap/dm/pkg/utils" "github.com/pingcap/errors" "github.com/pingcap/tidb-tools/pkg/dbutil" "github.com/pingcap/tidb-tools/pkg/filter" "github.com/unrolled/render" "go.uber.org/zap" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" + + "github.com/pingcap/dm/dm/config" + "github.com/pingcap/dm/pkg/log" + "github.com/pingcap/dm/pkg/utils" ) const ( @@ -341,19 +342,7 @@ func (p *Handler) AnalyzeConfig(w http.ResponseWriter, req *http.Request) { log.L().Info("analyze config", zap.String("config name", cfg.Name)) // decrypt password - dePwd, err := utils.DecryptOrPlaintext(cfg.TargetDB.Password) - log.L().Error("decrypt password failed", zap.Error(err)) - if err != nil { - p.genJSONResp(w, http.StatusBadRequest, AnalyzeResult{ - CommonResult: CommonResult{ - Result: failed, - Error: err.Error(), - }, - Config: DMTaskConfig{}, - }) - return - } - cfg.TargetDB.Password = dePwd + cfg.TargetDB.Password = utils.DecryptOrPlaintext(cfg.TargetDB.Password) p.genJSONResp(w, http.StatusOK, AnalyzeResult{ CommonResult: CommonResult{ diff --git a/dm/worker/relay.go b/dm/worker/relay.go index fdc3ad9b93..01cc047389 100644 --- a/dm/worker/relay.go +++ b/dm/worker/relay.go @@ -82,7 +82,7 @@ type realRelayHolder struct { // NewRealRelayHolder creates a new RelayHolder func NewRealRelayHolder(cfg *config.SourceConfig) RelayHolder { - clone, _ := cfg.DecryptPassword() + clone := cfg.DecryptPassword() relayCfg := &relay.Config{ EnableGTID: clone.EnableGTID, AutoFixGTID: clone.AutoFixGTID, diff --git a/dm/worker/worker.go b/dm/worker/worker.go index 125660a50d..c234ff0296 100644 --- a/dm/worker/worker.go +++ b/dm/worker/worker.go @@ -673,7 +673,7 @@ func (w *Worker) UpdateRelayConfig(ctx context.Context, content string) error { } w.l.Info("update config", zap.Stringer("new config", newCfg)) - cloneCfg, _ := newCfg.DecryptPassword() + cloneCfg := newCfg.DecryptPassword() // Update SubTask configure // NOTE: we only update `DB.Config` in SubTaskConfig now diff --git a/pkg/utils/encrypt.go b/pkg/utils/encrypt.go index cce7bd49f7..8205d7d2b4 100644 --- a/pkg/utils/encrypt.go +++ b/pkg/utils/encrypt.go @@ -45,10 +45,10 @@ func Decrypt(ciphertextB64 string) (string, error) { } // DecryptOrPlaintext tries to decrypt base64 encoded ciphertext to plaintext or return plaintext -func DecryptOrPlaintext(ciphertextB64 string) (string, error) { +func DecryptOrPlaintext(ciphertextB64 string) string { plaintext, err := Decrypt(ciphertextB64) if err != nil { - return ciphertextB64, nil + return ciphertextB64 } - return plaintext, nil + return plaintext }