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