From 7784cd2cf321c98c9c0b1c3b63511a05cdaee717 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 9 Dec 2015 16:43:48 +0000 Subject: 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 --- lorrycontroller/readconf.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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)) -- cgit v1.2.1