apply fix from 0.9-12 branch
[sfa.git] / sfa / methods / get_trusted_certs.py
1
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/reset_slices.py $
3
4 from sfa.util.faults import *
5 from sfa.util.method import Method
6 from sfa.util.parameter import Parameter, Mixed
7 from sfa.trust.auth import Auth
8 from sfa.trust.credential import Credential
9
10 class get_trusted_certs(Method):
11     """
12     @param cred credential string specifying the rights of the caller
13     @return list of gid strings  
14     """
15
16     interfaces = ['registry', 'aggregate', 'slicemgr']
17     
18     accepts = [
19         Mixed(Parameter(str, "Credential string"),
20               Parameter(None, "Credential not specified"))
21         ]
22
23     returns = Parameter(type([str]), "List of GID strings")
24     
25     def call(self, cred = None):
26         # If cred is not specified just return the gid for this interface.
27         # This is true when when a peer is attempting to initiate federation
28         # with this interface 
29         print cred
30         if not cred:
31             gid_strings = []
32             for gid in self.api.auth.trusted_cert_list:
33                 if gid.get_hrn() == self.api.config.SFA_INTERFACE_HRN:
34                     gid_strings.append(gid.save_to_string(save_parents=True))   
35             return gid_strings
36
37         # authenticate the cred
38         self.api.auth.check(cred, 'gettrustedcerts')
39         gid_strings = [gid.save_to_string(save_parents=True) for \
40                                 gid in self.api.auth.trusted_cert_list] 
41         
42         return gid_strings