avoid as much as possible accessing logger through class instances, whenever that...
[sfa.git] / sfa / methods / Update.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
7
8
9 class Update(Method):
10     """
11     Update an object in the registry. Currently, this only updates the
12     PLC information associated with the record. The SFA fields (name, type,
13     GID) are fixed.
14
15     @param cred credential string specifying rights of the caller
16     @param record a record dictionary to be updated
17
18     @return 1 if successful, faults otherwise
19     """
20
21     interfaces = ['registry']
22
23     accepts = [
24         Parameter(dict, "Record dictionary to be updated"),
25         Parameter(str, "Credential string"),
26     ]
27
28     returns = Parameter(int, "1 if successful")
29
30     def call(self, record_dict, creds):
31         # validate the cred
32         valid_creds = self.api.auth.checkCredentials(creds, "update")
33
34         # verify permissions
35         hrn = record_dict.get('hrn', '')
36         self.api.auth.verify_object_permission(hrn)
37
38         # log
39         origin_hrn = Credential(
40             string=valid_creds[0]).get_gid_caller().get_hrn()
41         logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
42                     (self.api.interface, origin_hrn, hrn, self.name))
43
44         return self.api.manager.Update(self.api, record_dict)