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