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

Add password as command line argument #253

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more familiar with "Pwd" as an abbreviation, but do we need to abbreviate this at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Psw to mimic the field name in the config

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you mean by "mimic the field name in the config"? There is no Psw field in the configuration file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field can be named "Psw" for consistency with old code (or all renamed to "Password"), but the CLI argument should be named -tidb-password not -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