Skip to content

Commit

Permalink
Modify cassandra/kubedb_client_builder.go
Browse files Browse the repository at this point in the history
Signed-off-by: Sabbir <[email protected]>
  • Loading branch information
sabbir-hossain70 committed Sep 6, 2024
1 parent 6146d16 commit e4a027c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cassandra/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package cassandra

import (
"context"
"errors"
"fmt"

core "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"strconv"

"github.com/gocql/gocql"
Expand Down Expand Up @@ -52,7 +56,33 @@ func (o *KubeDBClientBuilder) GetCassandraClient(dns string) (*Client, error) {
cluster.Keyspace = "system"
//cluster.Consistency = gocql.Any //ANY ConsistencyLevel is only supported for writes
cluster.Consistency = gocql.Quorum
//
if !o.db.Spec.DisableSecurity {
if o.db.Spec.AuthSecret == nil {
klog.Error("AuthSecret not set")
return nil, errors.New("auth-secret is not set")
}

authSecret := &core.Secret{}
err := o.kc.Get(o.ctx, types.NamespacedName{
Namespace: o.db.Namespace,
Name: o.db.Spec.AuthSecret.Name,
}, authSecret)
if err != nil {
if kerr.IsNotFound(err) {
klog.Error(err, "AuthSecret not found")
return nil, errors.New("auth-secret not found")
}
return nil, err
}
userName := string(authSecret.Data[core.BasicAuthUsernameKey])
password := string(authSecret.Data[core.BasicAuthPasswordKey])
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: userName,
Password: password,
}
}
//
session, err := cluster.CreateSession()
if err != nil {
return nil, fmt.Errorf("unable to connect to Cassandra cluster: %v", err)
Expand Down

0 comments on commit e4a027c

Please sign in to comment.