1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.sfalogging import logger
5 from sfa.trust.credential import Credential
7 from sfa.storage.parameter import Parameter, Mixed
10 class GetCredential(Method):
12 Retrive a credential for an object
13 If cred == None then the behavior reverts to GetSelfCredential
15 @param hrn human readable name of object (hrn or urn)
16 @param cred credential object specifying rights of the caller
17 @param type type of object (user | slice | node | authority )
19 @return the string representation of a credential object
22 interfaces = ['registry']
25 Mixed(Parameter(str, "Credential string"),
26 Parameter(type([str]), "List of credentials")),
27 Parameter(str, "Human readable name (hrn or urn)"),
28 Mixed(Parameter(str, "Record type"),
29 Parameter(None, "Type not specified")),
32 returns = Parameter(str, "String representation of a credential object")
34 def call(self, creds, xrn, type):
37 hrn = urn_to_hrn(xrn)[0]
39 hrn, type = urn_to_hrn(xrn)
42 valid_creds = self.api.auth.checkCredentials(creds, 'getcredential')
43 self.api.auth.verify_object_belongs_to_me(hrn)
46 origin_hrn = Credential(
47 string=valid_creds[0]).get_gid_caller().get_hrn()
48 logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
49 (self.api.interface, origin_hrn, hrn, self.name))
51 return self.api.manager.GetCredential(self.api, xrn, type, self.api.auth.client_gid.get_urn())