Add login support for cassandra

This commit is contained in:
Dpatel 2015-01-27 17:40:46 -05:00
parent 2cf4b2c33e
commit ee6a71da4c

View File

@ -2,13 +2,13 @@
package cassandra package cassandra
import ( import (
"net/url" "fmt"
"strings"
"time"
"github.com/gocql/gocql" "github.com/gocql/gocql"
"github.com/mattes/migrate/file" "github.com/mattes/migrate/file"
"github.com/mattes/migrate/migrate/direction" "github.com/mattes/migrate/migrate/direction"
"net/url"
"strings"
"time"
) )
type Driver struct { type Driver struct {
@ -50,6 +50,21 @@ func (driver *Driver) Initialize(rawurl string) error {
cluster.Consistency = gocql.All cluster.Consistency = gocql.All
cluster.Timeout = 1 * time.Minute cluster.Timeout = 1 * time.Minute
// Check if url user struct is null
if u.User != nil {
password, passwordSet := u.User.Password()
if passwordSet == false {
return fmt.Errorf("Missing password. Please provide password")
}
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: u.User.Username(),
Password: password,
}
}
driver.session, err = cluster.CreateSession() driver.session, err = cluster.CreateSession()
if err != nil { if err != nil {