summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-12-09 11:10:24 -0600
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2015-02-18 08:24:24 -0600
commit89e7afbf74ffbbb54dd892bf2c4245aedee2a832 (patch)
treeed4623b5c6e39d80c132e9f21f3d4804cabd93be /src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py
parent64b458b380620f84843b1841b441745a0984946f (diff)
downloadbcfg2-89e7afbf74ffbbb54dd892bf2c4245aedee2a832.tar.gz
bcfg2-89e7afbf74ffbbb54dd892bf2c4245aedee2a832.tar.bz2
bcfg2-89e7afbf74ffbbb54dd892bf2c4245aedee2a832.zip
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.
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py33
1 files changed, 14 insertions, 19 deletions
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