a little nicer wrt pep8
[sfa.git] / sfa / methods / Register.py
1 from sfa.util.method import Method
2 from sfa.util.sfalogging import logger
3
4 from sfa.trust.credential import Credential
5
6 from sfa.storage.parameter import Parameter, Mixed
7
8
9 class Register(Method):
10     """
11     Register an 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 cred credential string
16     @param record_dict dictionary containing record fields
17
18     @return gid string representation
19     """
20
21     interfaces = ['registry']
22
23     accepts = [
24         Parameter(dict, "Record dictionary containing record fields"),
25         Mixed(Parameter(str, "Credential string"),
26               Parameter(type([str]), "List of credentials")),
27     ]
28
29     returns = Parameter(int, "String representation of gid object")
30
31     def call(self, record, creds):
32         # validate cred
33         valid_creds = self.api.auth.checkCredentials(creds, 'register')
34
35         # verify permissions
36         hrn = record.get('hrn', '')
37         self.api.auth.verify_object_permission(hrn)
38
39         # log the call
40         origin_hrn = Credential(
41             string=valid_creds[0]).get_gid_caller().get_hrn()
42         logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
43                     (self.api.interface, origin_hrn, hrn, self.name))
44
45         return self.api.manager.Register(self.api, record)