group db-related stuff in sfa/storage
[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 class get_trusted_certs(Method):
9     """
10     @param cred credential string specifying the rights of the caller
11     @return list of gid strings  
12     """
13
14     interfaces = ['registry', 'aggregate', 'slicemgr']
15     
16     accepts = [
17         Mixed(Parameter(str, "Credential string"),
18               Parameter(None, "Credential not specified"))
19         ]
20
21     returns = Parameter(type([str]), "List of GID strings")
22     
23     def call(self, cred = None):
24         # If cred is not specified just return the gid for this interface.
25         # This is true when when a peer is attempting to initiate federation
26         # with this interface 
27         self.api.logger.debug("get_trusted_certs: %r"%cred)
28         if not cred:
29             gid_strings = []
30             for gid in self.api.auth.trusted_cert_list:
31                 if gid.get_hrn() == self.api.config.SFA_INTERFACE_HRN:
32                     gid_strings.append(gid.save_to_string(save_parents=True))   
33             return gid_strings
34
35         # authenticate the cred
36         self.api.auth.check(cred, 'gettrustedcerts')
37         gid_strings = [gid.save_to_string(save_parents=True) for \
38                                 gid in self.api.auth.trusted_cert_list] 
39         
40         return gid_strings