From 4c6f42f2f1dd94592418c088d13ca3af4eb10166 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 20 Dec 2016 22:14:17 +0200 Subject: [PATCH] passwords not exported in MigrationContext --- go/base/context.go | 20 ++++++++++++++++---- go/cmd/gh-ost/main.go | 10 ++++++---- go/logic/migrator.go | 4 ++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/go/base/context.go b/go/base/context.go index 0df0f83..a6944c6 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -87,9 +87,9 @@ type MigrationContext struct { configMutex *sync.Mutex ConfigFile string CliUser string - CliPassword string + cliPassword string CliMasterUser string - CliMasterPassword string + cliMasterPassword string HeartbeatIntervalMilliseconds int64 defaultNumRetries int64 @@ -629,6 +629,18 @@ func (this *MigrationContext) AddThrottleControlReplicaKey(key mysql.InstanceKey return nil } +func (this *MigrationContext) SetCliPassword(password string) { + this.cliPassword = password +} + +func (this *MigrationContext) SetCliMasterPassword(password string) { + this.cliMasterPassword = password +} + +func (this *MigrationContext) GetCliMasterPassword() string { + return this.cliMasterPassword +} + // ApplyCredentials sorts out the credentials between the config file and the CLI flags func (this *MigrationContext) ApplyCredentials() { this.configMutex.Lock() @@ -644,9 +656,9 @@ func (this *MigrationContext) ApplyCredentials() { if this.config.Client.Password != "" { this.InspectorConnectionConfig.Password = this.config.Client.Password } - if this.CliPassword != "" { + if this.cliPassword != "" { // Override - this.InspectorConnectionConfig.Password = this.CliPassword + this.InspectorConnectionConfig.Password = this.cliPassword } } diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index bb8b8d2..f4e75c1 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -49,9 +49,9 @@ func main() { flag.StringVar(&migrationContext.AssumeMasterHostname, "assume-master-host", "", "(optional) explicitly tell gh-ost the identity of the master. Format: some.host.com[:port] This is useful in master-master setups where you wish to pick an explicit master, or in a tungsten-replicator where gh-ost is unabel to determine the master") flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)") flag.StringVar(&migrationContext.CliUser, "user", "", "MySQL user") - flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password") + cliPassword := flag.String("password", "", "MySQL password") flag.StringVar(&migrationContext.CliMasterUser, "master-user", "", "MySQL user on master, if different from that on replica. Requires --assume-master-host") - flag.StringVar(&migrationContext.CliMasterPassword, "master-password", "", "MySQL password on master, if different from that on replica. Requires --assume-master-host") + cliMasterPassword := flag.String("master-password", "", "MySQL password on master, if different from that on replica. Requires --assume-master-host") flag.StringVar(&migrationContext.ConfigFile, "conf", "", "Config file") askPass := flag.Bool("ask-pass", false, "prompt for MySQL password") @@ -175,7 +175,7 @@ func main() { if migrationContext.CliMasterUser != "" && migrationContext.AssumeMasterHostname == "" { log.Fatalf("--master-user requires --assume-master-host") } - if migrationContext.CliMasterPassword != "" && migrationContext.AssumeMasterHostname == "" { + if *cliMasterPassword != "" && migrationContext.AssumeMasterHostname == "" { log.Fatalf("--master-password requires --assume-master-host") } @@ -202,13 +202,15 @@ func main() { if migrationContext.ServeSocketFile == "" { migrationContext.ServeSocketFile = fmt.Sprintf("/tmp/gh-ost.%s.%s.sock", migrationContext.DatabaseName, migrationContext.OriginalTableName) } + migrationContext.SetCliPassword(*cliPassword) + migrationContext.SetCliMasterPassword(*cliMasterPassword) if *askPass { fmt.Println("Password:") bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { log.Fatale(err) } - migrationContext.CliPassword = string(bytePassword) + migrationContext.SetCliPassword(string(bytePassword)) } migrationContext.SetHeartbeatIntervalMilliseconds(*heartbeatIntervalMillis) migrationContext.SetNiceRatio(*niceRatio) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 69f6da4..b5fc76c 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -663,8 +663,8 @@ func (this *Migrator) initiateInspector() (err error) { if this.migrationContext.CliMasterUser != "" { this.migrationContext.ApplierConnectionConfig.User = this.migrationContext.CliMasterUser } - if this.migrationContext.CliMasterPassword != "" { - this.migrationContext.ApplierConnectionConfig.Password = this.migrationContext.CliMasterPassword + if this.migrationContext.GetCliMasterPassword() != "" { + this.migrationContext.ApplierConnectionConfig.Password = this.migrationContext.GetCliMasterPassword() } log.Infof("Master forced to be %+v", *this.migrationContext.ApplierConnectionConfig.ImpliedKey) }