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

Cassandra Connection String Changes #3585

Merged
merged 18 commits into from
Apr 11, 2024
Merged
Changes from 2 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
65 changes: 55 additions & 10 deletions Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
#endregion

using Amdocs.Ginger.Common;
using Amdocs.Ginger.CoreNET.RunLib.CLILib;
using Cassandra;
using GingerCore.Actions;
using GingerCore.NoSqlBase.DataAccess;
using HBaseNet.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Authentication;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Expand All @@ -36,33 +39,74 @@
ActDBValidation Act = null;
dynamic myclass = null;
string mUDTName = null;


private SSLOptions sslOptions;

Check notice on line 42 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs#L42

Remove unassigned field 'sslOptions', or set its value.

public override bool Connect()
{
try
{
string queryTimeoutString = "querytimeout=";
const string queryTimeoutString = "querytimeout=";
const string sslString = "ssl=";
string sslValue = null;
int queryTimeout = 20000;//default timeout (20 seconds).
if (Db.DatabaseOperations.TNSCalculated.ToLower().Contains(queryTimeoutString.ToLower()))
string[] queryArray = Db.DatabaseOperations.TNSCalculated.Split(';');
aditydha marked this conversation as resolved.
Show resolved Hide resolved
if (queryArray[1].ToLower().Contains(queryTimeoutString))
{
string queryTimeoutValue = Db.DatabaseOperations.TNSCalculated.Substring(Db.DatabaseOperations.TNSCalculated.ToLower().IndexOf(queryTimeoutString.ToLower()) + queryTimeoutString.Length);
string queryTimeoutValue = queryArray[1].Substring(queryArray[1].ToLower().IndexOf(queryTimeoutString) + queryTimeoutString.Length);
aditydha marked this conversation as resolved.
Show resolved Hide resolved
queryTimeout = Convert.ToInt32(queryTimeoutValue) * 1000;
}
try
{
if (queryArray[2].ToLower().Contains(sslString))
{
sslValue = queryArray[2].Substring(queryArray[2].ToLower().IndexOf(sslString) + sslString.Length);

string[] HostKeySpace = Db.DatabaseOperations.TNSCalculated.Split('/');
}
var sslOptions = new SSLOptions(

Check warning on line 65 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs#L65

Rename 'sslOptions' which hides the field with the same name.
Enum.Parse<SslProtocols>(sslValue), false,
(sender, certificate, chain, errors) => { return true; });

Check notice on line 67 in Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Database/NoSqlBase/GingerCassandra.cs#L67

'sender' is not used. Use discard parameter instead.
}
catch (Exception e)
{
Reporter.ToLog(eLogLevel.ERROR, "SSL Value Not Correct. Please Enter SSL value like Default, None, Ssl2, Ssl3, Tls, Tls11, Tls12, Tls13", e);
throw (e);
}
string[] HostKeySpace = queryArray[0].ToLower().Replace("http://", "").Replace("https://", "").Split('/');
string[] HostPort = HostKeySpace[0].Split(':');

aditydha marked this conversation as resolved.
Show resolved Hide resolved
if (HostPort.Length == 2)
{
if (string.IsNullOrEmpty(Db.Pass) && string.IsNullOrEmpty(Db.User))
{
cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
if (string.IsNullOrEmpty(sslValue))
{
cluster = Cluster.Builder().AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
}
else
{
cluster = Cluster.Builder()
.AddContactPoint(HostPort[0])
.WithPort(Int32.Parse(HostPort[1]))
.WithSSL(sslOptions)
.WithQueryTimeout(queryTimeout)
.Build();
}
}
else
{
cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
if (string.IsNullOrEmpty(sslValue)) {
aditydha marked this conversation as resolved.
Show resolved Hide resolved
cluster = Cluster.Builder().WithCredentials(Db.User.ToString(), Db.Pass.ToString()).AddContactPoint(HostPort[0]).WithPort(Int32.Parse(HostPort[1])).WithQueryTimeout(queryTimeout).Build();
}
else
{
cluster = Cluster.Builder()
.AddContactPoint(HostPort[0])
.WithPort(Int32.Parse(HostPort[1]))
.WithAuthProvider(new PlainTextAuthProvider(Db.User, Db.Pass))
.WithSSL(sslOptions)
.WithQueryTimeout(queryTimeout)
.Build();
}
}
}
else
Expand Down Expand Up @@ -94,7 +138,7 @@
{
try
{
if (session != null)
if (session != null && !session.IsDisposed)
aditydha marked this conversation as resolved.
Show resolved Hide resolved
{
Metadata m = cluster.Metadata;
ICollection<string> Keyspaces = m.GetKeyspaces();
Expand Down Expand Up @@ -184,6 +228,7 @@
{
session.Dispose();
cluster.Dispose();
session = null;
aditydha marked this conversation as resolved.
Show resolved Hide resolved
}

public Type TypeConverter(RowSet RS, string Type1)
Expand Down
Loading