Skip to content

Commit

Permalink
Merge pull request #2690 from bagerard/mcsheehan-2507-support-mongodb…
Browse files Browse the repository at this point in the history
…-aws

#2507 support mongodb aws
  • Loading branch information
bagerard committed Sep 6, 2022
2 parents 51afeca + 0fdd743 commit a5f1508
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 22.8.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
Development
===========
- (Fill this out as you fix issues and develop your features).
- Support MONGODB-AWS authentication mechanism (with `authmechanismproperties`) #2507
- Turning off dereferencing for the results of distinct query. #2663

Changes in 0.24.2
Expand Down
10 changes: 10 additions & 0 deletions mongoengine/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _get_connection_settings(
password=None,
authentication_source=None,
authentication_mechanism=None,
authmechanismproperties=None,
**kwargs,
):
"""Get the connection settings as a dict
Expand Down Expand Up @@ -88,6 +89,7 @@ def _get_connection_settings(
"password": password,
"authentication_source": authentication_source,
"authentication_mechanism": authentication_mechanism,
"authmechanismproperties": authmechanismproperties,
}

_check_db_name(conn_settings["name"])
Expand Down Expand Up @@ -158,6 +160,10 @@ def _get_connection_settings(
):
conn_settings["read_preference"] = preference
break
if "authmechanismproperties" in uri_options:
conn_settings["authmechanismproperties"] = uri_options[
"authmechanismproperties"
]
else:
resolved_hosts.append(entity)
conn_settings["host"] = resolved_hosts
Expand Down Expand Up @@ -196,6 +202,7 @@ def register_connection(
password=None,
authentication_source=None,
authentication_mechanism=None,
authmechanismproperties=None,
**kwargs,
):
"""Register the connection settings.
Expand Down Expand Up @@ -228,6 +235,7 @@ def register_connection(
password=password,
authentication_source=authentication_source,
authentication_mechanism=authentication_mechanism,
authmechanismproperties=authmechanismproperties,
**kwargs,
)
_connection_settings[alias] = conn_settings
Expand Down Expand Up @@ -289,6 +297,7 @@ def _clean_settings(settings_dict):
"password",
"authentication_source",
"authentication_mechanism",
"authmechanismproperties",
}
rename_fields = {}
else:
Expand Down Expand Up @@ -388,6 +397,7 @@ def get_db(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
conn_settings["password"]
or conn_settings["authentication_mechanism"] == "MONGODB-X509"
)
and conn_settings["authmechanismproperties"] is None
):
auth_kwargs = {"source": conn_settings["authentication_source"]}
if conn_settings["authentication_mechanism"] is not None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def test_uri_without_credentials_doesnt_override_conn_settings(self):
db.list_collection_names()
else:
with pytest.raises(OperationFailure):
db = get_db()
get_db()

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

0 comments on commit a5f1508

Please sign in to comment.