review on imports & svn keywords
[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 from geni.registry import Registries
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
17     @return list of record dictionaries         
18     """
19
20     interfaces = ['registry']
21     
22     accepts = [
23         Parameter(str, "Credential string"),
24         Parameter(str, "Human readable name (hrn)")
25         ]
26
27     returns = [GeniRecord]
28     
29     def call(self, cred, hrn):
30         
31         self.api.auth.check(cred, 'list')
32         records = []
33         try:
34             if not self.api.auth.hierarchy.auth_exists(hrn):
35                 raise MissingAuthority(hrn)
36             table = self.api.auth.get_auth_table(hrn)   
37             records = table.list()
38         except MissingAuthority:
39             # is this a foreign authority
40             registries = Registries(self.api)
41             credential = self.api.getCredential()
42             for registry in registries:
43                 if hrn.startswith(registry) and registry not in [self.api.hrn]:
44                     record_list = registries[registry].list(credential, hrn)
45                     for record in record_list:
46                         records.append(record.as_dict()) 
47                     return records
48         
49         return records