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-host-prefix-option #340

Open
wants to merge 2 commits 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
13 changes: 12 additions & 1 deletion backends/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

type Mongo struct {
HostPrefix string
Host string
Port string
Username string
Expand Down Expand Up @@ -51,6 +52,7 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
log.SetLevel(logLevel)

var m = Mongo{
HostPrefix: "mongodb",
Host: "localhost",
Port: "27017",
Username: "",
Expand All @@ -68,6 +70,10 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has
m.disableSuperuser = true
}

if prefix, ok := authOpts["mongo_host_prefix"]; ok {
m.HostPrefix = prefix
}

if mongoHost, ok := authOpts["mongo_host"]; ok {
m.Host = mongoHost
}
Expand Down Expand Up @@ -108,7 +114,12 @@ 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 = ""
if m.HostPrefix != "mongodb+srv" {
addr = fmt.Sprintf("%s://%s:%s", m.HostPrefix, m.Host, m.Port)
} else {
addr = fmt.Sprintf("%s://%s", m.HostPrefix, m.Host)
}

to := 60 * time.Second

Expand Down
Loading