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