From 79937838e7db85dcdea1c00d9279ffe842db2622 Mon Sep 17 00:00:00 2001 From: Freddy Esteban Perez Date: Fri, 21 Aug 2020 21:12:31 -0500 Subject: [PATCH 1/4] wip --- .gitignore | 3 +++ objectrocket/instances/mongodb.py | 22 ++++++++++++++++++---- requirements/prod.txt | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a9823c9..643bcde 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ .cache build dist +.vscode/ +.python-version +.idea/ diff --git a/objectrocket/instances/mongodb.py b/objectrocket/instances/mongodb.py index ebbc17c..30a5871 100644 --- a/objectrocket/instances/mongodb.py +++ b/objectrocket/instances/mongodb.py @@ -8,6 +8,7 @@ import requests from concurrent import futures +from distutils.version import LooseVersion from objectrocket import bases from objectrocket import util @@ -72,6 +73,7 @@ def get_authenticated_connection(self, user, passwd, db='admin', ssl=True): try: connection = self.get_connection(ssl=ssl) connection[db].authenticate(user, passwd) + return connection # Catch exception here for logging, then just re-raise. @@ -79,12 +81,12 @@ def get_authenticated_connection(self, user, passwd, db='admin', ssl=True): logger.exception(ex) raise - def get_connection(self, ssl=True): + def get_connection(self, ssl=True, **kwargs): """Get a live connection to this instance. :param bool ssl: Use SSL/TLS if available for this instance. """ - return self._get_connection(ssl=ssl) + return self._get_connection(ssl=ssl, **kwargs) @util.token_auto_auth def shards(self, add_shard=False): @@ -264,7 +266,7 @@ def set_stepdown_window(self, start, end, enabled=True, scheduled=True, weekly=T ###################### # Private interface. # ###################### - def _get_connection(self, ssl): + def _get_connection(self, ssl, **kwargs): """Get a live connection to this instance.""" # Use SSL/TLS if requested and available. @@ -272,7 +274,19 @@ def _get_connection(self, ssl): if ssl and self.ssl_connect_string: connect_string = self.ssl_connect_string - return pymongo.MongoClient(connect_string) + client = pymongo.MongoClient(connect_string, **kwargs) + + # TODO: question? does python client require to know this? or should kwargs be enough? + # TODO: does python client admin need to know about retryWrites? or passing kwargs be enough? + # retryWrites first released in MongoDB version 3.6+ + # pymongo 3.9+ requires `retryWrites` to be explicitly set for deprecated mmapv1 storage engine + srv_info = connection.server_info() + srv_version = LooseVersion(srv_info["version"]) + if LooseVersion("3.6") <= srv_version < LooseVersion("4.2"): + storage_engine = connection.admin.command("serverStatus")["storageEngine"]["name"] + if storage_engine == "mmapv1": + connection = self.get_connection(ssl=ssl, retryWrites=False) + connection[db].authenticate(user, passwd) class Shard(bases.Extensible): diff --git a/requirements/prod.txt b/requirements/prod.txt index 8d8fe3f..df2d34d 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,5 +1,5 @@ elasticsearch>=2.0.0 -pymongo==3.8.0 +pymongo==3.10.1 redis>=2.0 requests>=2.0.0 six<2.0 From 3cc9d5f702589e595f04fd4ef1bce610423b8ed3 Mon Sep 17 00:00:00 2001 From: Freddy Esteban Perez Date: Sat, 22 Aug 2020 00:48:09 -0500 Subject: [PATCH 2/4] * Changelog update * Update to python 3.8 * Fix doc generation * Add ability to pass additional keyword arguments to client connection --- .circleci/config.yml | 4 ++-- changelog.rst | 4 ++++ docs/source/conf.py | 2 +- objectrocket/__init__.py | 2 ++ objectrocket/instances/mongodb.py | 20 ++++---------------- setup.py | 2 +- tox.ini | 2 +- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ce4cf6b..7cd5897 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,7 +17,7 @@ jobs: test-py3: docker: - - image: python:3.7 + - image: python:3.8 working_directory: ~/python-client steps: - checkout @@ -28,7 +28,7 @@ jobs: - run: command: | tox -e lint - tox -e py37 + tox -e py38 workflows: version: 2 diff --git a/changelog.rst b/changelog.rst index 3d92504..9099385 100644 --- a/changelog.rst +++ b/changelog.rst @@ -1,6 +1,10 @@ changelog ========= +0.7.x +----- +- Add ability to pass additional arguments when retrieving authenticated connection to instance. + 0.4.x ----- - New stats endpoint that provides instance stats (for consumption by newrelic) diff --git a/docs/source/conf.py b/docs/source/conf.py index 240350a..2fce43a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,7 +17,7 @@ import sphinx_rtd_theme -from setup import __version__ +from objectrocket import __version__ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/objectrocket/__init__.py b/objectrocket/__init__.py index 42e9110..ea0905a 100644 --- a/objectrocket/__init__.py +++ b/objectrocket/__init__.py @@ -1,3 +1,5 @@ """Top level package with imported objects for convenience.""" # Import this object for ease of access. from objectrocket.client import Client # noqa + +__version__ = '0.7.0' diff --git a/objectrocket/instances/mongodb.py b/objectrocket/instances/mongodb.py index 30a5871..5bc9489 100644 --- a/objectrocket/instances/mongodb.py +++ b/objectrocket/instances/mongodb.py @@ -60,18 +60,19 @@ def compaction(self, request_compaction=False): return response.json() - def get_authenticated_connection(self, user, passwd, db='admin', ssl=True): + def get_authenticated_connection(self, user, passwd, db='admin', ssl=True, **kwargs): """Get an authenticated connection to this instance. :param str user: The username to use for authentication. :param str passwd: The password to use for authentication. :param str db: The name of the database to authenticate against. Defaults to ``'Admin'``. :param bool ssl: Use SSL/TLS if available for this instance. Defaults to ``True``. + :param kwargs: Additional keyword arguments to pass to MongoClient. :raises: :py:class:`pymongo.errors.OperationFailure` if authentication fails. """ # Attempt to establish an authenticated connection. try: - connection = self.get_connection(ssl=ssl) + connection = self.get_connection(ssl=ssl, **kwargs) connection[db].authenticate(user, passwd) return connection @@ -274,20 +275,7 @@ def _get_connection(self, ssl, **kwargs): if ssl and self.ssl_connect_string: connect_string = self.ssl_connect_string - client = pymongo.MongoClient(connect_string, **kwargs) - - # TODO: question? does python client require to know this? or should kwargs be enough? - # TODO: does python client admin need to know about retryWrites? or passing kwargs be enough? - # retryWrites first released in MongoDB version 3.6+ - # pymongo 3.9+ requires `retryWrites` to be explicitly set for deprecated mmapv1 storage engine - srv_info = connection.server_info() - srv_version = LooseVersion(srv_info["version"]) - if LooseVersion("3.6") <= srv_version < LooseVersion("4.2"): - storage_engine = connection.admin.command("serverStatus")["storageEngine"]["name"] - if storage_engine == "mmapv1": - connection = self.get_connection(ssl=ssl, retryWrites=False) - connection[db].authenticate(user, passwd) - + return pymongo.MongoClient(connect_string, **kwargs) class Shard(bases.Extensible): """An ObjectRocket MongoDB instance shard. diff --git a/setup.py b/setup.py index 2ebfc0f..43c8764 100755 --- a/setup.py +++ b/setup.py @@ -3,8 +3,8 @@ """Setup script for ObjectRocket Python client.""" from setuptools import find_packages from setuptools import setup +from objectrocket import __version__ -__version__ = '0.6.0' with open('README.md') as f: readme = f.read() diff --git a/tox.ini b/tox.ini index eecbff2..49b0655 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 2.1 -envlist = lint,py27,py37 +envlist = lint,py27,py38 skipsdist = True [testenv] From 67a62953f76c11b142403eaedeb2bf1cf34b9655 Mon Sep 17 00:00:00 2001 From: Freddy Esteban Perez Date: Sat, 22 Aug 2020 00:49:19 -0500 Subject: [PATCH 3/4] change to rc tag --- objectrocket/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/objectrocket/__init__.py b/objectrocket/__init__.py index ea0905a..0c23cda 100644 --- a/objectrocket/__init__.py +++ b/objectrocket/__init__.py @@ -2,4 +2,4 @@ # Import this object for ease of access. from objectrocket.client import Client # noqa -__version__ = '0.7.0' +__version__ = '0.7.0rc0' From 7f574d4925c1729ff370160e9c98beb088222ee8 Mon Sep 17 00:00:00 2001 From: Freddy Esteban Perez Date: Tue, 25 Aug 2020 11:12:05 -0500 Subject: [PATCH 4/4] version bump and changelog update --- changelog.rst | 2 +- objectrocket/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.rst b/changelog.rst index 9099385..659e3b4 100644 --- a/changelog.rst +++ b/changelog.rst @@ -1,7 +1,7 @@ changelog ========= -0.7.x +0.7.0 ----- - Add ability to pass additional arguments when retrieving authenticated connection to instance. diff --git a/objectrocket/__init__.py b/objectrocket/__init__.py index 0c23cda..ea0905a 100644 --- a/objectrocket/__init__.py +++ b/objectrocket/__init__.py @@ -2,4 +2,4 @@ # Import this object for ease of access. from objectrocket.client import Client # noqa -__version__ = '0.7.0rc0' +__version__ = '0.7.0'