From d35c95f61c3017a19728aa100280066d42eefe95 Mon Sep 17 00:00:00 2001 From: Rob Vaterlaus Date: Mon, 20 Dec 2010 17:52:34 -0800 Subject: [PATCH] Fixed bugs with authentication. --- django_cassandra/db/base.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/django_cassandra/db/base.py b/django_cassandra/db/base.py index 70cde7a..b87e3a5 100644 --- a/django_cassandra/db/base.py +++ b/django_cassandra/db/base.py @@ -69,7 +69,7 @@ def login(self): # TODO: This user/password auth code hasn't been tested if not self.logged_in: if self.user: - credentials = {'username': user, 'password': password} + credentials = {'username': self.user, 'password': self.password} self.client.login(AuthenticationRequest(credentials)) self.logged_in = True @@ -82,12 +82,12 @@ def open(self, set_keyspace=False, login=False): transport.open() self.transport = transport self.client = Cassandra.Client(protocol) - - if set_keyspace: - self.set_keyspace() if login: self.login() + + if set_keyspace: + self.set_keyspace() def close(self): if self.transport != None: @@ -151,7 +151,6 @@ def get_db_connection(self, set_keyspace=False, login=False): password = self.settings_dict.get('PASSWORD') # Create our connection wrapper - print "Creating Cassandra connection" self._db_connection = CassandraConnection(host, port, keyspace, user, password) if not self._db_connection.is_connected(): @@ -161,6 +160,13 @@ def get_db_connection(self, set_keyspace=False, login=False): # FIXME: Should do some version check here to make sure that we're # talking to a cassandra daemon that supports the operations we require + if login: + try: + self._db_connection.login() + except Exception, e: + # FIXME: Better handling of auth error + raise e + if set_keyspace: try: self._db_connection.set_keyspace() @@ -178,13 +184,6 @@ def get_db_connection(self, set_keyspace=False, login=False): self._db_connection.client.system_add_keyspace(keyspace_def) self._db_connection.set_keyspace() - if login: - try: - self._db_connection.login() - except Exception, e: - # FIXME: Better handling of auth error - raise e - return self._db_connection @property