8f57354600d6d998c9757f170e6b1dbefa3da379
[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
8 class Register(Method):
9     """
10     Register an object with the registry. In addition to being stored in the
11     SFA database, the appropriate records will also be created in the
12     PLC databases
13
14     @param cred credential string
15     @param record_dict dictionary containing record fields
16
17     @return gid string representation
18     """
19
20     interfaces = ['registry']
21
22     accepts = [
23         Parameter(dict, "Record dictionary containing record fields"),
24         Mixed(Parameter(str, "Credential string"),
25               Parameter(type([str]), "List of credentials")),
26     ]
27
28     returns = Parameter(int, "String representation of gid object")
29
30     def call(self, record, creds):
31         # validate cred
32         valid_creds = self.api.auth.checkCredentials(creds, 'register')
33
34         # verify permissions
35         hrn = record.get('hrn', '')
36         self.api.auth.verify_object_permission(hrn)
37
38         # log the call
39         origin_hrn = Credential(
40             string=valid_creds[0]).get_gid_caller().get_hrn()
41         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
42                              (self.api.interface, origin_hrn, hrn, self.name))
43
44         return self.api.manager.Register(self.api, record)