4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.util.record import GeniRecord
9 from sfa.util.genitable import GeniTable
10 from sfa.server.registry import Registries
11 from sfa.util.prefixTree import prefixTree
12 from sfa.trust.credential import Credential
16 List the records in an authority.
18 @param cred credential string specifying the rights of the caller
19 @param hrn human readable name of authority to list
20 @return list of record dictionaries
22 interfaces = ['registry']
25 Parameter(str, "Credential string"),
26 Parameter(str, "Human readable name (hrn)"),
27 Mixed(Parameter(str, "Human readable name of the original caller"),
28 Parameter(None, "Origin hrn not specified"))
31 returns = [GeniRecord]
33 def call(self, cred, hrn, origin_hrn=None):
34 user_cred = Credential(string=cred)
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))
41 self.api.auth.check(cred, 'list')
43 # load all know registry names into a prefix tree and attempt to find
44 # the longest matching prefix
46 registries = Registries(self.api)
47 hrns = registries.keys()
50 registry_hrn = tree.best_match(hrn)
52 #if there was no match then this record belongs to an unknow registry
54 raise MissingAuthority(hrn)
56 # if the best match (longest matching hrn) is not the local registry,
58 if registry_hrn != self.api.hrn:
59 credential = self.api.getCredential()
60 record_list = registries[registry_hrn].list(credential, hrn, origin_hrn)
61 records = [GeniRecord(dict=record).as_dict() for record in record_list]
66 # if we still havnt found the record yet, try the local registry
67 if not self.api.auth.hierarchy.auth_exists(hrn):
68 raise MissingAuthority(hrn)
71 records = table.find({'authority': hrn})