more consistency between API method names and corresponding manager implementation
[sfa.git] / sfa / methods / GetCredential.py
1 from sfa.util.xrn import urn_to_hrn
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.credential import Credential
5
6 class GetCredential(Method):
7     """
8     Retrive a credential for an object
9     If cred == None then the behavior reverts to GetSelfCredential
10
11     @param hrn human readable name of object (hrn or urn)
12     @param cred credential object specifying rights of the caller
13     @param type type of object (user | slice | node | authority )
14
15     @return the string representation of a credential object  
16     """
17
18     interfaces = ['registry']
19     
20     accepts = [
21         Mixed(Parameter(str, "Credential string"),
22               Parameter(type([str]), "List of credentials")), 
23         Parameter(str, "Human readable name (hrn or urn)"),
24         Mixed(Parameter(str, "Record type"),
25               Parameter(None, "Type not specified")),
26         ]
27
28     returns = Parameter(str, "String representation of a credential object")
29
30     def call(self, creds, xrn, type):
31     
32         if type:
33             hrn = urn_to_hrn(xrn)[0]
34         else:
35             hrn, type = urn_to_hrn(xrn)
36
37         # check creds
38         valid_creds = self.api.auth.checkCredentials(creds, 'getcredential')
39         self.api.auth.verify_object_belongs_to_me(hrn)
40
41         #log the call
42         origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn()
43         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name)) 
44
45         return self.api.manager.GetCredential(self.api, xrn, type)
46