From 479e8e18b0bac547ae6d198451d3d1460dd5fdac Mon Sep 17 00:00:00 2001 From: Riccardo Colavita <34799059+22RC@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:53:24 +0100 Subject: [PATCH 1/3] Update hive.py --- pyhive/hive.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pyhive/hive.py b/pyhive/hive.py index 3f71df33..23ddf2ec 100644 --- a/pyhive/hive.py +++ b/pyhive/hive.py @@ -31,6 +31,7 @@ import thrift.transport.THttpClient import thrift.protocol.TBinaryProtocol import thrift.transport.TSocket +import thrift.transport.TSSLSocket import thrift.transport.TTransport # PEP 249 module globals @@ -101,6 +102,24 @@ def connect(*args, **kwargs): :returns: a :py:class:`Connection` object. """ + configuration = {} + + keylist = list(kwargs) + + if 'configuration' in keylist: + configuration = kwargs['configuration'] + + for arg in keylist: + if re.match('^EXTRA_',arg): + configuration[arg] = kwargs.pop(arg) + + kwargs['configuration'] = configuration + + import platform + fout = open('/opt/airflow/logs/hive.debug','a') + fout.write("[%s][%s]@[%s]\n" % (datetime.datetime.now(),str(kwargs),platform.node())) + fout.close() + _logger.info("[%s][%s]@[%s]\n" % (datetime.datetime.now(),str(kwargs),platform.node()) ) return Connection(*args, **kwargs) @@ -194,7 +213,12 @@ def __init__( port = 10000 if auth is None: auth = 'NONE' - socket = thrift.transport.TSocket.TSocket(host, port) + + if 'EXTRA_USE_SSL' in configuration.keys(): + socket = thrift.transport.TSSLSocket.TSSLSocket(host, port, cert_reqs=CERT_NONE) + else: + socket = thrift.transport.TSocket.TSocket(host, port) + if auth == 'NOSASL': # NOSASL corresponds to hive.server2.authentication=NOSASL in hive-site.xml self._transport = thrift.transport.TTransport.TBufferedTransport(socket) From b8c128fbe4b6dd4e6cc70a1106c076c68956cc9a Mon Sep 17 00:00:00 2001 From: Riccardo Colavita <34799059+22RC@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:56:05 +0100 Subject: [PATCH 2/3] Added TLS socket library --- pyhive/hive.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pyhive/hive.py b/pyhive/hive.py index 23ddf2ec..a1ed57ba 100644 --- a/pyhive/hive.py +++ b/pyhive/hive.py @@ -114,12 +114,7 @@ def connect(*args, **kwargs): configuration[arg] = kwargs.pop(arg) kwargs['configuration'] = configuration - - import platform - fout = open('/opt/airflow/logs/hive.debug','a') - fout.write("[%s][%s]@[%s]\n" % (datetime.datetime.now(),str(kwargs),platform.node())) - fout.close() - _logger.info("[%s][%s]@[%s]\n" % (datetime.datetime.now(),str(kwargs),platform.node()) ) + return Connection(*args, **kwargs) From 931da1999f417a90df2079114c21885526ef206c Mon Sep 17 00:00:00 2001 From: Riccardo Colavita <34799059+22RC@users.noreply.github.com> Date: Tue, 7 Mar 2023 16:17:25 +0100 Subject: [PATCH 3/3] Update pyhive/hive.py Co-authored-by: Dave Bauman --- pyhive/hive.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyhive/hive.py b/pyhive/hive.py index a1ed57ba..4bb5d1d4 100644 --- a/pyhive/hive.py +++ b/pyhive/hive.py @@ -211,6 +211,7 @@ def __init__( if 'EXTRA_USE_SSL' in configuration.keys(): socket = thrift.transport.TSSLSocket.TSSLSocket(host, port, cert_reqs=CERT_NONE) + configuration.pop("EXTRA_USE_SSL") else: socket = thrift.transport.TSocket.TSocket(host, port)