1 from sfa.util.xrn import Xrn, urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.sfalogging import logger
5 from sfa.trust.credential import Credential
7 from sfa.storage.parameter import Parameter, Mixed
10 class Resolve(Method):
14 @param cred credential string authorizing the caller
15 @param hrn human readable name to resolve (hrn or urn)
16 @return a list of record dictionaries or empty list
19 interfaces = ['registry']
21 # should we not accept an optional 'details' argument ?
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 Parameter(dict, "options"),
30 # xxx used to be [SfaRecord]
31 returns = [Parameter(dict, "registry record")]
33 def call(self, xrns, creds, options=None):
36 # use details=False by default, only when explicitly specified do we want
37 # to mess with the testbed details
38 if 'details' in options:
39 details = options['details']
43 if not isinstance(xrns, list):
44 type = Xrn(xrns).get_type()
46 hrns = [urn_to_hrn(xrn)[0] for xrn in xrns]
47 # find valid credentials
48 valid_creds = self.api.auth.checkCredentials(creds, 'resolve')
51 origin_hrn = Credential(
52 string=valid_creds[0]).get_gid_caller().get_hrn()
53 logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
54 (self.api.interface, origin_hrn, hrns, self.name))
56 # send the call to the right manager
57 return self.api.manager.Resolve(self.api, xrns, type, details=details)