From 6d7a070657bed98a4501a37b2adcc0ba756966c7 Mon Sep 17 00:00:00 2001 From: Damien Degois Date: Thu, 21 Dec 2023 09:57:19 +0100 Subject: [PATCH] Adapt auth, authenticate on db fails --- salt/modules/mongodb.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/salt/modules/mongodb.py b/salt/modules/mongodb.py index a0b34c79714..91eee1ce98f 100644 --- a/salt/modules/mongodb.py +++ b/salt/modules/mongodb.py @@ -71,7 +71,9 @@ def _connect( If connection fails for any reason, log error and return False. """ + verify_ssl = True if verify_ssl is None else verify_ssl + if not user: user = __salt__["config.option"]("mongodb.user") if not password: @@ -87,13 +89,13 @@ def _connect( conn = pymongo.MongoClient( host=host, port=port, + username=user, + password=password, + authSource=authdb, ssl=bool(ssl), tlsAllowInvalidCertificates=not verify_ssl, ) - mdb = pymongo.database.Database(conn, database) - if user and password: - mdb.authenticate(user, password, source=authdb) - except pymongo.errors.PyMongoError as e: + except pymongo.errors.PyMongoError: log.error("Error connecting to database %s", database) return False