Skip to content

Commit 54c3199

Browse files
lxynovggreg
authored andcommitted
Add support for basic authentication
1 parent 68bf49f commit 54c3199

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

prestodb/auth.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,34 @@ def get_exceptions(self):
102102

103103
def handle_error(self, handle_error):
104104
pass
105+
106+
107+
class BasicAuthentication(Authentication):
108+
def __init__(self, username, password):
109+
self._username = username
110+
self._password = password
111+
112+
def set_client_session(self, client_session):
113+
pass
114+
115+
def set_http_session(self, http_session):
116+
try:
117+
import requests.auth
118+
except ImportError:
119+
raise RuntimeError('unable to import requests.auth')
120+
121+
http_session.auth = requests.auth.HTTPBasicAuth(
122+
self._username,
123+
self._password
124+
)
125+
return http_session
126+
127+
def setup(self, presto_client):
128+
self.set_client_session(presto_client.client_session)
129+
self.set_http_session(presto_client.http_session)
130+
131+
def get_exceptions(self):
132+
return ()
133+
134+
def handle_error(self, handle_error):
135+
pass

0 commit comments

Comments
 (0)