Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass context to Cassandra queries #6954

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/database/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Cassandra) CreateUser(ctx context.Context, statements dbplugin.Statemen
err = session.Query(dbutil.QueryHelper(query, map[string]string{
"username": username,
"password": password,
})).Exec()
})).WithContext(ctx).Exec()
if err != nil {
for _, stmt := range rollbackCQL {
for _, query := range strutil.ParseArbitraryStringSlice(stmt, ";") {
Expand All @@ -140,7 +140,7 @@ func (c *Cassandra) CreateUser(ctx context.Context, statements dbplugin.Statemen

session.Query(dbutil.QueryHelper(query, map[string]string{
"username": username,
})).Exec()
})).WithContext(ctx).Exec()
}
}
return "", "", err
Expand Down Expand Up @@ -185,7 +185,7 @@ func (c *Cassandra) RevokeUser(ctx context.Context, statements dbplugin.Statemen

err := session.Query(dbutil.QueryHelper(query, map[string]string{
"username": username,
})).Exec()
})).WithContext(ctx).Exec()

result = multierror.Append(result, err)
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (c *Cassandra) RotateRootCredentials(ctx context.Context, statements []stri
err := session.Query(dbutil.QueryHelper(query, map[string]string{
"username": c.Username,
"password": password,
})).Exec()
})).WithContext(ctx).Exec()

result = multierror.Append(result, err)
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/database/cassandra/connection_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (c *cassandraConnectionProducer) Init(ctx context.Context, conf map[string]
return conf, nil
}

func (c *cassandraConnectionProducer) Connection(_ context.Context) (interface{}, error) {
func (c *cassandraConnectionProducer) Connection(ctx context.Context) (interface{}, error) {
if !c.Initialized {
return nil, connutil.ErrNotInitialized
}
Expand All @@ -147,7 +147,7 @@ func (c *cassandraConnectionProducer) Connection(_ context.Context) (interface{}
return c.session, nil
}

session, err := c.createSession()
session, err := c.createSession(ctx)
if err != nil {
return nil, err
}
Expand All @@ -172,7 +172,7 @@ func (c *cassandraConnectionProducer) Close() error {
return nil
}

func (c *cassandraConnectionProducer) createSession() (*gocql.Session, error) {
func (c *cassandraConnectionProducer) createSession(ctx context.Context) (*gocql.Session, error) {
hosts := strings.Split(c.Hosts, ",")
clusterConfig := gocql.NewCluster(hosts...)
clusterConfig.Authenticator = gocql.PasswordAuthenticator{
Expand Down Expand Up @@ -256,7 +256,7 @@ func (c *cassandraConnectionProducer) createSession() (*gocql.Session, error) {
}

// Verify the info
err = session.Query(`LIST ALL`).Exec()
err = session.Query(`LIST ALL`).WithContext(ctx).Exec()
if err != nil && len(c.Username) != 0 && strings.Contains(err.Error(), "not authorized") {
rowNum := session.Query(dbutil.QueryHelper(`LIST CREATE ON ALL ROLES OF '{{username}}';`, map[string]string{
"username": c.Username,
Expand Down