diff --git a/.circleci/config.yml b/.circleci/config.yml index 32bfbff..c49b92b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,42 +1,47 @@ version: 2 +references: + objectrocket-docker-auth: &objectrocket-docker-auth + auth: + username: ${DOCKER_USERNAME} + password: ${DOCKER_PASSWORD} + context-to-use: &context-to-use + context: objectrocket-shared jobs: - test: + test-py2: docker: - - image: python:3.5 + - <<: *objectrocket-docker-auth + image: python:2.7 working_directory: ~/python-client steps: - - checkout + - checkout + + - run: + command: pip install --upgrade pip tox + + - run: + command: | + tox -e lint + tox -e py27 - - run: - command: pip install --upgrade pip tox - - - run: - command: | - tox -e lint - tox -e py35 - - pypi_upload: + test-py3: docker: - - image: python:3.5 + - <<: *objectrocket-docker-auth + image: python:3.8 + working_directory: ~/python-client steps: - - checkout + - checkout + + - run: + command: pip install --upgrade pip tox - - run: - command: | - pip install --upgrade pip tox - tox -e build_pypi + - run: + command: | + tox -e lint + tox -e py38 workflows: version: 2 test: jobs: - - test - pypi_upload: - jobs: - - pypi_upload: - filters: - tags: - only: - - /^[0-9]+.[0-9]+.[0-9]+$/ - branches: - ignore: /.*/ \ No newline at end of file + - test-py2: *context-to-use + - test-py3: *context-to-use diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..d93a1a6 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,16 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 30 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: +- security +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false 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/changelog.rst b/changelog.rst index 3d92504..659e3b4 100644 --- a/changelog.rst +++ b/changelog.rst @@ -1,6 +1,10 @@ changelog ========= +0.7.0 +----- +- 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 ebbc17c..5bc9489 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 @@ -59,19 +60,21 @@ 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 # Catch exception here for logging, then just re-raise. @@ -79,12 +82,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 +267,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,8 +275,7 @@ def _get_connection(self, ssl): if ssl and self.ssl_connect_string: connect_string = self.ssl_connect_string - return pymongo.MongoClient(connect_string) - + return pymongo.MongoClient(connect_string, **kwargs) class Shard(bases.Extensible): """An ObjectRocket MongoDB instance shard. diff --git a/requirements/dev.txt b/requirements/dev.txt index 3d0a1c9..9304148 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -10,3 +10,4 @@ tox>=2.1 wheel>=0.22.0 git+https://github.com/mverteuil/pytest-ipdb.git responses>=0.4.0 +twine \ No newline at end of file diff --git a/requirements/prod.txt b/requirements/prod.txt index 2c773fd..df2d34d 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,5 +1,5 @@ elasticsearch>=2.0.0 -pymongo==3.7.2 +pymongo==3.10.1 redis>=2.0 requests>=2.0.0 six<2.0 diff --git a/setup.py b/setup.py index fca9571..43c8764 100755 --- a/setup.py +++ b/setup.py @@ -3,9 +3,8 @@ """Setup script for ObjectRocket Python client.""" from setuptools import find_packages from setuptools import setup +from objectrocket import __version__ -VERSION = ('0', '5', '2') -__version__ = '.'.join(VERSION) with open('README.md') as f: readme = f.read() diff --git a/tox.ini b/tox.ini index eecbff2..9b1df56 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] @@ -13,7 +13,7 @@ recreate = False commands = {envbindir}/py.test --cov objectrocket --cov-report term-missing {toxinidir}/tests [testenv:build_pypi] -deps = twine +deps = -r requirements/dev.txt commands = {envbindir}/python setup.py clean bdist_wheel {toxinidir}/scripts/upload_to_pypi.sh pypi