kill off the fixbot/*.py.dist config files, prepare for reading them from etc/, add an --api-secret option. Breaks logwatch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/fixbot-logwatch.py Thu Feb 04 18:31:34 2010 +0200
@@ -0,0 +1,19 @@
+import logwatch_filters as filters
+from logwatch_sources import *
+
+def sources () :
+ """
+ Return a sequence of LogSource objects
+ """
+
+ return (
+ Fifo("auth", "logs/auth.fifo", (
+ filters.sudo,
+ filters.cron_killer,
+ filters.all,
+ )),
+ Fifo("foo", "foo", (
+ filters.all,
+ )),
+ )
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/fixbot-nexus.py Thu Feb 04 18:31:34 2010 +0200
@@ -0,0 +1,5 @@
+# the shared static secret to use for API connections. This file shouldn't be world-readable
+
+# this should be a string
+secret = please replace me
+
--- a/fixbot/api.py Thu Feb 04 17:59:45 2010 +0200
+++ b/fixbot/api.py Thu Feb 04 18:31:34 2010 +0200
@@ -6,8 +6,6 @@
import buffer
-from api_secret import secret
-
class ModuleInfo (object) :
"""
Some info about a module
@@ -99,7 +97,7 @@
peer_secret = i.readVarLen('B')
- self._assert(peer_secret == secret, "Mismatching API secrets!")
+ self._assert(peer_secret == self.factory.secret, "Mismatching API secrets!")
m = ModuleInfo()
@@ -147,7 +145,7 @@
log.msg("Connected to API server, sending module init message")
o = self.startCommand('module_init')
- o.writeVarLen('B', secret)
+ o.writeVarLen('B', self.factory.secret)
o.writeVarLen('B', self.factory.name)
o.writeItem("H", self.factory.version)
buffer.writeStringStream(o, 'B', self.factory.event_types)
@@ -172,8 +170,9 @@
class Module (ModuleInfo, protocol.ClientFactory) :
protocol = ClientProtocol
- def __init__ (self) :
+ def __init__ (self, secret) :
self.connection = None
+ self.secret = secret
def connected (self, connection) :
log.msg("Connected!")
@@ -200,13 +199,15 @@
class ServerFactory (protocol.ServerFactory) :
protocol = ServerProtocol
- def __init__ (self, nexus) :
+ def __init__ (self, nexus, secret) :
self.nexus = nexus
+ self.secret = secret
class ClientOptions (usage.Options) :
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 ),
+ ( "api-secret", None, None, "secret key for API connections" ),
]
optFlags = [
@@ -217,7 +218,7 @@
s = service.MultiService()
# the API client
- module_factory = client_module_factory()
+ module_factory = client_module_factory(config['api-secret'])
log.msg("Connecting to API server on [%s:%d]" % (config['api-server'], config['api-port']))
api_client = internet.TCPClient(config['api-server'], config['api-port'], module_factory)
--- a/fixbot/api_secret.py.dist Thu Feb 04 17:59:45 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-# the shared static secret to use for API connections. This file shouldn't be world-readable
-
-# this should be a string
-secret = please replace me
-
--- a/fixbot/logwatch.py Thu Feb 04 17:59:45 2010 +0200
+++ b/fixbot/logwatch.py Thu Feb 04 18:31:34 2010 +0200
@@ -3,7 +3,7 @@
import sys
import api
-import logwatch_config as config
+#import logwatch_config as config
class LogWatchModule (api.Module) :
name = "logs"
--- a/fixbot/logwatch_config.py.dist Thu Feb 04 17:59:45 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-import logwatch_filters as filters
-from logwatch_sources import *
-
-def sources () :
- """
- Return a sequence of LogSource objects
- """
-
- return (
- Fifo("auth", "logs/auth.fifo", (
- filters.sudo,
- filters.cron_killer,
- filters.all,
- )),
- Fifo("foo", "foo", (
- filters.all,
- )),
- )
-
--- a/fixbot/nexus.py Thu Feb 04 17:59:45 2010 +0200
+++ b/fixbot/nexus.py Thu Feb 04 18:31:34 2010 +0200
@@ -52,7 +52,7 @@
irc_client.setServiceParent(s)
# the API side
- n.api = api.ServerFactory(n)
+ n.api = api.ServerFactory(n, config['api-secret'])
log.msg("Starting API server on [%s:%d]", config['api-port'], config['api-listen'])
api_server = internet.TCPServer(config['api-port'], n.api, interface=config['api-listen'])
--- a/twisted/plugins/fixbot_nexus_plugin.py Thu Feb 04 17:59:45 2010 +0200
+++ b/twisted/plugins/fixbot_nexus_plugin.py Thu Feb 04 18:31:34 2010 +0200
@@ -19,6 +19,7 @@
( "irc-channel", "c", "#fixme-test", "IRC channel", ),
( "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" ),
]
optFlags = [
@@ -32,6 +33,9 @@
options = NexusOptions
def makeService (self, config) :
+ if config['api-secret'] is None :
+ raise usage.UsageError("No value given for required option --api-secret")
+
return nexus.makeService(config)
serviceMaker = MyServiceMaker()