a136abfc3b5b50982d236552baab168a71e15179
[sfa.git] / geni / methods / list.py
1 from geni.util.faults import *
2 from geni.util.excep import *
3 from geni.util.method import Method
4 from geni.util.parameter import Parameter, Mixed
5 from geni.util.auth import Auth
6 from geni.util.record import GeniRecord
7
8 class list(Method):
9     """
10     List the records in an authority. 
11
12     @param cred credential string specifying the rights of the caller
13     @param hrn human readable name of authority to list
14     @return list of record dictionaries         
15     """
16
17     interfaces = ['registry']
18     
19     accepts = [
20         Parameter(str, "credential"),
21         Parameter(str, "Human readable name (hrn)")
22         ]
23
24     returns = [GeniRecord]
25     
26     def call(self, cred, hrn):
27         
28         self.api.auth.check(cred, 'list')
29         # is this a foreign authority
30         if not hrn.startswith(self.api.hrn):
31             for registry in self.api.registries:
32                 if hrn.startswith(registry):
33                     records = self.api.registries[registry].list(self.api.credential, hrn)
34                     return records    
35
36         if not self.api.auth.hierarchy.auth_exists(hrn):
37             raise MissingAuthority(hrn)
38         table = self.api.auth.get_auth_table(hrn)   
39         records = table.list()
40         
41         return records