Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mongo_uri config option #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions backends/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
m.insecureSkipVerify = true
}

addr := fmt.Sprintf("mongodb://%s:%s", m.Host, m.Port)
var addr string

if mongoUri, ok := authOpts["mongo_uri"]; ok {
addr = mongoUri
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some standard validation to run against the uri?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing mongo.Connect method will validate it and return an appropriate error if the URI is bad.

} else {
addr = fmt.Sprintf("mongodb://%s:%s", m.Host, m.Port)
}

to := 60 * time.Second

Expand Down Expand Up @@ -147,7 +153,7 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has

}

//GetUser checks that the username exists and the given password hashes to the same password.
// GetUser checks that the username exists and the given password hashes to the same password.
func (o Mongo) GetUser(username, password, clientid string) (bool, error) {

uc := o.Conn.Database(o.DBName).Collection(o.UsersCollection)
Expand All @@ -173,7 +179,7 @@ func (o Mongo) GetUser(username, password, clientid string) (bool, error) {

}

//GetSuperuser checks that the key username:su exists and has value "true".
// GetSuperuser checks that the key username:su exists and has value "true".
func (o Mongo) GetSuperuser(username string) (bool, error) {

if o.disableSuperuser {
Expand All @@ -199,7 +205,7 @@ func (o Mongo) GetSuperuser(username string) (bool, error) {

}

//CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.
// CheckAcl gets all acls for the username and tries to match against topic, acc, and username/clientid if needed.
func (o Mongo) CheckAcl(username, topic, clientid string, acc int32) (bool, error) {

//Get user and check his acls.
Expand Down Expand Up @@ -255,12 +261,12 @@ func (o Mongo) CheckAcl(username, topic, clientid string, acc int32) (bool, erro

}

//GetName returns the backend's name
// GetName returns the backend's name
func (o Mongo) GetName() string {
return "Mongo"
}

//Halt closes the mongo session.
// Halt closes the mongo session.
func (o Mongo) Halt() {
if o.Conn != nil {
err := o.Conn.Disconnect(context.TODO())
Expand Down
Loading