From 28246fda692b32360a6d51592f1b935e0a40f4ef Mon Sep 17 00:00:00 2001 From: j4zzcat Date: Mon, 9 Jul 2018 18:22:04 +0300 Subject: [PATCH 1/5] API version can be specified Allow one to specify the API version of the RestApiClient. --- modules/arielapiclient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/arielapiclient.py b/modules/arielapiclient.py index 34ff148..1833c6b 100755 --- a/modules/arielapiclient.py +++ b/modules/arielapiclient.py @@ -12,13 +12,13 @@ class APIClient(RestApiClient): # This class will encode any data or query parameters which will then be # sent to the call_api() method of its inherited class. - def __init__(self, config_section='DEFAULT', config=None): + def __init__(self, config_section='DEFAULT', version='6.0', config=None): # This version of the ariel APIClient is designed to function with # version 6.0 of the ariel API. self.endpoint_start = 'ariel/' super(APIClient, self).__init__(config_section=config_section, - version='6.0', config=config) + version=version, config=config) def get_databases(self): From e122dbc3ed0f022939bcdfa8abbac83a6dee3ea5 Mon Sep 17 00:00:00 2001 From: j4zzcat Date: Thu, 12 Jul 2018 09:53:06 +0300 Subject: [PATCH 2/5] Add timeout to call_api Exposed timeout control of urllib.urlopen() in call_api(). There are situations where increasing or decreasing the timeout period is desirable. The default now is 10 seconds. --- modules/RestApiClient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/RestApiClient.py b/modules/RestApiClient.py index d27ef0f..9de8b2e 100755 --- a/modules/RestApiClient.py +++ b/modules/RestApiClient.py @@ -108,7 +108,7 @@ def __init__(self, config_section='DEFAULT', version=None, config=None): # This method is used to set up an HTTP request and send it to the server def call_api(self, endpoint, method, headers=None, params=[], data=None, - print_request=False): + print_request=False, timeout=10): path = self.parse_path(endpoint, params) @@ -131,7 +131,7 @@ def call_api(self, endpoint, method, headers=None, params=[], data=None, headers=actual_headers) try: - response = urlopen(request, data) + response = urlopen(request, data, timeout=timeout) response_info = response.info() if 'Deprecated' in response_info: From 0fdf10840ee00bc03e498a9c5e9b4ac15de96ace Mon Sep 17 00:00:00 2001 From: Sharon Dagan Date: Sat, 22 Dec 2018 23:26:31 +0200 Subject: [PATCH 3/5] added option to disable certificate verification --- modules/RestApiClient.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/RestApiClient.py b/modules/RestApiClient.py index 9de8b2e..33c7d1c 100755 --- a/modules/RestApiClient.py +++ b/modules/RestApiClient.py @@ -88,9 +88,12 @@ def __init__(self, config_section='DEFAULT', version=None, config=None): context.check_hostname = False check_hostname = False - # Instead of loading the default certificates load only the - # certificates specified by the user. - context.load_verify_locations(cafile=certificate_file) + if str( certificate_file ).lower() == "false": + context.verify_mode = ssl.CERT_NONE + else: + # Instead of loading the default certificates load only the + # certificates specified by the user. + context.load_verify_locations(cafile=certificate_file) else: if sys.version_info >= (3, 4): # Python 3.4 and above has the improved load_default_certs() From 360d69677a1725e184c8e2edd5264337c072674f Mon Sep 17 00:00:00 2001 From: Sharon Dagan Date: Sat, 22 Dec 2018 23:39:08 +0200 Subject: [PATCH 4/5] Save --- modules/RestApiClient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/RestApiClient.py b/modules/RestApiClient.py index 33c7d1c..3d5366b 100755 --- a/modules/RestApiClient.py +++ b/modules/RestApiClient.py @@ -90,7 +90,7 @@ def __init__(self, config_section='DEFAULT', version=None, config=None): if str( certificate_file ).lower() == "false": context.verify_mode = ssl.CERT_NONE - else: + else: # Instead of loading the default certificates load only the # certificates specified by the user. context.load_verify_locations(cafile=certificate_file) From babe601998d60e57d5ffbc3249a5334f01749251 Mon Sep 17 00:00:00 2001 From: Sharon Dagan Date: Sun, 23 Dec 2018 01:09:07 +0200 Subject: [PATCH 5/5] fixed indentation issue --- modules/RestApiClient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/RestApiClient.py b/modules/RestApiClient.py index 3d5366b..734433c 100755 --- a/modules/RestApiClient.py +++ b/modules/RestApiClient.py @@ -88,9 +88,9 @@ def __init__(self, config_section='DEFAULT', version=None, config=None): context.check_hostname = False check_hostname = False - if str( certificate_file ).lower() == "false": - context.verify_mode = ssl.CERT_NONE - else: + if str( certificate_file ).lower() == "false": + context.verify_mode = ssl.CERT_NONE + else: # Instead of loading the default certificates load only the # certificates specified by the user. context.load_verify_locations(cafile=certificate_file)