Skip to content

Commit

Permalink
update as per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeshmu committed Jun 4, 2023
1 parent 1b359e9 commit 1e48903
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions pyhive/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,6 @@
}


def get_sasl_client(host, sasl_auth, service=None, username=None, password=None):
import sasl
sasl_client = sasl.Client()
sasl_client.setAttr('host', host)

if sasl_auth == 'GSSAPI':
if service is None:
raise ValueError("kerberos_service_name is required for GSSAPI authentication")
sasl_client.setAttr('service', service)
elif sasl_auth == 'PLAIN':
if username is None or password is None:
raise ValueError("username and password are required for PLAIN authentication")
sasl_client.setAttr('username', username)
sasl_client.setAttr('password', password)
else:
raise AssertionError

sasl_client.init()
return sasl_client


def get_pure_sasl_client(host, sasl_auth, service=None, username=None, password=None):
from pyhive.sasl_compat import PureSASLClient

if sasl_auth == 'GSSAPI':
if service is None:
raise ValueError("kerberos_service_name is required for GSSAPI authentication")
sasl_kwargs = {'service': service}
elif sasl_auth == 'PLAIN':
if username is None or password is None:
raise ValueError("username and password are required for PLAIN authentication")
sasl_kwargs = {'username': username, 'password': password}
else:
raise AssertionError

return PureSASLClient(host=host, **sasl_kwargs)


def _parse_timestamp(value):
if value:
match = _TIMESTAMP_PATTERN.match(value)
Expand Down Expand Up @@ -246,6 +208,44 @@ def __init__(
# Password doesn't matter in NONE mode, just needs to be nonempty.
password = 'x'

def get_sasl_client(host, sasl_auth, service=None, username=None, password=None):
import sasl
sasl_client = sasl.Client()
sasl_client.setAttr('host', host)

if sasl_auth == 'GSSAPI':
if service is None:
raise ValueError("kerberos_service_name is required for GSSAPI authentication")
sasl_client.setAttr('service', service)
elif sasl_auth == 'PLAIN':
if username is None or password is None:
raise ValueError("username and password are required for PLAIN authentication")
sasl_client.setAttr('username', username)
sasl_client.setAttr('password', password)
else:
raise AssertionError

sasl_client.init()
return sasl_client


def get_pure_sasl_client(host, sasl_auth, service=None, username=None, password=None):
from pyhive.sasl_compat import PureSASLClient

if sasl_auth == 'GSSAPI':
if service is None:
raise ValueError("kerberos_service_name is required for GSSAPI authentication")
sasl_kwargs = {'service': service}
elif sasl_auth == 'PLAIN':
if username is None or password is None:
raise ValueError("username and password are required for PLAIN authentication")
sasl_kwargs = {'username': username, 'password': password}
else:
raise AssertionError

return PureSASLClient(host=host, **sasl_kwargs)


def get_installed_sasl(host, sasl_auth, service=None, username=None, password=None):
try:
sasl_client = get_sasl_client(host=host, sasl_auth=sasl_auth, service=service, username=username, password=password)
Expand All @@ -260,6 +260,7 @@ def get_installed_sasl(host, sasl_auth, service=None, username=None, password=No

import thrift_sasl
self._transport = thrift_sasl.TSaslClientTransport(sasl_client, sasl_auth, socket)

else:
# All HS2 config options:
# https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-Configuration
Expand Down

0 comments on commit 1e48903

Please sign in to comment.