initial checkin of get_gid method
[sfa.git] / sfa / methods / get_gid.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_gid(Method):
18     """
19     Returns the client's gid if one exists      
20
21     @param cert certificate string 
22     @return client gid  
23     """
24
25     interfaces = ['registry']
26     
27     accepts = [
28         Parameter(str, "Certificate string"),
29         
30         Parameter(str, "Human readable name (hrn)")  
31         ]
32
33     returns = [Parameter(dict, "Aggregate interface information")]
34     
35     def call(self, cert, hrn, type, requestHash):
36       
37         certificate = Certificate(string=cert) 
38         table = GeniTable()
39         records = table.find({'hrn': hrn, 'type': type})
40         if not records:
41             raise RecordNotFound(hrn)
42         record = records[0]
43         gidStr = record['gid']
44         gid = GID(string=gidStr)
45          
46         #if not certificate.is_pubkey(gid.get_pubkey()):
47         #    raise ConnectionKeyGIDMismatch(gid.get_subject())
48         
49         # authenticate the gid
50         self.api.auth.authenticateGid(gidStr, [cert, hrn, type], requestHash)
51         
52         return gidStr