コード例 #1
0
ファイル: dbconfigs.go プロジェクト: nimishzynga/vitess
// refreshPassword uses the CredentialServer to refresh the password
// to use.
func refreshPassword(params *mysql.ConnectionParams) error {
	user, passwd, err := GetCredentialsServer().GetPassword(params.Uname)
	switch err {
	case nil:
		params.Uname = user
		params.Pass = passwd
	case ErrUnknownUser:
	default:
		return err
	}
	return nil
}
コード例 #2
0
ファイル: vt_binlog_player.go プロジェクト: shrutip/vitess
func createLookupClient(lookupConfigFile, dbCredFile string) (*DBClient, error) {
	lookupConfigData, err := ioutil.ReadFile(lookupConfigFile)
	if err != nil {
		return nil, fmt.Errorf("Error %s in reading lookup-config-file %s", err, lookupConfigFile)
	}

	lookupClient := &DBClient{}
	lookupConfig := new(mysql.ConnectionParams)
	err = json.Unmarshal(lookupConfigData, lookupConfig)
	if err != nil {
		return nil, fmt.Errorf("error in unmarshaling lookupConfig data, err '%v'", err)
	}

	var lookupPasswd string
	if dbCredFile != "" {
		dbCredentials := make(map[string][]string)
		dbCredData, err := ioutil.ReadFile(dbCredFile)
		if err != nil {
			return nil, fmt.Errorf("Error %s in reading db-credentials-file %s", err, dbCredFile)
		}
		err = json.Unmarshal(dbCredData, &dbCredentials)
		if err != nil {
			return nil, fmt.Errorf("Error in unmarshaling db-credentials-file %s", err)
		}
		if passwd, ok := dbCredentials[lookupConfig.Uname]; ok {
			lookupPasswd = passwd[0]
		}
	}

	lookupConfig.Pass = lookupPasswd
	relog.Info("lookupConfig %v", lookupConfig)
	lookupClient.dbConfig = lookupConfig

	lookupClient.dbConn, err = lookupClient.Connect()
	if err != nil {
		return nil, fmt.Errorf("error in connecting to mysql db, err %v", err)
	}
	return lookupClient, nil
}