summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2015-12-09 16:43:48 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-12-15 11:34:36 +0000
commit7784cd2cf321c98c9c0b1c3b63511a05cdaee717 (patch)
tree39a1dae88af7d236577d3a38597a478305bf4347
parent2e3195ffabe9aa2004160d82c24d534af3b4a2ae (diff)
downloadlorry-controller-7784cd2cf321c98c9c0b1c3b63511a05cdaee717.tar.gz
Perform some sanity checking for 'ignore' and 'globs' fields
The 'ignore' and 'globs' fields expect values to be string lists, add checks for this in config validation. Change-Id: I96fc8fa217a6f62b6b67f604bd50b2fbea723db5
-rw-r--r--lorrycontroller/readconf.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py
index 2eae4b3..f7a7404 100644
--- a/lorrycontroller/readconf.py
+++ b/lorrycontroller/readconf.py
@@ -344,6 +344,8 @@ class LorryControllerConfValidator(object):
['trovehost', 'protocol', 'interval', 'ls-interval', 'prefixmap'])
self._check_protocol(section)
self._check_prefixmap(section)
+ if 'ignore' in section:
+ self._check_is_list_of_strings(section, 'ignore')
def _check_protocol(self, section):
valid = ('ssh', 'http', 'https')
@@ -362,6 +364,7 @@ class LorryControllerConfValidator(object):
def _check_lorries_section(self, section):
self._check_has_required_fields(
section, ['interval', 'prefix', 'globs'])
+ self._check_is_list_of_strings(section, 'globs')
def _check_has_required_fields(self, section, fields):
for field in fields:
@@ -369,3 +372,11 @@ class LorryControllerConfValidator(object):
raise ValidationError(
'mandatory field %s missing in section %r' %
(field, section))
+
+ def _check_is_list_of_strings(self, section, field):
+ obj = section[field]
+ if not isinstance(obj, list) or not all(
+ isinstance(s, basestring) for s in obj):
+ raise ValidationError(
+ '%s field in %r must be a list of strings' %
+ (field, section))