From 61a64ad98c4ae09c60f84ff058826677b6108989 Mon Sep 17 00:00:00 2001 From: Jacob Lerche Date: Tue, 17 Dec 2019 10:06:04 -0800 Subject: [PATCH] Add password as command line argument (#253) * Add password as command line argument * Adds -tidb-pwd to config tests * Changes tidb-pwd to tidb-password cli flag --- lightning/config/config.go | 1 + lightning/config/config_test.go | 4 +++- lightning/config/global.go | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lightning/config/config.go b/lightning/config/config.go index 181367609..48bf73bd3 100644 --- a/lightning/config/config.go +++ b/lightning/config/config.go @@ -222,6 +222,7 @@ func (cfg *Config) LoadFromGlobal(global *GlobalConfig) error { cfg.TiDB.Host = global.TiDB.Host cfg.TiDB.Port = global.TiDB.Port cfg.TiDB.User = global.TiDB.User + cfg.TiDB.Psw = global.TiDB.Psw cfg.TiDB.StatusPort = global.TiDB.StatusPort cfg.TiDB.PdAddr = global.TiDB.PdAddr cfg.Mydumper.SourceDir = global.Mydumper.SourceDir diff --git a/lightning/config/config_test.go b/lightning/config/config_test.go index 3c69357e2..b145a7eb2 100644 --- a/lightning/config/config_test.go +++ b/lightning/config/config_test.go @@ -369,6 +369,7 @@ func (s *configTestSuite) TestLoadConfig(c *C) { "-tidb-host", "172.16.30.11", "-tidb-port", "4001", "-tidb-user", "guest", + "-tidb-password", "12345", "-pd-urls", "172.16.30.11:2379,172.16.30.12:2379", "-d", "/path/to/import", "-importer", "172.16.30.11:23008", @@ -379,6 +380,7 @@ func (s *configTestSuite) TestLoadConfig(c *C) { c.Assert(cfg.TiDB.Host, Equals, "172.16.30.11") c.Assert(cfg.TiDB.Port, Equals, 4001) c.Assert(cfg.TiDB.User, Equals, "guest") + c.Assert(cfg.TiDB.Psw, Equals, "12345") c.Assert(cfg.TiDB.PdAddr, Equals, "172.16.30.11:2379,172.16.30.12:2379") c.Assert(cfg.Mydumper.SourceDir, Equals, "/path/to/import") c.Assert(cfg.TikvImporter.Addr, Equals, "172.16.30.11:23008") @@ -391,7 +393,7 @@ func (s *configTestSuite) TestLoadConfig(c *C) { taskCfg.Checkpoint.Driver = config.CheckpointDriverMySQL err = taskCfg.Adjust() c.Assert(err, IsNil) - c.Assert(taskCfg.Checkpoint.DSN, Equals, "guest:@tcp(172.16.30.11:4001)/?charset=utf8&sql_mode='"+mysql.DefaultSQLMode+"'&maxAllowedPacket=67108864") + c.Assert(taskCfg.Checkpoint.DSN, Equals, "guest:12345@tcp(172.16.30.11:4001)/?charset=utf8&sql_mode='"+mysql.DefaultSQLMode+"'&maxAllowedPacket=67108864") result := taskCfg.String() c.Assert(result, Matches, `.*"pd-addr":"172.16.30.11:2379,172.16.30.12:2379".*`) diff --git a/lightning/config/global.go b/lightning/config/global.go index 1cec78cd6..4600510bf 100644 --- a/lightning/config/global.go +++ b/lightning/config/global.go @@ -39,6 +39,7 @@ type GlobalTiDB struct { Host string `toml:"host" json:"host"` Port int `toml:"port" json:"port"` User string `toml:"user" json:"user"` + Psw string `toml:"password" json:"-"` StatusPort int `toml:"status-port" json:"status-port"` PdAddr string `toml:"pd-addr" json:"pd-addr"` LogLevel string `toml:"log-level" json:"log-level"` @@ -111,6 +112,7 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon tidbHost := fs.String("tidb-host", "", "TiDB server host") tidbPort := fs.Int("tidb-port", 0, "TiDB server port (default 4000)") tidbUser := fs.String("tidb-user", "", "TiDB user name to connect") + tidbPsw := fs.String("tidb-password", "", "TiDB password to connect") tidbStatusPort := fs.Int("tidb-status", 0, "TiDB server status port (default 10080)") pdAddr := fs.String("pd-urls", "", "PD endpoint address") dataSrcPath := fs.String("d", "", "Directory of the dump to import") @@ -161,6 +163,9 @@ func LoadGlobalConfig(args []string, extraFlags func(*flag.FlagSet)) (*GlobalCon if *tidbUser != "" { cfg.TiDB.User = *tidbUser } + if *tidbPsw != "" { + cfg.TiDB.Psw = *tidbPsw + } if *pdAddr != "" { cfg.TiDB.PdAddr = *pdAddr }