removed another bunch of references to geni
[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
16 class get_gids(Method):
17     """
18     Get a list of record information (hrn, gid and type) for 
19     the specified hrns.
20
21     @param cred credential string 
22     @param cert certificate string 
23     @return    
24     """
25
26     interfaces = ['registry']
27     
28     accepts = [
29         Parameter(str, "Certificate string"),
30         Mixed(Parameter(str, "Human readable name (hrn)"), 
31               Parameter(type([str]), "List of Human readable names (hrn)")) 
32         ]
33
34     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
35     
36     def call(self, cred, hrns):
37         # validate the credential
38         self.api.auth.check(cred, 'getgids')
39         user_cred = Credential(string=cred)
40         origin_hrn = user_cred.get_gid_caller().get_hrn()
41
42         # resolve the record
43         manager_base = 'sfa.managers'
44         mgr_type = self.api.config.SFA_REGISTRY_TYPE
45         manager_module = manager_base + ".registry_manager_%s" % mgr_type
46         manager = __import__(manager_module, fromlist=[manager_base])
47         records = manager.resolve(self.api, hrns, None, origin_hrn=origin_hrn)
48         if not records:
49             raise RecordNotFound(hrns)
50
51         gids = []
52         allowed_fields =  ['hrn', 'type', 'gid']
53         for record in records:
54             for key in record.keys():
55                 if key not in allowed_fields:
56                     del(record[key])
57         return records