fe61f12378a6d1bd7736842e1162fbca0fe779f4
[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 from geni.registry import Registries
8
9 class list(Method):
10     """
11     List the records in an authority. 
12
13     @param cred credential string specifying the rights of the caller
14     @param hrn human readable name of authority to list
15     @return list of record dictionaries         
16     """
17
18     interfaces = ['registry']
19     
20     accepts = [
21         Parameter(str, "Credential string"),
22         Parameter(str, "Human readable name (hrn)")
23         ]
24
25     returns = [GeniRecord]
26     
27     def call(self, cred, hrn):
28         
29         self.api.auth.check(cred, 'list')
30         # is this a foreign authority
31         if not hrn.startswith(self.api.hrn):
32             registries = Registries(self.api) 
33             credential = self.api.getCredential()
34             for registry in registries:
35                 if hrn.startswith(registry):
36                     records = registries[registry].list(credential, hrn)
37                     return records    
38
39         if not self.api.auth.hierarchy.auth_exists(hrn):
40             raise MissingAuthority(hrn)
41         table = self.api.auth.get_auth_table(hrn)   
42         records = table.list()
43         
44         return records