2 from sfa.trust.rights import *
3 from sfa.util.faults import *
4 from sfa.util.xrn import urn_to_hrn
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.credential import Credential
9 class GetCredential(Method):
11 Retrive a credential for an object
12 If cred == None then the behavior reverts to GetSelfCredential
14 @param hrn human readable name of object (hrn or urn)
15 @param cred credential object specifying rights of the caller
16 @param type type of object (user | slice | node | authority )
18 @return the string representation of a credential object
21 interfaces = ['registry']
24 Mixed(Parameter(str, "Credential string"),
25 Parameter(type([str]), "List of credentials")),
26 Parameter(str, "Human readable name (hrn or urn)"),
27 Mixed(Parameter(str, "Record type"),
28 Parameter(None, "Type not specified")),
31 returns = Parameter(str, "String representation of a credential object")
33 def call(self, creds, xrn, type):
36 hrn = urn_to_hrn(xrn)[0]
38 hrn, type = urn_to_hrn(xrn)
41 valid_creds = self.api.auth.checkCredentials(creds, 'getcredential')
42 self.api.auth.verify_object_belongs_to_me(hrn)
45 origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
46 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
48 manager = self.api.get_interface_manager()
50 return manager.get_credential(self.api, xrn, type)