improve server-side logging of exceptions
[sfa.git] / sfa / plc / api.py
index 8a2567d..79555c4 100644 (file)
@@ -10,6 +10,9 @@ import os
 import traceback
 import string
 import xmlrpclib
+
+import sfa.util.sfalogging
+import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 from sfa.trust.auth import Auth
 from sfa.util.config import *
 from sfa.util.faults import *
@@ -20,7 +23,6 @@ from sfa.trust.certificate import *
 from sfa.util.namespace import *
 from sfa.util.api import *
 from sfa.util.nodemanager import NodeManager
-from sfa.util.sfalogging import *
 try:
     from collections import defaultdict
 except:
@@ -105,7 +107,7 @@ class SfaAPI(BaseAPI):
 
         self.hrn = self.config.SFA_INTERFACE_HRN
         self.time_format = "%Y-%m-%d %H:%M:%S"
-        self.logger=get_sfa_logger()
+        self.logger=sfa.util.sfalogging.logger
 
     def getPLCShell(self):
         self.plauth = {'Username': self.config.SFA_PLC_USER,
@@ -124,11 +126,26 @@ class SfaAPI(BaseAPI):
         return shell
 
     def getCredential(self):
+        """
+        Retrun a valid credential for this interface. 
+        """
         if self.interface in ['registry']:
             return self.getCredentialFromLocalRegistry()
         else:
             return self.getCredentialFromRegistry()
-    
+
+    def getDelegatedCredential(self, creds):
+        """
+        Attempt to find a credential delegated to us in
+        the specified list of creds.
+        """
+        if creds and not isinstance(creds, list): 
+            creds = [creds]
+        delegated_creds = filter_creds_by_caller(creds,self.hrn)
+        if not delegated_creds:
+            return None
+        return delegated_creds[0]
     def getCredentialFromRegistry(self):
         """ 
         Get our credential from a remote registry 
@@ -620,13 +637,14 @@ class ComponentAPI(BaseAPI):
         """
         path = self.config.SFA_DATA_DIR
         config_dir = self.config.config_path
-        credfile = path + os.sep + 'node.cred'
+        cred_filename = path + os.sep + 'node.cred'
         try:
             credential = Credential(filename = cred_filename)
             return credential.save_to_string(save_parents=True)
         except IOError:
             node_pkey_file = config_dir + os.sep + "node.key"
             node_gid_file = config_dir + os.sep + "node.gid"
+            cert_filename = path + os.sep + 'server.cert'
             if not os.path.exists(node_pkey_file) or \
                not os.path.exists(node_gid_file):
                 self.get_node_key()
@@ -635,6 +653,7 @@ class ComponentAPI(BaseAPI):
             gid = GID(filename=node_gid_file)
             hrn = gid.get_hrn()
             # get credential from registry
+            cert_str = Certificate(filename=cert_filename).save_to_string(save_parents=True)
             registry = self.get_registry()
             cred = registry.get_self_credential(cert_str, 'node', hrn)
             Credential(string=cred).save_to_file(credfile, save_parents=True)