Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
Add password as command line argument (#253)
Browse files Browse the repository at this point in the history
* Add password as command line argument

* Adds -tidb-pwd to config tests

* Changes tidb-pwd to tidb-password cli flag
  • Loading branch information
Jacob Lerche authored and gregwebs committed Dec 17, 2019
1 parent 99e1ed0 commit 61a64ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions lightning/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lightning/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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".*`)
Expand Down
5 changes: 5 additions & 0 deletions lightning/config/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 61a64ad

Please sign in to comment.