Skip to content

Commit

Permalink
Allow username password auth in Cassandra driver
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed Aug 13, 2015
1 parent b84d388 commit 2455395
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions datastore.md
Expand Up @@ -10,6 +10,8 @@ func main() {
// You can use table_cassandra.cql to generate the table.
// Arguments: ip address, keyspace, table
store.Get().Init("192.168.59.103", "crudtest", "instructions")
// OR, if you need authentication, it can also take 5 args, like so:
// store.Get().Init("192.168.59.103", "crudtest", "instructions", "username", "password")
}
```

Expand Down
11 changes: 10 additions & 1 deletion drivers/cassandra/cassandra.go
Expand Up @@ -30,7 +30,7 @@ func (cs *Cassandra) SetSession(session *gocql.Session) {
}

func (cs *Cassandra) Init(args ...string) {
if len(args) != 3 {
if len(args) != 3 || len(args) != 5 {
log.WithField("args", args).Fatal("Invalid arguments")
return
}
Expand All @@ -42,6 +42,15 @@ func (cs *Cassandra) Init(args ...string) {
cluster := gocql.NewCluster(ipaddr)
cluster.Keyspace = keyspace
cluster.Consistency = gocql.Quorum
if len(args) == 5 {
log.WithField("username", args[3]).
Debug("Passing username and password to Cassandra")
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: args[3],
Password: args[4],
}
}

session, err := cluster.CreateSession()
if err != nil {
x.LogErr(log, err).Fatal("While creating session")
Expand Down

0 comments on commit 2455395

Please sign in to comment.