func (s MysqlService) Bind(serviceInstance string, bindID string, req broker.BindRequest, planConfig config.PlanConfig) (resp broker.BindResponse, err error) { cred := broker.BindCredentials{Host: s.conf.Host, Port: s.conf.Port} // md5Sum := md5.Sum([]byte(bindID)) // cred.Username = fmt.Sprintf("%x", md5Sum[0:8]) //Mysql supports username <= 16 chars. cred.Username = bindID[0:16] //Mysql supports username <= 16 chars. cred.Password = utils.Rand_str(16) cred.Database = serviceInstance cred.Uri = fmt.Sprintf("mysql://%s:%s@%s:%d/%s", cred.Username, cred.Password, cred.Host, cred.Port, cred.Database) resp = broker.BindResponse{Credentials: cred} sql := fmt.Sprintf("CREATE USER '%s'@'%%' IDENTIFIED BY '%s'", cred.Username, cred.Password) _, err = s.db.Exec(sql) if err != nil { return } sql = fmt.Sprintf("GRANT ALL ON `%s`.* TO '%s'@'%%' WITH MAX_USER_CONNECTIONS %d", cred.Database, cred.Username, planConfig.Concurrency) _, err = s.db.Exec(sql) if err != nil { return } _, err = s.db.Exec("FLUSH PRIVILEGES") return return broker.BindResponse{}, nil }
func (s *PostgresService) Bind(serviceInstance string, bindID string, req broker.BindRequest, planConfig config.PlanConfig) (resp broker.BindResponse, err error) { cred := broker.BindCredentials{Host: s.conf.Host, Port: s.conf.Port} cred.Username = bindID cred.Password = utils.Rand_str(16) cred.Database = serviceInstance cred.Uri = fmt.Sprintf("postgres://%s:%s@%s:%d/%s", cred.Username, cred.Password, cred.Host, cred.Port, cred.Database) resp = broker.BindResponse{Credentials: cred} sql := fmt.Sprintf("CREATE USER \"%s\" WITH PASSWORD '%s'", cred.Username, cred.Password) _, err = s.db.Exec(sql) if err != nil { return } sql = fmt.Sprintf("GRANT ALL PRIVILEGES ON DATABASE \"%s\" TO \"%s\"", cred.Database, cred.Username) _, err = s.db.Exec(sql) return }