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