Skip to content

Commit

Permalink
Include replSetName in connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
ultragtx committed May 23, 2017
1 parent b605300 commit bcc21ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
13 changes: 11 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type Config struct {
}

type MongoConfig struct {
Nodes MongoNodes `yaml:"nodes"`
RootUser MongoRootUser `yaml:"root"`
Nodes MongoNodes `yaml:"nodes"`
RootUser MongoRootUser `yaml:"root"`
MongoReplicaSet MongoReplicaSet `yaml:"replSet"`
}

type MongoRootUser struct {
Expand All @@ -31,6 +32,10 @@ type MongoNodes struct {
Port string `yaml:"port"`
}

type MongoReplicaSet struct {
name string `yaml:"name"`
}

type BrokerConfig struct {
Host string `yaml:"host"`
BrokerUsername string `yaml:"security_user_name"`
Expand Down Expand Up @@ -107,6 +112,10 @@ func (config *Config) MongoPassword() string {
return config.MongoConfig.RootUser.Password
}

func (config *Config) ReplSetName() string {
return config.MongoConfig.MongoReplicaSet.name
}

func (config *Config) Services() []brokerapi.Service {
planList := []brokerapi.ServicePlan{}
for _, plan := range config.Plans() {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
}

//adminService, err := mongo.NewAdminService("172.16.0.156", "rootusername", "rootpassword", "admin")
adminService, err := mongo.NewAdminService(config.MongoHosts(), config.MongoUsername(), config.MongoPassword(), "admin")
adminService, err := mongo.NewAdminService(config.MongoHosts(), config.MongoUsername(), config.MongoPassword(), config.ReplSetName(), "admin")

if err != nil {
brokerLogger.Fatal("mongo-admin-service", err)
Expand Down
26 changes: 14 additions & 12 deletions mongo/admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ const (
)

type AdminService struct {
hosts string
username string
password string
authSource string
hosts string
username string
password string
replSetName string
authSource string

addresses []string

dialInfo *mgo.DialInfo
}

func NewAdminService(hosts, username, password, authSource string) (*AdminService, error) {
func NewAdminService(hosts, username, password, replSetName, authSource string) (*AdminService, error) {
if logEnabled {
logger := log.New(os.Stdout, "mongo-broker-mongo:", 0)
mgo.SetDebug(true)
Expand All @@ -55,12 +56,13 @@ func NewAdminService(hosts, username, password, authSource string) (*AdminServic
}

adminService := &AdminService{
hosts: hosts,
username: username,
password: password,
authSource: authSource,
addresses: addresses,
dialInfo: dialInfo,
hosts: hosts,
username: username,
password: password,
replSetName: replSetName,
authSource: authSource,
addresses: addresses,
dialInfo: dialInfo,
}

return adminService, nil
Expand Down Expand Up @@ -263,7 +265,7 @@ func (adminService *AdminService) DeleteUser(databaseName, username string) erro
}

func (adminService *AdminService) GetConnectionString(databaseName, username, password string) string {
parts := []string{"mongodb://", username, ":", password, "@", adminService.GetServerAddresses(), "/", databaseName}
parts := []string{"mongodb://", username, ":", password, "@", adminService.GetServerAddresses(), "/", databaseName, "?replicaSet=", adminService.replSetName}
return strings.Join(parts, "")
}

Expand Down

0 comments on commit bcc21ad

Please sign in to comment.