From 7b590a230ad21c3392999cc991bdd2cefd4b5fb6 Mon Sep 17 00:00:00 2001 From: Joachim Danmayr <46405460+joda01@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:59:58 +0200 Subject: [PATCH 1/2] add-host-prefix-option Allow to configure the host prefix. This allows to use mongodb and mongodb-srv --- backends/mongo.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backends/mongo.go b/backends/mongo.go index cc1f99a8..420ad68e 100644 --- a/backends/mongo.go +++ b/backends/mongo.go @@ -18,6 +18,7 @@ import ( ) type Mongo struct { + HostPrefix string Host string Port string Username string @@ -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: "", @@ -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 } @@ -108,7 +114,7 @@ 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) + addr := fmt.Sprintf("%s://%s:%s", m.HostPrefix, m.Host, m.Port) to := 60 * time.Second From a6a7f6c747f5361cda38e04e6016f7fe9bb48a23 Mon Sep 17 00:00:00 2001 From: Joachim Danmayr <46405460+joda01@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:40:41 +0200 Subject: [PATCH 2/2] chore: If url is +srv no port is allowed --- backends/mongo.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backends/mongo.go b/backends/mongo.go index 420ad68e..4e941976 100644 --- a/backends/mongo.go +++ b/backends/mongo.go @@ -114,7 +114,12 @@ func NewMongo(authOpts map[string]string, logLevel log.Level, hasher hashing.Has m.insecureSkipVerify = true } - addr := fmt.Sprintf("%s://%s:%s", m.HostPrefix, 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