From e77e5bb3d82c7a94e914b9ade2546946cd132496 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 27 Aug 2020 16:29:21 +0200 Subject: [PATCH] Only expand paths if set --- platypush/backend/mqtt.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index 11c689ed3..083dd3550 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -88,15 +88,9 @@ class MqttBackend(Backend): self._client = None self._listeners = [] - self.tls_cafile = os.path.abspath(os.path.expanduser(tls_cafile)) \ - if tls_cafile else None - - self.tls_certfile = os.path.abspath(os.path.expanduser(tls_certfile)) \ - if tls_certfile else None - - self.tls_keyfile = os.path.abspath(os.path.expanduser(tls_keyfile)) \ - if tls_keyfile else None - + self.tls_cafile = self._expandpath(tls_cafile) if tls_cafile else None + self.tls_certfile = self._expandpath(tls_certfile) if tls_certfile else None + self.tls_keyfile = self._expandpath(tls_keyfile) if tls_keyfile else None self.tls_version = MQTTPlugin.get_tls_version(tls_version) self.tls_ciphers = tls_ciphers self.tls_insecure = tls_insecure @@ -138,6 +132,10 @@ class MqttBackend(Backend): return handler + @staticmethod + def _expand_path(path: str) -> str: + return os.path.abspath(os.path.expanduser(path)) if path else path + def _initialize_listeners(self, listeners_conf): import paho.mqtt.client as mqtt @@ -153,7 +151,7 @@ class MqttBackend(Backend): topics = listener.get('topics') username = listener.get('username') password = listener.get('password') - tls_cafile = os.path.abspath(os.path.expanduser(listener.get('tls_cafile'))) + tls_cafile = self._expandpath(listener.get('tls_cafile')) if not host or not topics: self.logger.warning('No host nor list of topics specified for ' + @@ -169,8 +167,8 @@ class MqttBackend(Backend): if tls_cafile: client.tls_set(ca_certs=tls_cafile, - certfile=os.path.abspath(os.path.expanduser(listener.get('tls_certfile'))), - keyfile=os.path.abspath(os.path.expanduser(listener.get('tls_keyfile'))), + certfile=self._expandpath(listener.get('tls_certfile')), + keyfile=self._expandpath(listener.get('tls_keyfile')), tls_version=MQTTPlugin.get_tls_version(listener.get('tls_version')), ciphers=listener.get('tls_ciphers'))