Added CreateGid() method to Registry interface
[sfa.git] / sfa / methods / CreateGid.py
1 ### $Id: register.py 16477 2010-01-05 16:31:37Z thierry $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/register.py $
3
4 from sfa.util.xrn import urn_to_hrn
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.credential import Credential
8
9 class CreateGid(Method):
10     """
11     Create a signed credential for the s object with the registry. In addition to being stored in the
12     SFA database, the appropriate records will also be created in the
13     PLC databases
14     
15     @param xrn urn or hrn of certificate owner
16     @param cert caller's certificate
17     @param cred credential string
18     
19     @return gid string representation
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Mixed(Parameter(str, "Credential string"),
26               Parameter(type([str]), "List of credentials")),
27         Parameter(str, "URN or HRN of certificate owner"),
28         Parameter(str, "Certificate string"),
29         ]
30
31     returns = Parameter(int, "String representation of gid object")
32     
33     def call(self, creds, xrn, cert=None):
34         # TODO: is there a better right to check for or is 'update good enough? 
35         valid_creds = self.api.auth.checkCredentials(creds, 'update')
36
37         # verify permissions
38         hrn, type = urn_to_hrn(xrn)
39         self.api.auth.verify_object_permission(hrn)
40
41         #log the call
42         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
43
44         # log
45         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
46         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrn, self.name))
47
48         manager = self.api.get_interface_manager()
49
50         return manager.create_gid(self.api, xrn, cert)