Skip to content

Commit

Permalink
[dbapi] Added ssl certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
TechGeekD committed Oct 25, 2019
1 parent bc56184 commit ea1ac7e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
42 changes: 38 additions & 4 deletions pydruid/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def connect(
password=None,
context=None,
header=False,
ssl_verify_cert=True,
): # noqa: E125
"""
Constructor for creating a connection to the database.
Expand All @@ -38,7 +39,17 @@ def connect(
"""
context = context or {}
return Connection(host, port, path, scheme, user, password, context, header)
return Connection(
host,
port,
path,
scheme,
user,
password,
context,
header,
ssl_verify_cert,
)


def check_closed(f):
Expand Down Expand Up @@ -118,6 +129,7 @@ def __init__(
password=None,
context=None,
header=False,
ssl_verify_cert=True,
):
netloc = "{host}:{port}".format(host=host, port=port)
self.url = parse.urlunparse((scheme, netloc, path, None, None, None))
Expand All @@ -127,6 +139,7 @@ def __init__(
self.header = header
self.user = user
self.password = password
self.ssl_verify_cert = ssl_verify_cert

@check_closed
def close(self):
Expand All @@ -150,7 +163,14 @@ def commit(self):
@check_closed
def cursor(self):
"""Return a new Cursor Object using the connection."""
cursor = Cursor(self.url, self.user, self.password, self.context, self.header)
cursor = Cursor(
self.url,
self.user,
self.password,
self.context,
self.header,
self.ssl_verify_cert,
)
self.cursors.append(cursor)

return cursor
Expand All @@ -171,12 +191,21 @@ class Cursor(object):

"""Connection cursor."""

def __init__(self, url, user=None, password=None, context=None, header=False):
def __init__(
self,
url,
user=None,
password=None,
context=None,
header=False,
ssl_verify_cert=True,
):
self.url = url
self.context = context or {}
self.header = header
self.user = user
self.password = password
self.ssl_verify_cert = ssl_verify_cert

# This read/write attribute specifies the number of rows to fetch at a
# time with .fetchmany(). It defaults to 1 meaning to fetch a single
Expand Down Expand Up @@ -300,7 +329,12 @@ def _stream_query(self, query):
requests.auth.HTTPBasicAuth(self.user, self.password) if self.user else None
)
r = requests.post(
self.url, stream=True, headers=headers, json=payload, auth=auth
self.url,
stream=True,
headers=headers,
json=payload,
auth=auth,
verify=self.ssl_verify_cert,
)
if r.encoding is None:
r.encoding = "utf-8"
Expand Down
1 change: 1 addition & 0 deletions tests/db/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_context(self, requests_post_mock):
stream=True,
headers={'Content-Type': 'application/json'},
json={'query': query, 'context': context, 'header': False},
verify=True
)

@patch('requests.post')
Expand Down

0 comments on commit ea1ac7e

Please sign in to comment.