From: Tony Mack <tmack@paris.CS.Princeton.EDU>
Date: Wed, 4 Jan 2012 18:16:08 +0000 (-0500)
Subject: convert_public_key() should raise an exception instead for returning None
X-Git-Tag: sfa-2.0-8~5
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b7d88cadf2469efa09d0e760379626d6c5ae6284;p=sfa.git

convert_public_key() should raise an exception instead for returning None
---

diff --git a/sfa/trust/certificate.py b/sfa/trust/certificate.py
index f0a2d71c..595812b5 100644
--- a/sfa/trust/certificate.py
+++ b/sfa/trust/certificate.py
@@ -89,7 +89,7 @@ def convert_public_key(key):
 
     # we can only convert rsa keys
     if "ssh-dss" in key:
-        return None
+        raise Exception, "keyconvert: dss keys are not supported"  
 
     (ssh_f, ssh_fn) = tempfile.mkstemp()
     ssl_fn = tempfile.mktemp()
@@ -103,20 +103,22 @@ def convert_public_key(key):
     # that it can be expected to see why it failed.
     # TODO: for production, cleanup the temporary files
     if not os.path.exists(ssl_fn):
-        return None
+        raise Exception, "keyconvert: generated certificate not found. keyconvert may have failed." 
 
     k = Keypair()
     try:
         k.load_pubkey_from_file(ssl_fn)
+        return k
     except:
         logger.log_exc("convert_public_key caught exception")
-        k = None
+        raise
+    finally:
+        # remove the temporary files
+        if os.path.exists(ssh_fn):
+            os.remove(ssh_fn)
+        if os.path.exists(ssl_fn):
+            os.remove(ssl_fn)
 
-    # remove the temporary files
-    os.remove(ssh_fn)
-    os.remove(ssl_fn)
-
-    return k
 
 ##
 # Public-private key pairs are implemented by the Keypair class.