should check permissions in method class not manager class
[sfa.git] / sfa / methods / Update.py
1 ### $Id: update.py 16477 2010-01-05 16:31:37Z thierry $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/update.py $
3
4 import time
5 from sfa.util.faults import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.credential import Credential
9
10 class Update(Method):
11     """
12     Update an object in the registry. Currently, this only updates the
13     PLC information associated with the record. The SFA fields (name, type,
14     GID) are fixed.
15     
16     @param cred credential string specifying rights of the caller
17     @param record a record dictionary to be updated
18
19     @return 1 if successful, faults otherwise 
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
25         Parameter(dict, "Record dictionary to be updated"),
26         Parameter(str, "Credential string"),
27         ]
28
29     returns = Parameter(int, "1 if successful")
30     
31     def call(self, record_dict, creds):
32         # validate the cred
33         valid_creds = self.api.auth.checkCredentials(creds, "update")
34         
35         # verify permissions 
36         api.auth.verify_object_permission(record.get('hrn', ''))
37     
38         # log
39         origin_hrn = Credential(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"%(self.api.interface, origin_hrn, None, self.name))
41        
42         manager = self.api.get_interface_manager()
43  
44         return manager.update(self.api, record_dict)
45