Module: check_mk
Branch: master
Commit: 60a567a3d598302329b01d1157ddacbd133f2fa4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=60a567a3d59830…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 23 08:03:26 2018 +0200
Refactored path access in ConfigDomainCACertificates to pathlib
Change-Id: I2be49963d3410505dee80a6d3e79b75c2ca5d4e0
---
cmk/gui/watolib.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index c93b028..9a055e1 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -524,15 +524,16 @@ class ConfigDomainCACertificates(ConfigDomain):
def _get_system_wide_trusted_ca_certificates(self):
trusted_cas, errors = set([]), []
- for cert_path in self.system_wide_trusted_ca_search_paths:
- if not os.path.isdir(cert_path):
+ for p in self.system_wide_trusted_ca_search_paths:
+ cert_path = Path(p)
+
+ if not cert_path.is_dir():
continue
- for entry in os.listdir(cert_path):
- cert_file_path = os.path.join(cert_path, entry)
+ for entry in cert_path.iterdir():
+ cert_file_path = entry.absolute()
try:
- ext = os.path.splitext(entry)[-1]
- if ext not in [ ".pem", ".crt" ]:
+ if entry.suffix not in [ ".pem", ".crt" ]:
continue
trusted_cas.update(self._get_certificates_from_file(cert_file_path))
@@ -547,7 +548,7 @@ class ConfigDomainCACertificates(ConfigDomain):
# We know a permission problem with some files that are created by
default on
# some distros. We simply ignore these files because we assume that
they are
# not needed.
- if cert_file_path == "/etc/ssl/certs/localhost.crt":
+ if cert_file_path == Path("/etc/ssl/certs/localhost.crt"):
continue
errors.append("Failed to add certificate '%s' to trusted
CA certificates. "
@@ -560,7 +561,7 @@ class ConfigDomainCACertificates(ConfigDomain):
def _get_certificates_from_file(self, path):
try:
- return [ match.group(0) for match in self._PEM_RE.finditer(open(path).read())
]
+ return [ match.group(0) for match in
self._PEM_RE.finditer(open("%s" % path).read()) ]
except IOError, e:
if e.errno == 2: # No such file or directory
# Silently ignore e.g. dangling symlinks