From 89e7afbf74ffbbb54dd892bf2c4245aedee2a832 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 9 Dec 2014 11:10:24 -0600 Subject: Remove blanket excepts from plugins and lint This removes most blanket except: clauses from all plugins, including the base plugin libraries, and bcfg2-lint. The few that remain should all be necessary. Most of the changes were quite minor, but this did require some restructuring of the CfgPrivateKeyCreator; as a result, the tests for that module were rewritten. --- .../Server/Plugins/Cfg/CfgPrivateKeyCreator.py | 33 +++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py index 8cc3f7b21..43035b410 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py @@ -47,7 +47,7 @@ class CfgPrivateKeyCreator(XMLCfgCreator): the given client metadata, and may be obtained by doing ``self.XMLMatch(metadata)`` :type spec: lxml.etree._Element - :returns: string - The filename of the private key + :returns: tuple - (private key data, public key data) """ if spec is None: spec = self.XMLMatch(metadata) @@ -91,10 +91,9 @@ class CfgPrivateKeyCreator(XMLCfgCreator): "with errors: %s" % (filename, metadata.hostname, result.stderr)) - return filename - except: + return (open(filename).read(), open(filename + ".pub").read()) + finally: shutil.rmtree(tempdir) - raise # pylint: disable=W0221 def create_data(self, entry, metadata): @@ -109,21 +108,17 @@ class CfgPrivateKeyCreator(XMLCfgCreator): """ spec = self.XMLMatch(metadata) specificity = self.get_specificity(metadata) - filename = self._gen_keypair(metadata, spec) + privkey, pubkey = self._gen_keypair(metadata, spec) - try: - # write the public key, stripping the comment and - # replacing it with a comment that specifies the filename. - kdata = open(filename + ".pub").read().split()[:2] - kdata.append(self.pubkey_creator.get_filename(**specificity)) - pubkey = " ".join(kdata) + "\n" - self.pubkey_creator.write_data(pubkey, **specificity) + # write the public key, stripping the comment and + # replacing it with a comment that specifies the filename. + kdata = pubkey.split()[:2] + kdata.append(self.pubkey_creator.get_filename(**specificity)) + pubkey = " ".join(kdata) + "\n" + self.pubkey_creator.write_data(pubkey, **specificity) - # encrypt the private key, write to the proper place, and - # return it - privkey = open(filename).read() - self.write_data(privkey, **specificity) - return privkey - finally: - shutil.rmtree(os.path.dirname(filename)) + # encrypt the private key, write to the proper place, and + # return it + self.write_data(privkey, **specificity) + return privkey # pylint: enable=W0221 -- cgit v1.2.3-1-g7c22