PHOENIX-7848: Use ZK TLS properties from HBase config if present (#2467)

Parse ZooKeeper TLS properties from hbase-site.xml and add them to sqlline command line args.
diff --git a/bin/phoenix_utils.py b/bin/phoenix_utils.py
index 27032df..103bd70 100755
--- a/bin/phoenix_utils.py
+++ b/bin/phoenix_utils.py
@@ -25,6 +25,9 @@
 import re
 import subprocess
 import sys
+import xml.etree.ElementTree as ET
+
+zk_tls_args = ""
 
 def find(pattern, classPaths):
     paths = classPaths.split(os.pathsep)
@@ -126,6 +129,28 @@
             # Try to provide something valid
             hbase_conf_dir = '.'
 
+    hbase_site_file = os.path.join(hbase_conf_dir, "hbase-site.xml")
+    try:
+        global zk_tls_args
+        root = ET.parse(hbase_site_file).getroot()
+        zk_hbase_prefix = "hbase.zookeeper.property."
+        zkcfg = {
+            prop.find("name").text[len(zk_hbase_prefix):]: prop.find("value").text
+            for prop in root.findall("property")
+            if prop.find("name").text.startswith(zk_hbase_prefix)
+        }
+        if 'client.secure' in zkcfg and zkcfg.get('client.secure').lower() == 'true':
+            zk_tls_args = '-Dzookeeper.client.secure=true ' + \
+                '-Dzookeeper.clientCnxnSocket=' + zkcfg['clientCnxnSocket'] + ' ' + \
+                '-Dzookeeper.ssl.trustStore.location=' + zkcfg['ssl.trustStore.location'] + ' ' + \
+                '-Dzookeeper.ssl.trustStore.type=' + zkcfg['ssl.trustStore.type'] + ' ' + \
+                '-Dzookeeper.ssl.trustStore.password=' + zkcfg['ssl.trustStore.password'] + ' '
+    except Exception as e:
+        sys.exit(
+            "ERROR: Failed to parse ZooKeeper TLS properties from '%s': %s"
+            % (hbase_site_file, repr(e))
+        )
+
     global current_dir
     current_dir = os.path.dirname(os.path.abspath(__file__))
 
@@ -316,6 +341,7 @@
     setPath()
     print("phoenix_class_path:", phoenix_class_path)
     print("hbase_conf_dir:", hbase_conf_dir)
+    print("zk_tls_args:", zk_tls_args)
     print("current_dir:", current_dir)
     print("phoenix_embedded_jar_path:", phoenix_embedded_jar_path)
     print("phoenix_client_embedded_jar:", phoenix_client_embedded_jar)
diff --git a/bin/sqlline.py b/bin/sqlline.py
index 0942478..7fc8d25 100755
--- a/bin/sqlline.py
+++ b/bin/sqlline.py
@@ -94,6 +94,7 @@
 
 java_cmd = phoenix_utils.java + ' ' + phoenix_utils.jvm_module_flags + \
     ' ' + opts + \
+    ' ' + phoenix_utils.zk_tls_args + \
     ' -cp "' + phoenix_utils.hbase_conf_dir + os.pathsep + \
     phoenix_utils.hadoop_conf + os.pathsep + \
     phoenix_utils.sqlline_with_deps_jar + os.pathsep + \