Added 'checkCredentials' to auth.py. Made various other small fixes.
[sfa.git] / sfa / methods / Resolve.py
1 from sfa.util.faults import *
2 from sfa.util.namespace import *
3 from sfa.util.method import Method
4 from sfa.util.parameter import Parameter
5 from sfa.trust.credential import Credential
6
7 class Resolve(Method):
8     """
9     Lookup a URN and return information about the corresponding object.
10     @param slice_urn (string) URN of slice to renew
11     @param credentials ([string]) of credentials
12     
13     """
14     interfaces = ['registry']
15     accepts = [
16         Parameter(str, "URN"),
17         Parameter(type([str]), "List of credentials"),
18         ]
19     returns = Parameter(bool, "Success or Failure")
20
21     def call(self, xrn, creds):
22         for cred in creds:
23             try:
24                 self.api.auth.check(cred, 'resolve')
25                 # Make sure it's an authority and not a user
26                 if cred.get_gid_caller().get_type() != 'authority':
27                     raise 'NotAuthority'
28                 found = True
29                 break
30             except:
31                 continue
32                 
33         if not found:
34             raise InsufficientRights('Resolve: Credentials either did not verify, were no longer valid, or did not have appropriate privileges')
35         
36
37         manager_base = 'sfa.managers'
38
39         if self.api.interface in ['registry']:
40             mgr_type = self.api.config.SFA_REGISTRY_TYPE
41             manager_module = manager_base + ".registry_manager_%s" % mgr_type
42             manager = __import__(manager_module, fromlist=[manager_base])
43             return manager.Resolve(self.api, xrn, creds)
44                
45         return {}