From 8c0bf94904c2254f99d307a13b9b9c48a1150856 Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 8 Feb 2019 20:38:29 +0100 Subject: [PATCH] better log+fix in conf checking + fix in ppolicy handler * log where the backend is declared (role or attribute) when inconsistency with main .ini file * fix check of configuration, only role file was checked 2 times instead on checking role one time and attribute one time * .keys() seems to have a different behavior between 2 (return "list") and 3 (return "dict_keys"), casting to "list" to avoid that. --- ldapcherry/__init__.py | 8 ++++---- ldapcherry/exceptions.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 642ee2f..d058d80 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -149,10 +149,10 @@ class LdapCherry(object): backends = self.backends_params.keys() for b in self.roles.get_backends(): if b not in backends: - raise MissingBackend(b) - for b in self.roles.get_backends(): + raise MissingBackend(b, 'role') + for b in self.attributes.get_backends(): if b not in backends: - raise MissingBackend(b) + raise MissingBackend(b, 'attribute') def _init_backends(self, config): """ Init all backends @@ -1003,7 +1003,7 @@ class LdapCherry(object): def checkppolicy(self, **params): """ search user page """ self._check_auth(must_admin=False, redir_login=False) - keys = params.keys() + keys = list(params.keys()) if len(keys) != 1: cherrypy.response.status = 400 return "bad argument" diff --git a/ldapcherry/exceptions.py b/ldapcherry/exceptions.py index 0bd39b5..cb3ac54 100644 --- a/ldapcherry/exceptions.py +++ b/ldapcherry/exceptions.py @@ -46,11 +46,12 @@ class MissingRole(Exception): class MissingBackend(Exception): - def __init__(self, backend): + def __init__(self, backend, type_conf): self.backend = backend self.log = \ - "backend '%(backend)s' does not exist in main config file" % \ - {'backend': backend} + "backend '%(backend)s' does not exist in main config file " \ + "but is still declared in '%(type_conf)s' file" % \ + {'backend': backend, 'type_conf': type_conf} class WrongBackend(Exception):