added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / get_gid.py
index b6bf56a..630221d 100644 (file)
@@ -6,19 +6,20 @@
 #            raise ConnectionKeyGIDMismatch(gid.get_subject())
 
 from sfa.util.faults import *
 #            raise ConnectionKeyGIDMismatch(gid.get_subject())
 
 from sfa.util.faults import *
-from sfa.util.misc import *
+from sfa.util.namespace import *
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
 from sfa.trust.gid import GID
 from sfa.trust.certificate import Certificate
 from sfa.util.method import Method
 from sfa.util.parameter import Parameter, Mixed
 from sfa.trust.auth import Auth
 from sfa.trust.gid import GID
 from sfa.trust.certificate import Certificate
-from sfa.util.genitable import GeniTable
 
 class get_gid(Method):
     """
     Returns the client's gid if one exists      
 
     @param cert certificate string 
 
 class get_gid(Method):
     """
     Returns the client's gid if one exists      
 
     @param cert certificate string 
+    @param xrn human readable name (hrn or urn)  
+    @param type object type 
     @return client gid  
     """
 
     @return client gid  
     """
 
@@ -26,27 +27,37 @@ class get_gid(Method):
     
     accepts = [
         Parameter(str, "Certificate string"),
     
     accepts = [
         Parameter(str, "Certificate string"),
-        
-        Parameter(str, "Human readable name (hrn)")  
+        Parameter(str, "Human readable name (hrn or urn)"), 
+        Parameter(str, "Object type") 
         ]
 
         ]
 
-    returns = [Parameter(dict, "Aggregate interface information")]
+    returns = Parameter(str, "GID string")
     
     
-    def call(self, cert, hrn, type, requestHash):
-      
-        certificate = Certificate(string=cert) 
-        table = GeniTable()
-        records = table.find({'hrn': hrn, 'type': type})
+    def call(self, cert, xrn, type):
+     
+        # convert xrn to hrn     
+        if type:
+            hrn = urn_to_hrn(xrn)[0]
+        else:
+            hrn, type = urn_to_hrn(xrn)
+        self.api.auth.verify_object_belongs_to_me(hrn)
+
+        # resolve the record
+        manager_base = 'sfa.managers'
+        mgr_type = self.api.config.SFA_REGISTRY_TYPE
+        manager_module = manager_base + ".registry_manager_%s" % mgr_type
+        manager = __import__(manager_module, fromlist=[manager_base])
+        records = manager.resolve(self.api, xrn, type, origin_hrn=hrn)
         if not records:
             raise RecordNotFound(hrn)
         record = records[0]
         if not records:
             raise RecordNotFound(hrn)
         record = records[0]
-        gidStr = record['gid']
-        gid = GID(string=gidStr)
-         
-        #if not certificate.is_pubkey(gid.get_pubkey()):
-        #    raise ConnectionKeyGIDMismatch(gid.get_subject())
-        
-        # authenticate the gid
-        self.api.auth.authenticateGid(gidStr, [cert, hrn, type], requestHash)
+
+        # make sure client's certificate is the gid's pub key 
+        gid = GID(string=record['gid'])
+        certificate = Certificate(string=cert) 
+        if not certificate.is_pubkey(gid.get_pubkey()):
+            raise ConnectionKeyGIDMismatch(gid.get_subject())
+
+        return record['gid'] 
         
         
-        return gidStr