trash wsdl
[sfa.git] / sfa / server / sfaserver.py
1 """
2 This module implements a general-purpose server layer for sfa.
3 The same basic server should be usable on the registry or
4 other interfaces.
5 """
6
7 import threading
8
9 from sfa.server.threadedserver import ThreadedServer, SecureXMLRpcRequestHandler
10
11 from sfa.util.sfalogging import logger
12 from sfa.trust.certificate import Keypair, Certificate
13
14 ##
15 # Implements an HTTPS XML-RPC server. Generally it is expected that SFA
16 # functions will take a credential string, which is passed to
17 # decode_authentication. Decode_authentication() will verify the validity of
18 # the credential, and verify that the user is using the key that matches the
19 # GID supplied in the credential.
20
21
22 class SfaServer(threading.Thread):
23
24     ##
25     # Create a new SfaServer object.
26     #
27     # @param ip the ip address to listen on
28     # @param port the port to listen on
29     # @param key_file private key filename of registry
30     # @param cert_file certificate filename containing public key
31     #   (could be a GID file)
32
33     def __init__(self, ip, port, key_file, cert_file, interface):
34         threading.Thread.__init__(self)
35         self.key = Keypair(filename=key_file)
36         self.cert = Certificate(filename=cert_file)
37         #self.server = SecureXMLRPCServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
38         self.server = ThreadedServer(
39             (ip, int(port)), SecureXMLRpcRequestHandler, key_file, cert_file)
40         self.server.interface = interface
41         self.trusted_cert_list = None
42         self.register_functions()
43         logger.info("Starting SfaServer, interface=%s" % interface)
44
45     ##
46     # Register functions that will be served by the XMLRPC server. This
47     # function should be overridden by each descendant class.
48
49     def register_functions(self):
50         self.server.register_function(self.noop)
51
52     ##
53     # Sample no-op server function. The no-op function decodes the credential
54     # that was passed to it.
55
56     def noop(self, cred, anything):
57         return anything
58
59     ##
60     # Execute the server, serving requests forever.
61
62     def run(self):
63         print("IN")
64         self.server.serve_forever()
65         print("OUT")