From 97c03ab734057ab8a83504388e36a7d5995eac15 Mon Sep 17 00:00:00 2001 From: Damian Piontek Date: Tue, 21 Mar 2017 16:13:12 +0100 Subject: [PATCH 1/6] Added methode to allow http basic auth with username and password to BaseDruidClient --- pydruid/client.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pydruid/client.py b/pydruid/client.py index 0ac6bd48..44eec202 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -29,6 +29,12 @@ def __init__(self, url, endpoint): self.url = url self.endpoint = endpoint self.query_builder = QueryBuilder() + self.username = None + self.password = None + + def set_basic_auth_credentials(self, username, password): + self.username = username + self.password = password def _prepare_url_headers_and_body(self, query): querystr = json.dumps(query.query_dict).encode('utf-8') @@ -37,6 +43,11 @@ def _prepare_url_headers_and_body(self, query): else: url = self.url + '/' + self.endpoint headers = {'Content-Type': 'application/json'} + if (self.username is not None) and (self.password is not None): + username_password = \ + b64encode(bytes('{}:{}'.format(self.username, self.password))) + headers['Authorization'] = 'Basic {}'.format(username_password) + return headers, querystr, url def _post(self, query): From b9b33aa8f4c2703133b51fdd0e7124180d4c3e60 Mon Sep 17 00:00:00 2001 From: Damian Piontek Date: Wed, 22 Mar 2017 16:21:53 +0100 Subject: [PATCH 2/6] added missing import --- pydruid/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydruid/client.py b/pydruid/client.py index 44eec202..548cff86 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -22,7 +22,7 @@ from six.moves import urllib from pydruid.query import QueryBuilder - +from base64 import b64encode class BaseDruidClient(object): def __init__(self, url, endpoint): From fcb2f4cb611fa51ac01ffc3022d0bc4929b69232 Mon Sep 17 00:00:00 2001 From: Damian Piontek Date: Fri, 7 Apr 2017 15:22:05 +0200 Subject: [PATCH 3/6] show full error message --- pydruid/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pydruid/client.py b/pydruid/client.py index 548cff86..8716127a 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -413,8 +413,6 @@ def _post(self, query): err = json.loads(e.read().decode("utf-8")) except (ValueError, AttributeError, KeyError): pass - else: - err = err.get('error', None) raise IOError('{0} \n Druid Error: {1} \n Query is: {2}'.format( e, err, json.dumps(query.query_dict, indent=4))) From de304210cd2436bf5775cf647028183a0acafcef Mon Sep 17 00:00:00 2001 From: Jeremy Phelps Date: Thu, 18 Jan 2018 14:04:55 -0800 Subject: [PATCH 4/6] Allow ignoring of SSL certificate errors. --- pydruid/client.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pydruid/client.py b/pydruid/client.py index 8716127a..92f32e3c 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -18,6 +18,7 @@ import json import sys +import ssl from six.moves import urllib @@ -31,11 +32,15 @@ def __init__(self, url, endpoint): self.query_builder = QueryBuilder() self.username = None self.password = None + self.ignore_certificate_errors=False def set_basic_auth_credentials(self, username, password): self.username = username self.password = password + def set_ignore_certificate_errors(self,value=True): + self.ignore_certificate_errors=value + def _prepare_url_headers_and_body(self, query): querystr = json.dumps(query.query_dict).encode('utf-8') if self.url.endswith('/'): @@ -397,11 +402,20 @@ class PyDruid(BaseDruidClient): def __init__(self, url, endpoint): super(PyDruid, self).__init__(url, endpoint) + def ssl_context(self): + ctx = ssl.create_default_context() + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + return ctx + def _post(self, query): try: headers, querystr, url = self._prepare_url_headers_and_body(query) req = urllib.request.Request(url, querystr, headers) - res = urllib.request.urlopen(req) + if self.ignore_certificate_errors: + res = urllib.request.urlopen(req, context=self.ssl_context()) + else: + res = urllib.request.urlopen(req) data = res.read().decode("utf-8") res.close() except urllib.error.HTTPError: From 0e37443005ff53583bad706706c340cc0969dfd6 Mon Sep 17 00:00:00 2001 From: Jeremy Phelps Date: Thu, 18 Jan 2018 16:03:49 -0800 Subject: [PATCH 5/6] Fix style errors. --- pydruid/client.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pydruid/client.py b/pydruid/client.py index 92f32e3c..98c7b460 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -25,6 +25,7 @@ from pydruid.query import QueryBuilder from base64 import b64encode + class BaseDruidClient(object): def __init__(self, url, endpoint): self.url = url @@ -33,13 +34,13 @@ def __init__(self, url, endpoint): self.username = None self.password = None self.ignore_certificate_errors=False - + def set_basic_auth_credentials(self, username, password): self.username = username self.password = password - def set_ignore_certificate_errors(self,value=True): - self.ignore_certificate_errors=value + def set_ignore_certificate_errors(self, value=True): + self.ignore_certificate_errors = value def _prepare_url_headers_and_body(self, query): querystr = json.dumps(query.query_dict).encode('utf-8') @@ -52,7 +53,7 @@ def _prepare_url_headers_and_body(self, query): username_password = \ b64encode(bytes('{}:{}'.format(self.username, self.password))) headers['Authorization'] = 'Basic {}'.format(username_password) - + return headers, querystr, url def _post(self, query): From b153f78035c191e949976da7faaad408147c9913 Mon Sep 17 00:00:00 2001 From: Jeremy Phelps Date: Thu, 18 Jan 2018 16:06:06 -0800 Subject: [PATCH 6/6] Fix another style error --- pydruid/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydruid/client.py b/pydruid/client.py index 98c7b460..a6b4c3da 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -33,7 +33,7 @@ def __init__(self, url, endpoint): self.query_builder = QueryBuilder() self.username = None self.password = None - self.ignore_certificate_errors=False + self.ignore_certificate_errors = False def set_basic_auth_credentials(self, username, password): self.username = username