diff options
author | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-05-07 16:32:33 +0100 |
---|---|---|
committer | Ben Hutchings <ben.hutchings@codethink.co.uk> | 2020-06-01 15:31:19 +0100 |
commit | d19a2d783d8567b8c482b01e3e6704403f3f43c5 (patch) | |
tree | a8485a832e88bb57585efb6d720d91461db41aad /lorrycontroller | |
parent | 47c49a46f3614db55d7926ee27b3b889b1479a7f (diff) | |
download | lorry-controller-d19a2d783d8567b8c482b01e3e6704403f3f43c5.tar.gz |
lorrycontroller.readconf: Make general validator methods public
I will move validation of the GitLab-specific field out to the gitlab
module. In future we may also add further fields for specific
Upstream Host types, that will also need to be validated in the
associated modules.
In preparation for that, drop the leading '_' from the more general
methods in LorryControllerConfValidator, to mark them as public.
Diffstat (limited to 'lorrycontroller')
-rw-r--r-- | lorrycontroller/readconf.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py index b95b9de..875e982 100644 --- a/lorrycontroller/readconf.py +++ b/lorrycontroller/readconf.py @@ -319,8 +319,8 @@ class LorryControllerConfValidator(object): def validate_config(self, conf_obj): try: - self._check_is_list(conf_obj) - self._check_is_list_of_dicts(conf_obj) + self.check_is_list(conf_obj) + self.check_is_list_of_dicts(conf_obj) for section in conf_obj: if 'type' not in section: @@ -343,12 +343,12 @@ class LorryControllerConfValidator(object): return None - def _check_is_list(self, conf_obj): + def check_is_list(self, conf_obj): if type(conf_obj) is not list: raise ValidationError( 'type %r is not a JSON list' % type(conf_obj)) - def _check_is_list_of_dicts(self, conf_obj): + def check_is_list_of_dicts(self, conf_obj): for item in conf_obj: if type(item) is not dict: raise ValidationError('all items must be dicts') @@ -359,14 +359,14 @@ class LorryControllerConfValidator(object): def _check_host_section(self, section): if not any(i in ('trovehost', 'host') for i in section): - self._check_has_required_fields(section, ['host']) - self._check_has_required_fields( + self.check_has_required_fields(section, ['host']) + self.check_has_required_fields( section, ['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') + self.check_is_list_of_strings(section, 'ignore') def _check_protocol(self, section): valid = ('ssh', 'http', 'https') @@ -383,18 +383,18 @@ class LorryControllerConfValidator(object): pass def _check_lorries_section(self, section): - self._check_has_required_fields( + self.check_has_required_fields( section, ['interval', 'prefix', 'globs']) - self._check_is_list_of_strings(section, 'globs') + self.check_is_list_of_strings(section, 'globs') - def _check_has_required_fields(self, section, fields): + def check_has_required_fields(self, section, fields): for field in fields: if field not in section: raise ValidationError( 'mandatory field %s missing in section %r' % (field, section)) - def _check_is_list_of_strings(self, section, field): + def check_is_list_of_strings(self, section, field): obj = section[field] if not isinstance(obj, list) or not all( isinstance(s, str) for s in obj): |