fix bugs
[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.misc import *
10 from sfa.util.method import Method
11 from sfa.util.parameter import Parameter, Mixed
12 from sfa.trust.auth import Auth
13 from sfa.trust.gid import GID
14 from sfa.trust.certificate import Certificate
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([str], "List of Human readable names (hrn)")), 
33         Mixed(Parameter(str, "Request hash"),
34               Parameter(None, "Request hash not specified")) 
35         ]
36
37     returns = [Parameter(dict, "Dictionary of gids keyed on hrn")]
38     
39     def call(self, cred, hrns, request_hash=None):
40         self.api.auth.authenticateCred(cred, [cred, hrns], request_hash)
41         self.api.auth.check(cred, 'getgids')
42         table = GeniTable()
43         if not isinstance(hrns, list):
44             hrns = [hrns]
45         records = table.find({'hrn': hrns}, columns=['hrn','type','gid'])
46         
47         return records