54b74082f59a1f0cf1b002d3f3c23877fbc4d561
[sfa.git] / sfa / methods / List.py
1
2 from sfa.util.xrn import urn_to_hrn
3 from sfa.util.method import Method
4
5 from sfa.trust.credential import Credential
6
7 from sfa.storage.parameter import Parameter, Mixed
8
9
10 class List(Method):
11     """
12     List the records in an authority. 
13
14     @param cred credential string specifying the rights of the caller
15     @param hrn human readable name of authority to list (hrn or urn)
16     @return list of record dictionaries         
17     """
18     interfaces = ['registry']
19
20     accepts = [
21         Parameter(str, "Human readable name (hrn or urn)"),
22         Mixed(Parameter(str, "Credential string"),
23               Parameter(type([str]), "List of credentials")),
24     ]
25
26     # xxx used to be [SfaRecord]
27     returns = [Parameter(dict, "registry record")]
28
29     def call(self, xrn, creds, options=None):
30         if options is None:
31             options = {}
32         hrn, type = urn_to_hrn(xrn)
33         valid_creds = self.api.auth.checkCredentials(creds, 'list')
34
35         # log the call
36         origin_hrn = Credential(
37             string=valid_creds[0]).get_gid_caller().get_hrn()
38         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
39                              (self.api.interface, origin_hrn, hrn, self.name))
40
41         return self.api.manager.List(self.api, xrn, options=options)