group db-related stuff in sfa/storage
[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 class GetGids(Method):
9     """
10     Get a list of record information (hrn, gid and type) for 
11     the specified hrns.
12
13     @param cred credential string 
14     @param cert certificate string 
15     @return    
16     """
17
18     interfaces = ['registry']
19     
20     accepts = [
21         Mixed(Parameter(str, "Human readable name (hrn or xrn)"), 
22               Parameter(type([str]), "List of Human readable names (hrn or xrn)")),
23         Mixed(Parameter(str, "Credential string"),
24               Parameter(type([str]), "List of credentials")), 
25         ]
26
27     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
28     
29     def call(self, xrns, creds):
30         # validate the credential
31         valid_creds = self.api.auth.checkCredentials(creds, 'getgids')
32         # xxxpylintxxx origin_hrn is unused..
33         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
34         
35         # resolve the record
36         records = self.api.manager.Resolve(self.api, xrns, full = False)
37         if not records:
38             raise RecordNotFound(xrns)
39
40         allowed_fields =  ['hrn', 'type', 'gid']
41         for record in records:
42             for key in record.keys():
43                 if key not in allowed_fields:
44                     del(record[key])
45         return records