removed another bunch of references to geni
[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.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
15 class get_gid(Method):
16     """
17     Returns the client's gid if one exists      
18
19     @param cert certificate string 
20     @return client gid  
21     """
22
23     interfaces = ['registry']
24     
25     accepts = [
26         Parameter(str, "Certificate string"),
27         Parameter(str, "Human readable name (hrn)"), 
28         Parameter(str, "Object type") 
29         ]
30
31     returns = Parameter(str, "GID string")
32     
33     def call(self, cert, hrn, type):
34       
35         self.api.auth.verify_object_belongs_to_me(hrn)
36
37         # resolve the record
38         manager_base = 'sfa.managers'
39         mgr_type = self.api.config.SFA_REGISTRY_TYPE
40         manager_module = manager_base + ".registry_manager_%s" % mgr_type
41         manager = __import__(manager_module, fromlist=[manager_base])
42         records = manager.resolve(self.api, hrn, type, origin_hrn=hrn)
43         if not records:
44             raise RecordNotFound(hrn)
45         record = records[0]
46
47         # make sure client's certificate is the gid's pub key 
48         gid = GID(string=record['gid'])
49         certificate = Certificate(string=cert) 
50         if not certificate.is_pubkey(gid.get_pubkey()):
51             raise ConnectionKeyGIDMismatch(gid.get_subject())
52
53         return record['gid'] 
54