From fd5998c06e2bf387b45397f97349df292eabd41f Mon Sep 17 00:00:00 2001 From: Guillermo Date: Tue, 15 Jun 2010 23:58:48 -0500 Subject: [PATCH] Adding Cassandra.login! method for authentication in database server --- README.rdoc | 4 ++++ lib/cassandra/cassandra.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.rdoc b/README.rdoc index 21a16a9..51a1c9b 100644 --- a/README.rdoc +++ b/README.rdoc @@ -38,6 +38,10 @@ Connect to a server and keyspace: client = Cassandra.new('Twitter', '127.0.0.1:9160') +Login on server if the keyspace require authentication: + + client.login!('username','password') + Insert into a column family. You can insert a `Cassandra::OrderedHash`, or a regular Hash, if order doesn't matter: client.insert(:Users, "5", {'screen_name' => "buttonscat"}) diff --git a/lib/cassandra/cassandra.rb b/lib/cassandra/cassandra.rb index 3928955..b273b59 100644 --- a/lib/cassandra/cassandra.rb +++ b/lib/cassandra/cassandra.rb @@ -3,6 +3,10 @@ Create a new Cassandra client instance. Accepts a keyspace name, and optional host and port. client = Cassandra.new('twitter', '127.0.0.1:9160') + +If the server requires authentication, you must authenticate before make calls + + client.login!('username','password') You can then make calls to the server via the client instance. @@ -85,6 +89,12 @@ def disconnect! def keyspaces @keyspaces ||= client.get_string_list_property("keyspaces") end + + def login!(username, password) + auth_request = CassandraThrift::AuthenticationRequest.new + auth_request.credentials = {'username' => username, 'password' => password} + client.login(@keyspace, auth_request) + end def inspect "#