3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 13:09:23 +01:00

Make server config validation protocol specific

Closes #282.
This commit is contained in:
James Lu 2016-07-28 21:34:00 -07:00
parent 85e786904c
commit c410de2fad
4 changed files with 22 additions and 5 deletions

View File

@ -172,6 +172,13 @@ class Irc():
while True:
self.aborted.clear()
self.initVars()
try:
self.proto.validateServerConf()
except AssertionError as e:
log.exception("(%s) Configuration error: %s", self.name, e)
return
ip = self.serverdata["ip"]
port = self.serverdata["port"]
checks_ok = True
@ -1144,6 +1151,18 @@ class Protocol():
# Lock for updateTS to make sure only one thread can change the channel TS at one time.
self.ts_lock = threading.Lock()
# Lists required conf keys for the server block.
self.conf_keys = {'ip', 'port', 'hostname', 'sid', 'sidrange', 'protocol', 'sendpass',
'recvpass'}
def validateServerConf(self):
"""Validates that the server block given contains the required keys."""
for k in self.conf_keys:
assert k in self.irc.serverdata, "Missing option %r in server block for network %s." % (k, self.irc.name)
port = self.irc.serverdata['port']
assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.irc.name)
def parseArgs(self, args):
"""Parses a string of RFC1459-style arguments split into a list, where ":" may
be used for multi-word arguments that last until the end of a line.

View File

@ -50,10 +50,6 @@ def validateConf(conf):
for section in ('bot', 'servers', 'login', 'logging'):
assert conf.get(section), "Missing %r section in config." % section
for netname, serverblock in conf['servers'].items():
for section in ('ip', 'port', 'hostname', 'sid', 'sidrange', 'protocol'):
assert serverblock.get(section), "Missing %r in server block for %r." % (section, netname)
assert type(conf['login'].get('password')) == type(conf['login'].get('user')) == str and \
conf['login']['password'] != "changeme", "You have not set the login details correctly!"

View File

@ -10,6 +10,9 @@ class ClientbotWrapperProtocol(Protocol):
def __init__(self, irc):
super().__init__(irc)
# Remove conf key checks for those not needed for Clientbot.
self.conf_keys -= {'recvpass', 'sendpass'}
# This is just a fallback. Actual casemapping is fetched by handle_005()
self.casemapping = 'ascii'

View File

@ -39,7 +39,6 @@ class IRCS2SProtocol(Protocol):
return {'target': killed, 'text': killmsg, 'userdata': data}
def handle_squit(self, numeric, command, args):
"""Handles incoming SQUITs."""
return self._squit(numeric, command, args)