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