mirror of
https://github.com/adulau/crl-monitor.git
synced 2024-11-22 01:57:05 +00:00
Merge pull request #8 from mlodic/adding_timeout
adding timeout option to pypssl GET
This commit is contained in:
commit
a4f62e2a43
1 changed files with 8 additions and 8 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue