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