53a687f36cd1efa8e20a8fe9d5045614b2b9d814
[sfa.git] / sfa / methods / get_trusted_certs.py
1 from sfa.util.method import Method
2
3 from sfa.trust.auth import Auth
4 from sfa.trust.credential import Credential
5
6 from sfa.storage.parameter import Parameter, Mixed
7
8
9 class get_trusted_certs(Method):
10     """
11     @param cred credential string specifying the rights of the caller
12     @return list of gid strings  
13     """
14
15     interfaces = ['registry', 'aggregate', 'slicemgr']
16
17     accepts = [
18         Mixed(Parameter(str, "Credential string"),
19               Parameter(None, "Credential not specified"))
20     ]
21
22     returns = Parameter(type([str]), "List of GID strings")
23
24     def call(self, cred=None):
25         # If cred is not specified just return the gid for this interface.
26         # This is true when when a peer is attempting to initiate federation
27         # with this interface
28         self.api.logger.debug("get_trusted_certs: %r" % cred)
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