Skip to content

Commit ef33ddf

Browse files
authored
feat: improve mongodb SCRAM-SHA-1 auth error msg (#549)
1 parent 4dda928 commit ef33ddf

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.49
2+
3+
* **Improve MongoDB SCRAM-SHA-1 authentication error message**
4+
15
## 1.0.48
26

37
* **Improve Jira attachment path results**

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.48" # pragma: no cover
1+
__version__ = "1.0.49" # pragma: no cover

unstructured_ingest/processes/connectors/mongodb.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)