added support for urn name format. urn is the default name format used over the wire
[sfa.git] / sfa / methods / list.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.util.faults import *
5 from sfa.util.namespace import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.util.record import SfaRecord
9 from sfa.trust.credential import Credential
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, "Credential string"),
23         Parameter(str, "Human readable name (hrn or urn)"),
24         Mixed(Parameter(str, "Human readable name of the original caller"),
25               Parameter(None, "Origin hrn not specified"))
26         ]
27
28     returns = [SfaRecord]
29     
30     def call(self, cred, xrn, origin_hrn=None):
31         hrn, type = urn_to_hrn(xrn)
32         user_cred = Credential(string=cred)
33         #log the call
34         if not origin_hrn:
35             origin_hrn = user_cred.get_gid_caller().get_hrn()
36         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
37        
38         # validate the cred 
39         self.api.auth.check(cred, 'list')
40         
41         # send the call to the right manager    
42         manager_base = 'sfa.managers'
43         mgr_type = self.api.config.SFA_REGISTRY_TYPE
44         manager_module = manager_base + ".registry_manager_%s" % mgr_type
45         manager = __import__(manager_module, fromlist=[manager_base])
46         return manager.list(self.api, xrn)