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 from sfa.trust.credential import Credential
13 class get_credential(Method):
15 Retrive a credential for an object
16 If cred == Nonee then the behavior reverts to get_self_credential
18 @param cred credential object specifying rights of the caller
19 @param type type of object (user | slice | sa | ma | node)
20 @param hrn human readable name of object (hrn or urn)
22 @return the string representation of a credential object
25 interfaces = ['registry']
28 Mixed(Parameter(str, "credential"),
29 Parameter(None, "No credential")),
30 Parameter(str, "Human readable name (hrn or urn)")
33 returns = Parameter(str, "String representation of a credential object")
35 def call(self, cred, type, xrn, origin_hrn=None):
37 hrn = urn_to_hrn(xrn)[0]
39 hrn, type = urn_to_hrn(xrn)
43 origin_hrn = Credential(string=cred).get_gid_caller().get_hrn()
44 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
45 self.api.auth.check(cred, 'getcredential')
46 self.api.auth.verify_object_belongs_to_me(hrn)
48 # send the call to the right manager
49 manager_base = 'sfa.managers'
50 mgr_type = self.api.config.SFA_REGISTRY_TYPE
51 manager_module = manager_base + ".registry_manager_%s" % mgr_type
52 manager = __import__(manager_module, fromlist=[manager_base])
53 return manager.get_credential(self.api, xrn, type)