trimmed useless imports, unstarred all imports
[sfa.git] / sfa / methods / GetGids.py
1 from sfa.util.faults import RecordNotFound
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.credential import Credential
5
6 class GetGids(Method):
7     """
8     Get a list of record information (hrn, gid and type) for 
9     the specified hrns.
10
11     @param cred credential string 
12     @param cert certificate string 
13     @return    
14     """
15
16     interfaces = ['registry']
17     
18     accepts = [
19         Mixed(Parameter(str, "Human readable name (hrn or xrn)"), 
20               Parameter(type([str]), "List of Human readable names (hrn or xrn)")),
21         Mixed(Parameter(str, "Credential string"),
22               Parameter(type([str]), "List of credentials")), 
23         ]
24
25     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
26     
27     def call(self, xrns, creds):
28         # validate the credential
29         valid_creds = self.api.auth.checkCredentials(creds, 'getgids')
30         # xxxpylintxxx origin_hrn is unused..
31         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
32         
33         # resolve the record
34         manager = self.api.get_interface_manager()
35         records = manager.resolve(self.api, xrns, full = False)
36         if not records:
37             raise RecordNotFound(xrns)
38
39         allowed_fields =  ['hrn', 'type', 'gid']
40         for record in records:
41             for key in record.keys():
42                 if key not in allowed_fields:
43                     del(record[key])
44         return records