more consistency between API method names and corresponding manager implementation
[sfa.git] / sfa / methods / Resolve.py
1 import types
2
3 from sfa.util.xrn import Xrn, urn_to_hrn
4 from sfa.util.method import Method
5 from sfa.util.parameter import Parameter, Mixed
6 from sfa.trust.credential import Credential
7 from sfa.util.record import SfaRecord
8
9 class Resolve(Method):
10     """
11     Resolve a record.
12
13     @param cred credential string authorizing the caller
14     @param hrn human readable name to resolve (hrn or urn) 
15     @return a list of record dictionaries or empty list     
16     """
17
18     interfaces = ['registry']
19     
20     accepts = [
21         Mixed(Parameter(str, "Human readable name (hrn or urn)"),
22               Parameter(list, "List of Human readable names ([hrn])")),
23         Mixed(Parameter(str, "Credential string"),
24               Parameter(list, "List of credentials)"))  
25         ]
26
27     returns = [SfaRecord]
28     
29     def call(self, xrns, creds):
30         type = None
31         if not isinstance(xrns, types.ListType):
32             type = Xrn(xrns).get_type()
33             xrns=[xrns]
34         hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
35         #find valid credentials
36         valid_creds = self.api.auth.checkCredentials(creds, 'resolve')
37
38         #log the call
39         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
40         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrns, self.name))
41  
42         # send the call to the right manager
43         return self.api.manager.Resolve(self.api, xrns, type)
44