c11c5671bd108c8ec60e407617ceb2c2105b7701
[sfa.git] / sfa / methods / get_credential.py
1 ### $Id$
2 ### $URL$
3
4 from sfa.trust.credential import *
5 from sfa.trust.rights import *
6 from sfa.util.faults import *
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.util.debug import log
10
11 class get_credential(Method):
12     """
13     Retrive a credential for an object
14     If cred == Nonee then the behavior reverts to get_self_credential
15
16     @param cred credential object specifying rights of the caller
17     @param type type of object (user | slice | sa | ma | node)
18     @param hrn human readable name of object
19
20     @return the string representation of a credential object  
21     """
22
23     interfaces = ['registry']
24     
25     accepts = [
26         Mixed(Parameter(str, "credential"),
27               Parameter(None, "No credential")),  
28         Parameter(str, "Human readable name (hrn)")
29         ]
30
31     returns = Parameter(str, "String representation of a credential object")
32
33     def call(self, cred, type, hrn):
34
35         self.api.auth.check(cred, 'getcredential')
36         self.api.auth.verify_object_belongs_to_me(hrn)
37
38         # send the call to the right manager
39         manager_base = 'sfa.managers'
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.get_credential(self.api, hrn, type)