minor correction to CM side
[sfa.git] / sfa / methods / get_gids.py
index 359a947..1273402 100644 (file)
@@ -6,13 +6,12 @@
 #            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.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
+from sfa.trust.credential import Credential
 
 class get_gids(Method):
     """
 
 class get_gids(Method):
     """
@@ -28,18 +27,31 @@ class get_gids(Method):
     
     accepts = [
         Parameter(str, "Certificate string"),
     
     accepts = [
         Parameter(str, "Certificate string"),
-        Mixed(Paramter(str, "Human readable name (hrn)"), 
-              Parameter([str], "List of Human readable names (hrn)")), 
-        Mixed(Parameter(str, "Request hash"),
-              Parameter(None, "Request hash not specified")) 
+        Mixed(Parameter(str, "Human readable name (hrn or xrn)"), 
+              Parameter(type([str]), "List of Human readable names (hrn or xrn)")) 
         ]
 
     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
     
         ]
 
     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
     
-    def call(self, cred, hrns, request_hash=None):
-        self.api.auth.authenticateCred(cred, [cred, hrns], request_hash)
+    def call(self, cred, xrns):
+        # validate the credential
         self.api.auth.check(cred, 'getgids')
         self.api.auth.check(cred, 'getgids')
-        table = GeniTable()
-        records = table.find({'hrn': [hrns]}, columns=['hrn','type','gid'])
-        
-        return records 
+        user_cred = Credential(string=cred)
+        origin_hrn = user_cred.get_gid_caller().get_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, xrns, None, origin_hrn=origin_hrn)
+        if not records:
+            raise RecordNotFound(hrns)
+
+        gids = []
+        allowed_fields =  ['hrn', 'type', 'gid']
+        for record in records:
+            for key in record.keys():
+                if key not in allowed_fields:
+                    del(record[key])
+        return records