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