Merge pull request #30 from pateld982/master

Add authentication support for cassandra
This commit is contained in:
Matthias Kadenbach 2015-02-04 21:47:02 +01:00
commit cac6e08b44
1 changed files with 19 additions and 4 deletions

View File

@ -2,13 +2,13 @@
package cassandra
import (
"net/url"
"strings"
"time"
"fmt"
"github.com/gocql/gocql"
"github.com/mattes/migrate/file"
"github.com/mattes/migrate/migrate/direction"
"net/url"
"strings"
"time"
)
type Driver struct {
@ -50,6 +50,21 @@ func (driver *Driver) Initialize(rawurl string) error {
cluster.Consistency = gocql.All
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()
if err != nil {