Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Settings for cassandra connection #11

Closed
drivard opened this issue Oct 30, 2014 · 7 comments
Closed

Advanced Settings for cassandra connection #11

drivard opened this issue Oct 30, 2014 · 7 comments

Comments

@drivard
Copy link

drivard commented Oct 30, 2014

Hi,

I am looking for help in setting the connection to cassandra. I can't find what are the proper options to get it connected with my django settings.

I can tell that my cassandra setup is working fine because I can connect from OpsCenter and DevCenter and query the system tables. But I can't figure out how to initiate the connection for django-cassandra -engine.

I would really appreciate if you could help.

The following code is in my settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'mykeyspace',
        'USER': 'user',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',  # comma separeted hosts
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            },
            'connection': {
                'consistency': ConsistencyLevel.ONE,
                'lazy_connect': True,
                'retry_connect': True,
                'port': 9042,
                'username': 'user',
                'password': 'password',
                # + All connection options for cassandra.Cluster()
            }
        }
    }
}

If I leave the username and password in the connection options list I get the following message:

raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider")
cqlengine.exceptions.CQLEngineException: Username & Password are now handled by using the native driver's auth_provider

I didn't found anything talking about auth_provider and yes in my /etc/cassandra/cassandra.yaml I have it set to authenticator: PasswordAuthenticator.

Where can I find how to correctly set the connection options?

Any help is appreciated.

Regards
Dominick

@r4fek
Copy link
Owner

r4fek commented Oct 31, 2014

Hi Dominick,

thanks for your input! I'll implement support for auth_provider in very near future. Stay tuned!

@r4fek
Copy link
Owner

r4fek commented Oct 31, 2014

In the meantime you can add PlainTextAuthProvider (described here: http://datastax.github.io/python-driver/api/cassandra/auth.html#cassandra.auth.PlainTextAuthProvider) to connection options. Let me know if it solves your problem.

I'll add this option automatically if USER and PASSWORD options are set.

@drivard
Copy link
Author

drivard commented Oct 31, 2014

Yes I saw that this morning. I hadn't time yet to implement it completely
I'll finish the code and publish an example later tonight.

Thanks
Dominick

@drivard
Copy link
Author

drivard commented Oct 31, 2014

Here is how to get it to work:
At the top of your settings.py file import the Authenticator class:

from cassandra.auth import PlainTextAuthProvider

Once the Authenticator class is imported you can tweak your database connection like the following.

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'mykeyspace',
        'USER': 'user',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',  # comma separeted hosts
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            },
            'connection': {
                'consistency': ConsistencyLevel.ONE,
                'lazy_connect': True,
                'retry_connect': True,
                'port': 9042,
                'auth_provider': PlainTextAuthProvider(username='user', password='password'),
                # + All connection options for cassandra.Cluster()
            }
        }
    }
}

In my case the python manage.py syncdb command line returned

python manage.py syncdb
Creating keyspace mykeyspace..

Thanks for your help, I am closing the issue.

Best
Dominick

@drivard drivard closed this as completed Nov 1, 2014
@r4fek
Copy link
Owner

r4fek commented Nov 1, 2014

Try the new version 0.1.4. Just add USER and PASSWORD, no need to define auth_provider in connection options.
Thanks for your contribution!

@drivard
Copy link
Author

drivard commented Nov 1, 2014

I confirm this works using the following connection pattern:

DATABASES = {
    'default': {
        'ENGINE': 'django_cassandra_engine',
        'NAME': 'mykeyspace',
        'USER': 'user',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',  # comma separeted hosts
        'OPTIONS': {
            'replication': {
                'strategy_class': 'SimpleStrategy',
                'replication_factor': 1
            },
            'connection': {
                'consistency': ConsistencyLevel.ONE,
                'lazy_connect': True,
                'retry_connect': True,
                'port': 9042,
                # + All connection options for cassandra.Cluster()
            }
        }
    }
}

No more need to import from cassandra.auth import PlainTextAuthProvider in the settings.py file.

Thanks
Dominick

@drivard
Copy link
Author

drivard commented Nov 1, 2014

Thanks Rafal the fast fix is really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants