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