From f15d61779e6e3ea395171cab18b8a3d13320dee0 Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Wed, 30 Sep 2020 04:05:40 +0300 Subject: [PATCH] client: fixed localhost as ip_addr error in config --- drone/config/spec/configspec_client.ini | 2 +- lib/config.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drone/config/spec/configspec_client.ini b/drone/config/spec/configspec_client.ini index 8666ed1..9f6cf48 100644 --- a/drone/config/spec/configspec_client.ini +++ b/drone/config/spec/configspec_client.ini @@ -6,7 +6,7 @@ clover_dir = string(default=auto) [SERVER] port = integer(default=25000, min=1) -host = ip_addr(default=192.168.1.101) # string? +host = ip(default=192.168.1.101) # string? buffer_size = integer(default=1024) [BROADCAST] diff --git a/lib/config.py b/lib/config.py index 0596e91..4b92aef 100644 --- a/lib/config.py +++ b/lib/config.py @@ -3,7 +3,7 @@ import copy import collections from configobj import ConfigObj, Section, flatten_errors -from validate import Validator, is_tuple, is_boolean, is_integer +from validate import Validator, is_tuple, is_boolean, is_integer, is_ip_addr def modify_filename(path, pattern): # TODO move to core @@ -27,6 +27,11 @@ def is_preset_param(value): parsed = is_tuple(value, min=2, max=2) return is_boolean(parsed[0]), is_integer(parsed[1], min=0) +def is_ip_or_local(value): + if value == 'localhost': + return True + return is_ip_addr(value) + class ValidationError(ValueError): def __init__(self, message, config, errors): @@ -92,7 +97,9 @@ class ConfigManager: def validate_config(self, config=None, copy_defaults=False): config = self.config if config is None else config - vdt = Validator({"preset_param": is_preset_param}) + vdt = Validator({"preset_param": is_preset_param, + "ip": is_ip_or_local, + }) test = config.validate(vdt, copy=copy_defaults, preserve_errors=True) if test != True: # Important syntax, do no change @@ -186,7 +193,7 @@ class ConfigManager: def load_from_file(self, path): if not self.config_exists(path): - raise ValueError('Config file do not exist!') + raise ValueError('Config file does not exist!') f_path, filename = os.path.split(path) if filename.startswith('configspec_'):