aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/config/validator.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/config/validator.py')
-rw-r--r--src/mailman_pgp/config/validator.py51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/mailman_pgp/config/validator.py b/src/mailman_pgp/config/validator.py
index 1010663..51f57d7 100644
--- a/src/mailman_pgp/config/validator.py
+++ b/src/mailman_pgp/config/validator.py
@@ -15,13 +15,9 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-"""Config validation and transforms."""
-import builtins
-import re
+"""Config validation."""
from configparser import ConfigParser
-from mailman.utilities.modules import find_name
-
class ConfigValidator:
"""Validates a ConfigParser object against a schema."""
@@ -36,29 +32,28 @@ class ConfigValidator:
:param cfg:
:type cfg: ConfigParser
"""
+ errors = []
+ additional_sections = set(cfg.sections()).difference(
+ self.schema.sections())
+
+ if len(additional_sections) > 0:
+ errors.append(
+ 'Additional sections: {}'.format(additional_sections))
+
for section in self.schema.sections():
- assert cfg.has_section(section)
+ if not cfg.has_section(section):
+ errors.append('Missing config section: {}'.format(section))
+ continue
for option in self.schema.options(section):
- assert cfg.has_option(section, option)
- self._check_option(cfg.get(section, option),
- self.schema.get(section, option))
-
- def _check_option(self, value, schema):
- call = None
- try:
- call = getattr(builtins, schema)
- except:
- try:
- call = find_name(schema)
- except:
- if len(schema) != 0:
- def call(value):
- match = re.search(schema, value)
- if match is None:
- raise ValueError
- return match
+ if not cfg.has_option(section, option):
+ errors.append(
+ 'Missing config option {} in {}'.format(option,
+ section))
+ additional_options = set(cfg.options(section)).difference(
+ self.schema.options(section))
+ if len(additional_options) > 0:
+ errors.append(
+ 'Additional options: {}'.format(additional_options))
- if call is None:
- raise ValueError
- else:
- return call(value)
+ if len(errors) > 0:
+ raise ValueError(errors)