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