* tried to put some sense in the way things get logged, at least on server-side for now
[sfa.git] / sfa / methods / get_trusted_certs.py
1 from sfa.util.faults import *
2 from sfa.util.method import Method
3 from sfa.util.parameter import Parameter, Mixed
4 from sfa.trust.auth import Auth
5 from sfa.trust.credential import Credential
6
7 class get_trusted_certs(Method):
8     """
9     @param cred credential string specifying the rights of the caller
10     @return list of gid strings  
11     """
12
13     interfaces = ['registry', 'aggregate', 'slicemgr']
14     
15     accepts = [
16         Mixed(Parameter(str, "Credential string"),
17               Parameter(None, "Credential not specified"))
18         ]
19
20     returns = Parameter(type([str]), "List of GID strings")
21     
22     def call(self, cred = None):
23         # If cred is not specified just return the gid for this interface.
24         # This is true when when a peer is attempting to initiate federation
25         # with this interface 
26         sfaloging.logger.debug("get_trusted_certs: %r"%cred)
27         if not cred:
28             gid_strings = []
29             for gid in self.api.auth.trusted_cert_list:
30                 if gid.get_hrn() == self.api.config.SFA_INTERFACE_HRN:
31                     gid_strings.append(gid.save_to_string(save_parents=True))   
32             return gid_strings
33
34         # authenticate the cred
35         self.api.auth.check(cred, 'gettrustedcerts')
36         gid_strings = [gid.save_to_string(save_parents=True) for \
37                                 gid in self.api.auth.trusted_cert_list] 
38         
39         return gid_strings