Redo SSL configuration for SocketService.
This makes the code a bit clearer, reduces the nesting of try blocks, and also lets us provide a nice warning message if the user asks for SSL but we can't load the module for it.
Austin S. Hemmelgarn committed
May 2, 2018 at 08:57 UTC
5a8001352c609720797e9588ad7d29165b80d5c0
1 file changed
+16
-12
python.d/python_modules/bases/FrameworkServices/SocketService.py
+16
-12
@@ -273,20 +273,24 @@ class SocketService(SimpleService):
273
except (KeyError, TypeError):
274
self.debug('No port specified. Using: "{0}"'.format(self.port))
275
276
- if _SSL_SUPPORT:
276
+ try:
277
+ self.ssl = bool(self.configuration['ssl'])
278
+ if self.ssl and not _SSL_SUPPORT:
279
+ self.warning('SSL requested but not SSL module found, disabling SSL support.')
280
+ self.ssl = False
281
+ except (KeyError, TypeError):
282
+ if _SSL_SUPPORT:
283
+ self.debug('No SSL preference specified, not using SSL.')
284
+ self.ssl = False
285
+
286
+ if self.ssl and _SSL_SUPPORT:
287
try:
278
- self.ssl = bool(self.configuration['ssl'])
288
+ self.key = str(self.configuration['ssl_key'])
289
+ self.cert = str(self.configuration['ssl_cert'])
290
except (KeyError, TypeError):
280
- self.debug('No SSL preference specified, not using SSL.')
281
- self.ssl = False
282
- else:
283
- try:
284
- self.key = str(self.configuration['ssl_key'])
285
- self.cert = str(self.configuration['ssl_cert'])
286
- except (KeyError, TypeError):
287
- self.debug('No SSL client certificate configuration found.')
288
- self.key = None
289
- self.cert = None
291
+ self.debug('No SSL client certificate configuration found.')
292
+ self.key = None
293
+ self.cert = None
294
295
try:
296
self.request = str(self.configuration['request'])