Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

test-py3:
docker:
- image: python:3.7
- image: python:3.8
working_directory: ~/python-client
steps:
- checkout
Expand All @@ -28,7 +28,7 @@ jobs:
- run:
command: |
tox -e lint
tox -e py37
tox -e py38

workflows:
version: 2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
.cache
build
dist
.vscode/
.python-version
.idea/
4 changes: 4 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions objectrocket/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 9 additions & 7 deletions objectrocket/instances/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests

from concurrent import futures
from distutils.version import LooseVersion

from objectrocket import bases
from objectrocket import util
Expand Down Expand Up @@ -59,32 +60,34 @@ 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.
except pymongo.errors.OperationFailure as ex:
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):
Expand Down Expand Up @@ -264,16 +267,15 @@ 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.
connect_string = self.connect_string
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.
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 2.1
envlist = lint,py27,py37
envlist = lint,py27,py38
skipsdist = True

[testenv]
Expand Down