The code that loads the password.conf in PKIInstance.load() has been converted into a general purpose load_properties() method. A corresponding store_properties() method has been added as well.
Pushed to master under trivial rule. -- Endi S. Dewata
>From 7810a55d0b967ff5355312e952fc4c7314a45f35 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" <edew...@redhat.com> Date: Wed, 1 Mar 2017 07:08:11 +0100 Subject: [PATCH] Refactored PKIInstance.load(). The code that loads the password.conf in PKIInstance.load() has been converted into a general purpose load_properties() method. A corresponding store_properties() method has been added as well. --- base/common/python/pki/util.py | 33 +++++++++++++++++++++++++++++++ base/server/python/pki/server/__init__.py | 14 +------------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py index 8a75ff6f500f86aa0e442577e48daf6913251d75..68118f439c76ad014a172dfbcba843692184c249 100644 --- a/base/common/python/pki/util.py +++ b/base/common/python/pki/util.py @@ -143,6 +143,39 @@ def customize_file(input_file, output_file, params): outfile.write(line) +def load_properties(filename, properties): + + with open(filename) as f: + + lines = f.read().splitlines() + + for index, line in enumerate(lines): + + line = line.strip() + + if not line or line.startswith('#'): + continue + + parts = line.split('=', 1) + + if len(parts) < 2: + raise Exception('Missing delimiter in %s line %d' % + (filename, index + 1)) + + name = parts[0].strip() + value = parts[1].strip() + properties[name] = value + + +def store_properties(filename, properties): + + with open(filename, 'w') as f: + + for name, value in properties.items(): + line = '%s=%s\n' % (name, value) + f.write(line) + + def copytree(src, dst, symlinks=False, ignore=None): """ Recursively copy a directory tree using copy2(). diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py index d556312a7c0f87cfeda025abd9d6841939d220f1..70734c3db778167ba867deecdf21473de5012671 100644 --- a/base/server/python/pki/server/__init__.py +++ b/base/server/python/pki/server/__init__.py @@ -568,19 +568,7 @@ class PKIInstance(object): # load passwords self.passwords.clear() if os.path.exists(self.password_conf): - - lines = open(self.password_conf).read().splitlines() - - for index, line in enumerate(lines): - if not line or line.startswith('#'): - continue - parts = line.split('=', 1) - if len(parts) < 2: - raise Exception('Missing delimiter in %s line %d' % - (self.password_conf, index + 1)) - name = parts[0] - value = parts[1] - self.passwords[name] = value + pki.util.load_properties(self.password_conf, self.passwords) self.load_external_certs(self.external_certs_conf) -- 2.5.5
_______________________________________________ Pki-devel mailing list Pki-devel@redhat.com https://www.redhat.com/mailman/listinfo/pki-devel