a little nicer wrt pep8
[sfa.git] / sfa / methods / GetGids.py
1 from sfa.util.faults import RecordNotFound
2 from sfa.util.method import Method
3
4 from sfa.trust.credential import Credential
5
6 from sfa.storage.parameter import Parameter, Mixed
7
8
9 class GetGids(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         Mixed(Parameter(str, "Human readable name (hrn or xrn)"),
23               Parameter(type([str]), "List of Human readable names (hrn or xrn)")),
24         Mixed(Parameter(str, "Credential string"),
25               Parameter(type([str]), "List of credentials")),
26     ]
27
28     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
29
30     def call(self, xrns, creds):
31         # validate the credential
32         valid_creds = self.api.auth.checkCredentials(creds, 'getgids')
33         # xxxpylintxxx origin_hrn is unused..
34         origin_hrn = Credential(
35             string=valid_creds[0]).get_gid_caller().get_hrn()
36
37         # resolve the record
38         records = self.api.manager.Resolve(self.api, xrns, details=False)
39         if not records:
40             raise RecordNotFound(xrns)
41
42         allowed_fields = ['hrn', 'type', 'gid']
43         for record in records:
44             for key in list(record.keys()):
45                 if key not in allowed_fields:
46                     del(record[key])
47         return records