get_trusted_certs is exposed by all interfaces (registry, aggregate and slicemgr)
[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([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         if not cred:
30             gid_strings = []
31             for gid in self.api.auth.trusted_cert_list:
32                 if gid.get_hrn() == self.api.config.SFA_INTERFACE_HRN:
33                     gid_strings.append[gid.save_to_string(save_parents=True)]   
34             return gid_strings
35
36         # authenticate the cred
37         self.api.auth.check(cred, 'gettrustedcerts')
38         gid_strings = [gid.save_to_string(save_parents=True) for \
39                                 gid in self.api.auth.trusted_cert_list] 
40         
41         return gid_strings