UrlService self signed certs support fix
lgz committed
Apr 14, 2018 at 22:57 UTC
23e9030f9aa5e4a6437a558bbaaf4e8e85f255bc
1 file changed
+5
-4
python.d/python_modules/bases/FrameworkServices/UrlService.py
+5
-4
@@ -24,6 +24,7 @@ class UrlService(SimpleService):
24
self.proxy_url = self.configuration.get('proxy_url')
25
self.header = self.configuration.get('header')
26
self.request_timeout = self.configuration.get('timeout', 1)
27
+ self.tls_verify = self.configuration.get('tls_verify')
28
self._manager = None
29
30
def __make_headers(self, **header_kw):
@@ -62,8 +63,8 @@ class UrlService(SimpleService):
63
params = dict(headers=header)
64
try:
65
url = header_kw.get('url') or self.url
65
- if url.startswith('https'):
66
- return manager(assert_hostname=False, cert_reqs='CERT_NONE', **params)
66
+ if url.startswith('https') and not self.tls_verify:
67
+ return manager(assert_hostname=False, cert_reqs='CERT_NONE', ca_certs=None, **params)
68
return manager(**params)
69
except (urllib3.exceptions.ProxySchemeUnknown, TypeError) as error:
70
self.error('build_manager() error:', str(error))
@@ -77,13 +78,13 @@ class UrlService(SimpleService):
78
try:
79
status, data = self._get_raw_data_with_status(url, manager)
80
except (urllib3.exceptions.HTTPError, TypeError, AttributeError) as error:
80
- self.error('Url: {url}. Error: {error}'.format(url=url, error=error))
81
+ self.error('Url: {url}. Error: {error}'.format(url=url or self.url, error=error))
82
return None
83
84
if status == 200:
85
return data.decode()
86
else:
86
- self.debug('Url: {url}. Http response status code: {code}'.format(url=url, code=status))
87
+ self.debug('Url: {url}. Http response status code: {code}'.format(url=url or self.url, code=status))
88
return None
89
90
def _get_raw_data_with_status(self, url=None, manager=None, retries=1, redirect=True):