@@ -90,6 +90,22 @@ def get_client(self) -> Generator["MongoClient", None, None]:
9090 "server_api" : ServerApi (version = SERVER_API_VERSION ),
9191 }
9292 with MongoClient (** client_kwargs ) as client :
93+ # UnsupportedDigestmodError means that SCRAM-SHA-1 is disabled
94+ # It uses md5 which is unavailable on FIPS images
95+ try :
96+ from hashlib import UnsupportedDigestmodError # type: ignore[attr-defined]
97+ except ImportError :
98+ from _hashlib import UnsupportedDigestmodError # type: ignore[attr-defined]
99+
100+ # Check if the authentication mechanism is supported
101+ try :
102+ client .admin .command ("ping" )
103+ except UnsupportedDigestmodError as e :
104+ raise ConnectionError (
105+ "Authentication using SCRAM-SHA-1 is disabled. "
106+ "Use SCRAM-SHA-256 instead. "
107+ "See: https://www.mongodb.com/docs/manual/core/security-scram/"
108+ ) from e
93109 yield client
94110
95111
@@ -117,7 +133,7 @@ def precheck(self) -> None:
117133 database_names = client .list_database_names ()
118134 database_name = self .index_config .database
119135 if database_name not in database_names :
120- raise DestinationConnectionError (
136+ raise SourceConnectionError (
121137 "database {} does not exist: {}" .format (
122138 database_name , ", " .join (database_names )
123139 )
@@ -303,7 +319,7 @@ def precheck(self) -> None:
303319 collection_names = database .list_collection_names ()
304320 collection_name = self .upload_config .collection
305321 if collection_name not in collection_names :
306- raise SourceConnectionError (
322+ raise DestinationConnectionError (
307323 "collection {} does not exist: {}" .format (
308324 collection_name , ", " .join (collection_names )
309325 )
0 commit comments