a little nicer wrt pep8
[sfa.git] / sfa / methods / get_trusted_certs.py
1 from sfa.util.method import Method
2 from sfa.util.sfalogging import logger
3
4 from sfa.trust.auth import Auth
5 from sfa.trust.credential import Credential
6
7 from sfa.storage.parameter import Parameter, Mixed
8
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']
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         logger.debug("get_trusted_certs: %r" % 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