trimmed useless imports, unstarred all imports
[sfa.git] / sfa / methods / Register.py
1 from sfa.util.method import Method
2 from sfa.util.parameter import Parameter, Mixed
3 from sfa.trust.credential import Credential
4
5 class Register(Method):
6     """
7     Register an object with the registry. In addition to being stored in the
8     SFA database, the appropriate records will also be created in the
9     PLC databases
10     
11     @param cred credential string
12     @param record_dict dictionary containing record fields
13     
14     @return gid string representation
15     """
16
17     interfaces = ['registry']
18     
19     accepts = [
20         Parameter(dict, "Record dictionary containing record fields"),
21         Mixed(Parameter(str, "Credential string"),
22               Parameter(type([str]), "List of credentials")),
23         ]
24
25     returns = Parameter(int, "String representation of gid object")
26     
27     def call(self, record, creds):
28         # validate cred    
29         valid_creds = self.api.auth.checkCredentials(creds, 'register')
30         
31         # verify permissions
32         hrn = record.get('hrn', '')
33         self.api.auth.verify_object_permission(hrn)
34
35         #log the call
36         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
37         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
38         
39         manager = self.api.get_interface_manager()
40
41         return manager.register(self.api, record)