Skip to content

Commit a5f1508

Browse files
authored
Merge pull request #2690 from bagerard/mcsheehan-2507-support-mongodb-aws
#2507 support mongodb aws
2 parents 51afeca + 0fdd743 commit a5f1508

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
fail_fast: false
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.1.0
4+
rev: v4.3.0
55
hooks:
66
- id: check-merge-conflict
77
- id: debug-statements
88
- id: trailing-whitespace
99
- id: end-of-file-fixer
1010
- repo: https://github.com/ambv/black
11-
rev: 22.3.0
11+
rev: 22.8.0
1212
hooks:
1313
- id: black
1414
- repo: https://gitlab.com/pycqa/flake8
1515
rev: 3.9.2
1616
hooks:
1717
- id: flake8
1818
- repo: https://github.com/asottile/pyupgrade
19-
rev: v2.31.1
19+
rev: v2.37.3
2020
hooks:
2121
- id: pyupgrade
2222
args: [--py36-plus]

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changelog
77
Development
88
===========
99
- (Fill this out as you fix issues and develop your features).
10+
- Support MONGODB-AWS authentication mechanism (with `authmechanismproperties`) #2507
1011
- Turning off dereferencing for the results of distinct query. #2663
1112

1213
Changes in 0.24.2

mongoengine/connection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def _get_connection_settings(
5858
password=None,
5959
authentication_source=None,
6060
authentication_mechanism=None,
61+
authmechanismproperties=None,
6162
**kwargs,
6263
):
6364
"""Get the connection settings as a dict
@@ -88,6 +89,7 @@ def _get_connection_settings(
8889
"password": password,
8990
"authentication_source": authentication_source,
9091
"authentication_mechanism": authentication_mechanism,
92+
"authmechanismproperties": authmechanismproperties,
9193
}
9294

9395
_check_db_name(conn_settings["name"])
@@ -158,6 +160,10 @@ def _get_connection_settings(
158160
):
159161
conn_settings["read_preference"] = preference
160162
break
163+
if "authmechanismproperties" in uri_options:
164+
conn_settings["authmechanismproperties"] = uri_options[
165+
"authmechanismproperties"
166+
]
161167
else:
162168
resolved_hosts.append(entity)
163169
conn_settings["host"] = resolved_hosts
@@ -196,6 +202,7 @@ def register_connection(
196202
password=None,
197203
authentication_source=None,
198204
authentication_mechanism=None,
205+
authmechanismproperties=None,
199206
**kwargs,
200207
):
201208
"""Register the connection settings.
@@ -228,6 +235,7 @@ def register_connection(
228235
password=password,
229236
authentication_source=authentication_source,
230237
authentication_mechanism=authentication_mechanism,
238+
authmechanismproperties=authmechanismproperties,
231239
**kwargs,
232240
)
233241
_connection_settings[alias] = conn_settings
@@ -289,6 +297,7 @@ def _clean_settings(settings_dict):
289297
"password",
290298
"authentication_source",
291299
"authentication_mechanism",
300+
"authmechanismproperties",
292301
}
293302
rename_fields = {}
294303
else:
@@ -388,6 +397,7 @@ def get_db(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
388397
conn_settings["password"]
389398
or conn_settings["authentication_mechanism"] == "MONGODB-X509"
390399
)
400+
and conn_settings["authmechanismproperties"] is None
391401
):
392402
auth_kwargs = {"source": conn_settings["authentication_source"]}
393403
if conn_settings["authentication_mechanism"] is not None:

tests/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_uri_without_credentials_doesnt_override_conn_settings(self):
418418
db.list_collection_names()
419419
else:
420420
with pytest.raises(OperationFailure):
421-
db = get_db()
421+
get_db()
422422

423423
def test_connect_uri_with_authsource(self):
424424
"""Ensure that the connect() method works well with `authSource`

0 commit comments

Comments
 (0)