replaceing resolve with Resolve
[sfa.git] / sfa / methods / GetGids.py
1 from sfa.util.faults import *
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.auth import Auth
5 from sfa.trust.gid import GID
6 from sfa.trust.certificate import Certificate
7 from sfa.trust.credential import Credential
8
9 class get_gids(Method):
10     """
11     Get a list of record information (hrn, gid and type) for 
12     the specified hrns.
13
14     @param cred credential string 
15     @param cert certificate string 
16     @return    
17     """
18
19     interfaces = ['registry']
20     
21     accepts = [
22         Parameter(str, "Certificate string"),
23         Mixed(Parameter(str, "Human readable name (hrn or xrn)"), 
24               Parameter(type([str]), "List of Human readable names (hrn or xrn)")) 
25         ]
26
27     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
28     
29     def call(self, cred, xrns):
30         # validate the credential
31         self.api.auth.check(cred, 'getgids')
32         user_cred = Credential(string=cred)
33         origin_hrn = user_cred.get_gid_caller().get_hrn()
34
35         # resolve the record
36         manager_base = 'sfa.managers'
37         mgr_type = self.api.config.SFA_REGISTRY_TYPE
38         manager_module = manager_base + ".registry_manager_%s" % mgr_type
39         manager = __import__(manager_module, fromlist=[manager_base])
40         records = manager.resolve(self.api, xrns, None, origin_hrn=origin_hrn, full = False)
41         if not records:
42             raise RecordNotFound(hrns)
43
44         gids = []
45         allowed_fields =  ['hrn', 'type', 'gid']
46         for record in records:
47             for key in record.keys():
48                 if key not in allowed_fields:
49                     del(record[key])
50         return records