Skip to content
Open
Changes from all 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
11 changes: 8 additions & 3 deletions pyhs2/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from thrift.protocol.TBinaryProtocol import TBinaryProtocol
from thrift.transport.TSocket import TSocket
from thrift.transport.TSSLSocket import TSSLSocket
from thrift.transport.TTransport import TBufferedTransport
import sasl
from cloudera.thrift_sasl import TSaslClientTransport
Expand All @@ -16,15 +17,19 @@ class Connection(object):
client = None
session = None

def __init__(self, host=None, port=10000, authMechanism=None, user=None, password=None, database=None, configuration=None, timeout=None):
def __init__(self, host=None, port=10000, authMechanism=None, user=None, password=None, database=None, configuration=None, timeout=None, ssl=False, ssl_validate=True):
authMechanisms = set(['NOSASL', 'PLAIN', 'KERBEROS', 'LDAP'])
if authMechanism not in authMechanisms:
raise NotImplementedError('authMechanism is either not supported or not implemented')
#Must set a password for thrift, even if it doesn't need one
#Open issue with python-sasl
if authMechanism == 'PLAIN' and (password is None or len(password) == 0):
password = 'password'
socket = TSocket(host, port)
socket = None
if ssl:
socket = TSSLSocket(host, port, ssl_validate)
else:
socket = TSocket(host, port)
socket.setTimeout(timeout)
if authMechanism == 'NOSASL':
transport = TBufferedTransport(socket)
Expand Down Expand Up @@ -75,4 +80,4 @@ def cursor(self):

def close(self):
req = TCloseSessionReq(sessionHandle=self.session)
self.client.CloseSession(req)
self.client.CloseSession(req)