merged namespace
[sfa.git] / sfa / methods / GetCredential.py
1 #
2 from sfa.trust.credential import *
3 from sfa.trust.rights import *
4 from sfa.util.faults import *
5 from sfa.util.namespace import *
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.trust.credential import Credential
9
10 class GetCredential(Method):
11     """
12     Retrive a credential for an object
13     If cred == None then the behavior reverts to GetSelfCredential
14
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 )
18
19     @return the string representation of a credential object  
20     """
21
22     interfaces = ['registry']
23     
24     accepts = [
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")),
30         ]
31
32     returns = Parameter(str, "String representation of a credential object")
33
34     def call(self, creds, xrn, type):
35     
36         if type:
37             hrn = urn_to_hrn(xrn)[0]
38         else:
39             hrn, type = urn_to_hrn(xrn)
40
41         # check creds
42         valid_creds = self.api.auth.checkCredentials(creds, 'getcredential')
43         self.api.auth.verify_object_belongs_to_me(hrn)
44
45         #log the call
46         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
47         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name)) 
48
49         manager = self.api.get_interface_manager()
50         
51         return manager.get_credential(self.api, xrn, type)
52