refactored registry methods to use the registry manager module
authorTony Mack <tmack@cs.princeton.edu>
Sun, 3 Jan 2010 21:13:29 +0000 (21:13 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Sun, 3 Jan 2010 21:13:29 +0000 (21:13 +0000)
sfa/managers/registry_manager_pl.py
sfa/methods/get_gid.py

index 5c70ee7..32dacec 100644 (file)
@@ -59,7 +59,7 @@ def get_credential(api, hrn, type, is_self=False):
 
     return new_cred.save_to_string(save_parents=True)
 
-def resolve(api, hrns, type=None, origin_hrn):
+def resolve(api, hrns, type=None, origin_hrn=None):
 
     # load all know registry names into a prefix tree and attempt to find
     # the longest matching prefix
index 65f71e5..66320e6 100644 (file)
@@ -34,16 +34,22 @@ class get_gid(Method):
     def call(self, cert, hrn, type):
       
         self.api.auth.verify_object_belongs_to_me(hrn)
-        certificate = Certificate(string=cert) 
-        table = GeniTable()
-        records = table.find({'hrn': hrn, 'type': type})
+
+        # 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, hrn, type, origin_hrn=hrn)
         if not records:
             raise RecordNotFound(hrn)
         record = records[0]
-        gidStr = record['gid']
-        gid = GID(string=gidStr)
-         
+
+        # 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