sdap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eamonf...@apache.org
Subject [incubator-sdap-nexus] 01/01: Add cassandra auth support to delete_by_query script
Date Fri, 30 Oct 2020 20:09:21 GMT
This is an automated email from the ASF dual-hosted git repository.

eamonford pushed a commit to branch delete-script-support-cassandra-auth
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git

commit 395e154d1231e0f22f97d00e59d3ddb0493aff1c
Author: Eamon Ford <eamonford@gmail.com>
AuthorDate: Fri Oct 30 13:09:01 2020 -0700

    Add cassandra auth support to delete_by_query script
---
 tools/deletebyquery/deletebyquery.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tools/deletebyquery/deletebyquery.py b/tools/deletebyquery/deletebyquery.py
index f703448..6d5233c 100644
--- a/tools/deletebyquery/deletebyquery.py
+++ b/tools/deletebyquery/deletebyquery.py
@@ -20,9 +20,10 @@ import logging
 import uuid
 from random import sample
 
+from cassandra.auth import PlainTextAuthProvider
 import cassandra.concurrent
 from cassandra.cluster import Cluster
-from cassandra.policies import RoundRobinPolicy, TokenAwarePolicy
+from cassandra.policies import RoundRobinPolicy, TokenAwarePolicy, WhiteListRoundRobinPolicy
 from solrcloudpy import SolrConnection, SearchOptions
 
 from six.moves import input
@@ -52,10 +53,16 @@ def init(args):
     dc_policy = RoundRobinPolicy()
     token_policy = TokenAwarePolicy(dc_policy)
 
+    if args.cassandraUsername and args.cassandraPassword:
+        auth_provider = PlainTextAuthProvider(username=args.cassandraUsername, password=args.cassandraPassword)
+    else:
+        auth_provider = None
+
     global cassandra_cluster
     cassandra_cluster = Cluster(contact_points=args.cassandra, port=args.cassandraPort,
                                 protocol_version=int(args.cassandraProtocolVersion),
-                                load_balancing_policy=token_policy)
+                                load_balancing_policy=token_policy,
+                                auth_provider=auth_provider)
     global cassandra_session
     cassandra_session = cassandra_cluster.connect(keyspace=args.cassandraKeyspace)
 
@@ -128,7 +135,8 @@ def check_query(query):
         return False
     else:
         se = SearchOptions()
-        se.commonparams.q('%s:%s' % (SOLR_UNIQUE_KEY, sample(solr_response.result.response.docs,
1)[0][SOLR_UNIQUE_KEY]))
+        se.commonparams.q('%s:%s' % (SOLR_UNIQUE_KEY, sample(
+            solr_response.result.response.docs, 1)[0][SOLR_UNIQUE_KEY]))
         logging.info(json.dumps(solr_collection.search(se).result.response.docs[0], indent=2))
         return check_query(query)
 
@@ -237,6 +245,14 @@ def parse_args():
                         required=False,
                         default='9042')
 
+    parser.add_argument('--cassandraUsername',
+                        help='The username used to connect to Cassandra.',
+                        required=False)
+
+    parser.add_argument('--cassandraPassword',
+                        help='The password used to connect to Cassandra.',
+                        required=False)
+
     parser.add_argument('-pv', '--cassandraProtocolVersion',
                         help='The version of the Cassandra protocol the driver should use.',
                         required=False,


Mime
View raw message