Skip to content

Instantly share code, notes, and snippets.

@elvuel
Created May 16, 2013 01:57
Show Gist options
  • Save elvuel/5588868 to your computer and use it in GitHub Desktop.
Save elvuel/5588868 to your computer and use it in GitHub Desktop.
cequel & cassandra-cql patch for Cassandra1.2 user Authentication
# /home/elvuel/.rvm/gems/ruby-2.0.0-p0@rails/gems/cequel-0.5.6/lib/cequel/keyspace.rb
def configure(configuration = {})
@configuration = configuration
@hosts = configuration[:host] || configuration[:hosts]
@thrift_options = configuration[:thrift].try(:symbolize_keys) || {}
@keyspace = configuration[:keyspace]
@username = configuration[:username] # ++
@password = configuration[:password] # ++
# reset the connections
clear_active_connections!
end
def build_connection
options = @keyspace ? {:keyspace => @keyspace, :username => @username, :password => @password } : {} # +-
CassandraCQL::Database.new(
@hosts,
options,
@thrift_options
)
end
# /home/elvuel/.rvm/gems/ruby-2.0.0-p0@rails/gems/cassandra-cql-1.1.5/lib/cassandra-cql/database.rb
def connect!
@connection = ThriftClient.new(CassandraCQL::Thrift::Client, @servers, @thrift_client_options)
login!(@options[:username], @options[:password]) if @options[:username] && @options[:password] # ++
obj = self
@connection.add_callback(:post_connect) do
@connection.set_cql_version(@cql_version) if @cql_version
execute("USE #{@keyspace}")
@connection.login(@auth_request) if @auth_request
end
end
#========OTHER NOTES==========
DEFAULT CREATED USER 'cassandra' with password 'cassandra'
# in conf/cassandra.yml change authenticator to PasswordAuthenticator
# in conf/cassandra.yml change authorizer to CassandraAuthorizer
#authenticator: org.apache.cassandra.auth.AllowAllAuthenticator
authenticator: org.apache.cassandra.auth.PasswordAuthenticator
#authorizer: org.apache.cassandra.auth.AllowAllAuthorizer
authorizer: org.apache.cassandra.auth.CassandraAuthorizer
# BASH FOR CREATE KEYSPACE
./bin/cqlsh<<EOF
DROP KEYSPACE roolv_dev;
CREATE KEYSPACE roolv_dev WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};
EOF
# CREATE A NEW USER
CREATE USER elvuel WITH PASSWORD 'elvuel';
GRANT ALL PERMISSIONS ON KEYSPACE roolv_dev TO elvuel;
# LIST A USER'S PERMISIONS ON SPECIFIC KEYSPACE
list all PERMISSIONS ON KEYSPACE roolv_dev OF elvuel;
username | resource | permission
----------+----------------------+------------
elvuel | <keyspace roolv_dev> | CREATE
elvuel | <keyspace roolv_dev> | ALTER
elvuel | <keyspace roolv_dev> | DROP
elvuel | <keyspace roolv_dev> | SELECT
elvuel | <keyspace roolv_dev> | MODIFY
elvuel | <keyspace roolv_dev> | AUTHORIZE
# ADD COLUMNFAMILY EXAMPLE
client.add_column_family(
Cassandra::ColumnFamily.new(
keyspace: 'roolv_dev',
name: 'keyword',
column_metadata: [
Cassandra::ColumnDef.new(
name: 'id'
)
]
)
)
# CREATE COLUMNFAMILY USING CQLSH
CREATE COLUMNFAMILY keywords (id uuid PRIMARY KEY, keyword varchar, created_at timestamp, updated_at timestamp);
CREATE INDEX keywords_idx ON keywords (keyword);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment