diff --git a/pyhive/hive.py b/pyhive/hive.py index 9d610419..14af3d36 100644 --- a/pyhive/hive.py +++ b/pyhive/hive.py @@ -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) @@ -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) @@ -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