Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cac6e08

Browse files
committed
Merge pull request golang-migrate#30 from pateld982/master
Add authentication support for cassandra
2 parents f12373e + ee6a71d commit cac6e08

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

driver/cassandra/cassandra.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
package cassandra
33

44
import (
5-
"net/url"
6-
"strings"
7-
"time"
8-
5+
"fmt"
96
"github.com/gocql/gocql"
107
"github.com/mattes/migrate/file"
118
"github.com/mattes/migrate/migrate/direction"
9+
"net/url"
10+
"strings"
11+
"time"
1212
)
1313

1414
type Driver struct {
@@ -50,6 +50,21 @@ func (driver *Driver) Initialize(rawurl string) error {
5050
cluster.Consistency = gocql.All
5151
cluster.Timeout = 1 * time.Minute
5252

53+
// Check if url user struct is null
54+
if u.User != nil {
55+
password, passwordSet := u.User.Password()
56+
57+
if passwordSet == false {
58+
return fmt.Errorf("Missing password. Please provide password")
59+
}
60+
61+
cluster.Authenticator = gocql.PasswordAuthenticator{
62+
Username: u.User.Username(),
63+
Password: password,
64+
}
65+
66+
}
67+
5368
driver.session, err = cluster.CreateSession()
5469

5570
if err != nil {

0 commit comments

Comments
 (0)