c4aeadc94894d72e853134472fe5698cfc5a8a0a
[sfa.git] / sfa / methods / resolve.py
1 ### $Id$
2 ### $URL$
3 import traceback
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.debug import log
9 from sfa.trust.credential import Credential
10 from sfa.util.record import SfaRecord
11
12 class resolve(Method):
13     """
14     Resolve a record.
15
16     @param cred credential string authorizing the caller
17     @param hrn human readable name to resolve (hrn or urn) 
18     @return a list of record dictionaries or empty list     
19     """
20
21     interfaces = ['registry']
22     
23     accepts = [
24         Parameter(str, "Credential string"),
25         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
26               Parameter(list, "List of Human readable names ([hrn])"))  
27         ]
28
29     returns = [SfaRecord]
30     
31     def call(self, cred, xrn, origin_hrn=None):
32         user_cred = Credential(string=cred)
33         hrn = urn_to_hrn(xrn)[0]
34
35         #log the call
36         if not origin_hrn:
37             origin_hrn = user_cred.get_gid_caller().get_hrn()
38         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
39  
40         # validate the cred
41         self.api.auth.check(cred, 'resolve')
42         # send the call to the right manager
43         manager_base = 'sfa.managers'
44         mgr_type = self.api.config.SFA_REGISTRY_TYPE
45         manager_module = manager_base + ".registry_manager_%s" % mgr_type
46         manager = __import__(manager_module, fromlist=[manager_base])
47         return manager.resolve(self.api, xrn, origin_hrn=origin_hrn)
48
49
50