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