Skip to content

Commit

Permalink
add missing code for mongodb username/password
Browse files Browse the repository at this point in the history
  • Loading branch information
alexferl committed Sep 24, 2019
1 parent 5fe2cd6 commit 26e150b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backend/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type MongoDBBackend struct {
Uri string
}

func NewMongoDBBackend(uri string, timeout time.Duration) Backend {
func NewMongoDBBackend(uri string, timeout time.Duration, username, password string) Backend {
return Backend(&MongoDBBackend{
Username: username,
Password: password,
Timeout: timeout,
Uri: uri,
})
Expand Down
6 changes: 4 additions & 2 deletions factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ import (

func BackendFactory() backend.Backend {
backendType := viper.GetString("backend-type")
mongoDBUsername := viper.GetString("backend-mongodb-username")
mongoDBPassword := viper.GetString("backend-mongodb-password")
mongoDBTimeout := viper.GetDuration("backend-mongodb-timeout")
mongoDBUri := viper.GetString("backend-mongodb-uri")
logrus.Debugf("Using '%s' backend", backendType)

switch strings.ToLower(backendType) {
case "mongodb":
return backend.NewMongoDBBackend(mongoDBUri, mongoDBTimeout)
return backend.NewMongoDBBackend(mongoDBUri, mongoDBTimeout, mongoDBUsername, mongoDBPassword)
default:
logrus.Warningf("Unknown backend type '%s'. Falling back to 'mongodb'", backendType)
return backend.NewMongoDBBackend(mongoDBUri, mongoDBTimeout)
return backend.NewMongoDBBackend(mongoDBUri, mongoDBTimeout, mongoDBUsername, mongoDBPassword)
}
}

0 comments on commit 26e150b

Please sign in to comment.