Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding Cassandra.login! method for authentication in database server
  • Loading branch information
guilleiguaran committed Jun 16, 2010
1 parent 55c2dd7 commit fd5998c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -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"})
Expand Down
10 changes: 10 additions & 0 deletions lib/cassandra/cassandra.rb
Expand Up @@ -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 <tt>client</tt> instance.
Expand Down Expand Up @@ -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
"#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
Expand Down

0 comments on commit fd5998c

Please sign in to comment.