|
@@ -11,6 +11,7 @@ from __future__ import absolute_import
|
|
import sys
|
|
import sys
|
|
try: # pragma: no cover
|
|
try: # pragma: no cover
|
|
import cassandra
|
|
import cassandra
|
|
|
|
+ import cassandra.auth
|
|
import cassandra.cluster
|
|
import cassandra.cluster
|
|
except ImportError: # pragma: no cover
|
|
except ImportError: # pragma: no cover
|
|
cassandra = None # noqa
|
|
cassandra = None # noqa
|
|
@@ -29,6 +30,11 @@ You need to install the cassandra-driver library to
|
|
use the Cassandra backend. See https://github.com/datastax/python-driver
|
|
use the Cassandra backend. See https://github.com/datastax/python-driver
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+E_NO_SUCH_CASSANDRA_AUTH_PROVIDER = """
|
|
|
|
+CASSANDRA_AUTH_PROVIDER you provided is not a valid auth_provider class.
|
|
|
|
+See https://datastax.github.io/python-driver/api/cassandra/auth.html.
|
|
|
|
+"""
|
|
|
|
+
|
|
Q_INSERT_RESULT = """
|
|
Q_INSERT_RESULT = """
|
|
INSERT INTO {table} (
|
|
INSERT INTO {table} (
|
|
task_id, status, result, date_done, traceback, children) VALUES (
|
|
task_id, status, result, date_done, traceback, children) VALUES (
|
|
@@ -121,6 +127,15 @@ class CassandraBackend(BaseBackend):
|
|
cassandra.ConsistencyLevel.LOCAL_QUORUM,
|
|
cassandra.ConsistencyLevel.LOCAL_QUORUM,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ self.auth_provider = None
|
|
|
|
+ auth_provider = conf.get('cassandra_auth_provider', None)
|
|
|
|
+ auth_kwargs = conf.get('cassandra_auth_kwargs', None)
|
|
|
|
+ if auth_provider and auth_kwargs:
|
|
|
|
+ auth_provider_class = getattr(cassandra.auth, auth_provider, None)
|
|
|
|
+ if not auth_provider_class:
|
|
|
|
+ raise ImproperlyConfigured(E_NO_SUCH_CASSANDRA_AUTH_PROVIDER)
|
|
|
|
+ self.auth_provider = auth_provider_class(**auth_kwargs)
|
|
|
|
+
|
|
self._connection = None
|
|
self._connection = None
|
|
self._session = None
|
|
self._session = None
|
|
self._write_stmt = None
|
|
self._write_stmt = None
|
|
@@ -142,8 +157,9 @@ class CassandraBackend(BaseBackend):
|
|
"""
|
|
"""
|
|
if self._connection is None:
|
|
if self._connection is None:
|
|
try:
|
|
try:
|
|
- self._connection = cassandra.cluster.Cluster(self.servers,
|
|
|
|
- port=self.port)
|
|
|
|
|
|
+ self._connection = cassandra.cluster.Cluster(
|
|
|
|
+ self.servers, port=self.port,
|
|
|
|
+ auth_provider=self.auth_provider)
|
|
self._session = self._connection.connect(self.keyspace)
|
|
self._session = self._connection.connect(self.keyspace)
|
|
|
|
|
|
# We are forced to do concatenation below, as formatting would
|
|
# We are forced to do concatenation below, as formatting would
|