added support for urn name format. urn is the default name format used over the wire
[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.namespace import *
8 from sfa.util.method import Method
9 from sfa.util.parameter import Parameter, Mixed
10 from sfa.util.debug import log
11
12 class get_credential(Method):
13     """
14     Retrive a credential for an object
15     If cred == Nonee then the behavior reverts to get_self_credential
16
17     @param cred credential object specifying rights of the caller
18     @param type type of object (user | slice | sa | ma | node)
19     @param hrn human readable name of object (hrn or urn)
20
21     @return the string representation of a credential object  
22     """
23
24     interfaces = ['registry']
25     
26     accepts = [
27         Mixed(Parameter(str, "credential"),
28               Parameter(None, "No credential")),  
29         Parameter(str, "Human readable name (hrn or urn)")
30         ]
31
32     returns = Parameter(str, "String representation of a credential object")
33
34     def call(self, cred, type, xrn):
35         if type:
36             hrn = urn_to_hrn(xrn)[0]
37         else:
38             hrn, type = urn_to_hrn(xrn)
39
40         self.api.auth.check(cred, 'getcredential')
41         self.api.auth.verify_object_belongs_to_me(hrn)
42
43         # send the call to the right manager
44         manager_base = 'sfa.managers'
45         mgr_type = self.api.config.SFA_REGISTRY_TYPE
46         manager_module = manager_base + ".registry_manager_%s" % mgr_type
47         manager = __import__(manager_module, fromlist=[manager_base])
48         return manager.get_credential(self.api, xrn, type)