refactored registry methods to use the registry manager module
[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.util.genitable import GeniTable
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         table = GeniTable()
40         if not isinstance(hrns, list):
41             hrns = [hrns]
42         records = table.find({'hrn': hrns}, columns=['hrn','type','gid'])
43         
44         return records