Skip to content

Commit

Permalink
BUG: sqlalchemy connection string parsing and ldap auth (cloudera#261)
Browse files Browse the repository at this point in the history
* pass parsed connection string username as user to connect

* pass PLAIN as auth_mech in case of LDAP to sasl_factory

* move auth_mech assignment after user/pass setting
  • Loading branch information
devinstevenson authored and timarmstrong committed Mar 7, 2019
1 parent 845a1c0 commit 521901c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions impala/_thrift_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_transport(socket, host, kerberos_service_name, auth_mechanism='NOSASL',
# PLAIN always requires a password for HS2.
password = 'password'
log.debug('get_transport: password=%s', password)

auth_mechanism = 'PLAIN' # sasl doesn't know mechanism LDAP
# Initializes a sasl client
from thrift_sasl import TSaslClientTransport
try:
Expand All @@ -169,6 +169,7 @@ def sasl_factory():
from impala.sasl_compat import PureSASLClient

def sasl_factory():
return PureSASLClient(host, username=user, password=password, service=kerberos_service_name)
return PureSASLClient(host, username=user, password=password,
service=kerberos_service_name)

return TSaslClientTransport(sasl_factory, auth_mechanism, socket)
2 changes: 1 addition & 1 deletion impala/hiveserver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def connect(host, port, timeout=None, use_ssl=False, ca_cert=None,
user=None, password=None, kerberos_service_name='impala',
auth_mechanism=None):
log.debug('Connecting to HiveServer2 %s:%s with %s authentication '
'mechanism', host, port, auth_mechanism)
'mechanism', host, port, auth_mechanism)
sock = get_socket(host, port, use_ssl, ca_cert)
if timeout is not None:
timeout = timeout * 1000. # TSocket expects millis
Expand Down
11 changes: 11 additions & 0 deletions impala/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ def dbapi(cls):
import impala.dbapi
return impala.dbapi

def create_connect_args(self, url):
kwargs = {
'host': url.host,
'port': url.port,
'user': url.username,
'password': url.password,
'database': url.database,
}
kwargs.update(url.query)
return ([], kwargs)

def initialize(self, connection):
self.default_schema_name = connection.connection.default_db

Expand Down

0 comments on commit 521901c

Please sign in to comment.