drop User Password Auth, only url and dbname

This commit is contained in:
Pasha 2024-11-28 19:03:11 +03:00
parent 3ec559676d
commit 763b6a0f63
3 changed files with 2 additions and 17 deletions

@ -8,9 +8,6 @@ import (
type Configuration struct { type Configuration struct {
URL string `env:"MONGO_URL,required"` URL string `env:"MONGO_URL,required"`
User string `env:"MONGO_USER,required"`
Password string `env:"MONGO_PASSWORD,required"`
Auth string `env:"MONGO_AUTH,required"`
DatabaseName string `env:"MONGO_DB_NAME,required"` DatabaseName string `env:"MONGO_DB_NAME,required"`
} }

@ -40,13 +40,7 @@ func Connect(ctx context.Context, deps *ConnectDeps) (*mongo.Database, error) {
} }
connectionOptions := options.Client(). connectionOptions := options.Client().
ApplyURI(deps.Configuration.URL). ApplyURI(deps.Configuration.URL).SetMonitor(cmdMonitor)
SetAuth(options.Credential{
AuthMechanism: "SCRAM-SHA-1",
AuthSource: deps.Configuration.Auth,
Username: deps.Configuration.User,
Password: deps.Configuration.Password,
}).SetMonitor(cmdMonitor)
ticker := time.NewTicker(1 * time.Second) ticker := time.NewTicker(1 * time.Second)
timeoutExceeded := time.After(deps.Timeout) timeoutExceeded := time.After(deps.Timeout)

@ -13,9 +13,6 @@ func TestConnectMongo(t *testing.T) {
d, err := Connect(ctx, &ConnectDeps{ d, err := Connect(ctx, &ConnectDeps{
Configuration: &Configuration{ Configuration: &Configuration{
URL: "mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0&readPreference=primary&ssl=false", URL: "mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0&readPreference=primary&ssl=false",
User: "test",
Password: "test",
Auth: "admin",
DatabaseName: "test_replicaset", DatabaseName: "test_replicaset",
}, },
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
@ -25,10 +22,7 @@ func TestConnectMongo(t *testing.T) {
d2, err := Connect(ctx, &ConnectDeps{ d2, err := Connect(ctx, &ConnectDeps{
Configuration: &Configuration{ Configuration: &Configuration{
URL: "mongodb://localhost:27020/", URL: "mongodb://test:test@localhost:27020/",
User: "test",
Password: "test",
Auth: "admin",
DatabaseName: "test_default", DatabaseName: "test_default",
}, },
Timeout: 10 * time.Second, Timeout: 10 * time.Second,