diff options
| author | J08nY | 2017-08-01 01:00:34 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-01 01:00:34 +0200 |
| commit | 8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b (patch) | |
| tree | a5d61f909810688d32fda0ba10ce422eccbb5be5 /src/mailman_pgp/config/validator.py | |
| parent | 8c3ac4d693cfa6138a02bf2d58b98ff62fe4f234 (diff) | |
| parent | 89e7005f70a7feda03f15cbe39bf866a6f5bd059 (diff) | |
| download | mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.tar.gz mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.tar.zst mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.zip | |
Diffstat (limited to 'src/mailman_pgp/config/validator.py')
| -rw-r--r-- | src/mailman_pgp/config/validator.py | 51 |
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) |
