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