adding timeout option to pypssl GET

This commit is contained in:
Matteo Lodi 2021-04-14 16:28:55 +02:00
parent 7cc17a4ced
commit 3a0ee47df2

View file

@ -26,8 +26,8 @@ class PyPSSL(object):
# No authentication defined. # No authentication defined.
pass pass
def _query(self, url): def _query(self, url, timeout=None):
response = self.session.get(url) response = self.session.get(url, timeout=timeout)
try: try:
return response.json() return response.json()
except: except:
@ -47,7 +47,7 @@ class PyPSSL(object):
return {'error': 'Incorrect format'} return {'error': 'Incorrect format'}
return None return None
def query(self, q): def query(self, q, timeout=None):
check = self._check_IP(q) check = self._check_IP(q)
if check is not None: if check is not None:
return check return check
@ -55,19 +55,19 @@ class PyPSSL(object):
path = 'pssl/query/{}'.format(q) path = 'pssl/query/{}'.format(q)
else: else:
path = 'v2pssl/query/{}'.format(q) path = 'v2pssl/query/{}'.format(q)
return self._query(urljoin(self.base_url, path)) return self._query(urljoin(self.base_url, path), timeout=timeout)
def query_cert(self, q): def query_cert(self, q, timeout=None):
if self.api_version != 2: if self.api_version != 2:
return {'error': 'Only available in API v2'} return {'error': 'Only available in API v2'}
path = 'v2pssl/cquery/{}'.format(q) path = 'v2pssl/cquery/{}'.format(q)
return self._query(urljoin(self.base_url, path)) return self._query(urljoin(self.base_url, path), timeout=timeout)
def fetch_cert(self, q, make_datetime=True): def fetch_cert(self, q, make_datetime=True, timeout=None):
if self.api_version != 2: if self.api_version != 2:
return {'error': 'Only available in API v2'} return {'error': 'Only available in API v2'}
path = 'v2pssl/cfetch/{}'.format(q) path = 'v2pssl/cfetch/{}'.format(q)
response = self._query(urljoin(self.base_url, path)) response = self._query(urljoin(self.base_url, path), timeout=timeout)
if response.get('error') or not make_datetime: if response.get('error') or not make_datetime:
return response return response
# create python datetime, doesn't return a json object # create python datetime, doesn't return a json object