Merge pull request #536 from github/go-mysql-ignore-pass

go-mysql library to avoid printing password in cleartext
This commit is contained in:
Shlomi Noach 2018-01-15 10:57:24 +02:00 committed by GitHub
commit ce4e42da32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 25 deletions

View File

@ -39,7 +39,7 @@ func NewGoMySQLReader(migrationContext *base.MigrationContext) (binlogReader *Go
serverId := uint32(migrationContext.ReplicaServerId) serverId := uint32(migrationContext.ReplicaServerId)
binlogSyncerConfig := &replication.BinlogSyncerConfig{ binlogSyncerConfig := replication.BinlogSyncerConfig{
ServerID: serverId, ServerID: serverId,
Flavor: "mysql", Flavor: "mysql",
Host: binlogReader.connectionConfig.Key.Hostname, Host: binlogReader.connectionConfig.Key.Hostname,

View File

@ -25,7 +25,7 @@ cfg := replication.BinlogSyncerConfig {
User: "root", User: "root",
Password: "", Password: "",
} }
syncer := replication.NewBinlogSyncer(&cfg) syncer := replication.NewBinlogSyncer(cfg)
// Start sync with sepcified binlog file and position // Start sync with sepcified binlog file and position
streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos}) streamer, _ := syncer.StartSync(mysql.Position{binlogFile, binlogPos})

View File

@ -265,7 +265,7 @@ func (c *Canal) prepareSyncer() error {
Password: c.cfg.Password, Password: c.cfg.Password,
} }
c.syncer = replication.NewBinlogSyncer(&cfg) c.syncer = replication.NewBinlogSyncer(cfg)
return nil return nil
} }

View File

@ -45,7 +45,7 @@ func main() {
SemiSyncEnabled: *semiSync, SemiSyncEnabled: *semiSync,
} }
b := replication.NewBinlogSyncer(&cfg) b := replication.NewBinlogSyncer(cfg)
pos := mysql.Position{*file, uint32(*pos)} pos := mysql.Position{*file, uint32(*pos)}
if len(*backupPath) > 0 { if len(*backupPath) > 0 {

View File

@ -54,7 +54,7 @@ type BinlogSyncerConfig struct {
type BinlogSyncer struct { type BinlogSyncer struct {
m sync.RWMutex m sync.RWMutex
cfg *BinlogSyncerConfig cfg BinlogSyncerConfig
c *client.Conn c *client.Conn
@ -71,8 +71,13 @@ type BinlogSyncer struct {
} }
// NewBinlogSyncer creates the BinlogSyncer with cfg. // NewBinlogSyncer creates the BinlogSyncer with cfg.
func NewBinlogSyncer(cfg *BinlogSyncerConfig) *BinlogSyncer { func NewBinlogSyncer(cfg BinlogSyncerConfig) *BinlogSyncer {
// Clear the Password to avoid outputing it in log.
pass := cfg.Password
cfg.Password = ""
log.Infof("create BinlogSyncer with config %v", cfg) log.Infof("create BinlogSyncer with config %v", cfg)
cfg.Password = pass
b := new(BinlogSyncer) b := new(BinlogSyncer)

View File

@ -271,7 +271,7 @@ func (t *testSyncerSuite) setupTest(c *C, flavor string) {
Password: "", Password: "",
} }
t.b = NewBinlogSyncer(&cfg) t.b = NewBinlogSyncer(cfg)
} }
func (t *testSyncerSuite) testPositionSync(c *C) { func (t *testSyncerSuite) testPositionSync(c *C) {