fixbot/api/__init__.py
author Tero Marttila <terom@fixme.fi>
Sat, 20 Feb 2010 22:31:17 +0200
changeset 62 e4db89a5f6bc
permissions -rw-r--r--
restructure api, using AMP as the client-server protocol
from twisted.internet import protocol

from fixbot import config
from fixbot.api import amp

class ServerOptions (config.ConfigOptions) :
    """
        Options for the API component of the Nexus
    """

    optParameters = [
        (   "api-listen",   "l",    "127.0.0.1",        "address for API server to listen on"           ),
        (   "api-port",     "P",    34888,              "port for API server to listen on",     int     ),
        (   "api-secret",   None,   None,               "secret key for API connections"                ),
    ]

class ClientOptions (config.ConfigOptions) :
    """
        Options for the API component of a Module
    """

    optParameters = [
        (   "api-server",   "s",    "127.0.0.1",        "address of API server to connect to"           ),
        (   "api-port",     "P",    34888,              "port of API server to connect to",     int     ),
    ]

class ServerFactory (protocol.ServerFactory) :
    def __init__ (self, nexus, config) :
        self.nexus = nexus

        # protocol to use
        self.protocol = amp.ServerProtocol
        
        # XXX: only used for legacy
        self.secret = config.get('api-secret')