Skip to content
Closed
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
18 changes: 17 additions & 1 deletion airflow/providers/presto/hooks/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from prestodb.exceptions import DatabaseError
from prestodb.transaction import IsolationLevel

from airflow.configuration import conf
from airflow.security import utils
from airflow.hooks.dbapi_hook import DbApiHook


Expand All @@ -44,7 +46,21 @@ class PrestoHook(DbApiHook):
def get_conn(self):
"""Returns a connection object"""
db = self.get_connection(self.presto_conn_id) # pylint: disable=no-member
auth = prestodb.auth.BasicAuthentication(db.login, db.password) if db.password else None

auth = None
if db.extra_dejson.get('kerberos'):
principal = db.extra_dejson.get('kerberos_principal', conf.get('kerberos', 'principal'))
if "_HOST" in principal:
principal = utils.replace_hostname_pattern(
utils.get_components(principal))
auth = prestodb.auth.KerberosAuthentication(
config=db.extra_dejson.get('kerberos_config', '/etc/krb5.conf'),
service_name=db.extra_dejson.get('kerberos_service', 'presto'),
principal=principal,
ca_bundle=db.extra_dejson.get('kerberos_ca_bundle'),
)
elif db.password:
auth = prestodb.auth.BasicAuthentication(db.login, db.password)

return prestodb.dbapi.connect(
host=db.host,
Expand Down