1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 09:24:21 +01:00

implementing backends parsing of main config file

This commit is contained in:
kakwa 2015-05-19 17:53:14 +02:00
parent a3938c73b4
commit 56be37ff38
2 changed files with 23 additions and 3 deletions

View File

@ -76,8 +76,24 @@ class LdapCherry(object):
else: else:
raise MissingParameter(section, key) raise MissingParameter(section, key)
def _check_backends(self):
backends = self.backends_params.keys()
for b in self.roles.get_backends():
if not b in backends:
raise MissingBackend(b)
for b in self.roles.get_backends():
if not b in backends:
raise MissingBackend(b)
def _init_backends(self, config): def _init_backends(self, config):
pass self.backends_params = {}
for entry in config['backends']:
# split at the first dot
backend, sep, param = entry.partition('.')
value = config['backends'][entry]
if not backend in self.backends_params:
self.backends_params[backend] = {}
self.backends_params[backend][param] = value
def _set_access_log(self, config, level): def _set_access_log(self, config, level):
access_handler = self._get_param('global', 'log.access_handler', config, 'syslog') access_handler = self._get_param('global', 'log.access_handler', config, 'syslog')
@ -200,6 +216,7 @@ class LdapCherry(object):
self.attributes_file = self._get_param('attributes', 'attributes.file', config) self.attributes_file = self._get_param('attributes', 'attributes.file', config)
self.roles = Attributes(self.attributes_file) self.roles = Attributes(self.attributes_file)
self._init_backends(config) self._init_backends(config)
self._check_backends()
except Exception as e: except Exception as e:
self._handle_exception(e) self._handle_exception(e)

View File

@ -28,6 +28,11 @@ class MissingRole(Exception):
self.role = role self.role = role
self.log = "role <%(role)s> does not exist in role file" % { 'role' : role} self.log = "role <%(role)s> does not exist in role file" % { 'role' : role}
class MissingBackend(Exception):
def __init__(self, backend):
self.backend = backend
self.log = "backend <%(backend)s> does not exist in main config file" % { 'backend' : backend}
class DumplicateRoleContent(Exception): class DumplicateRoleContent(Exception):
def __init__(self, role1, role2): def __init__(self, role1, role2):
self.role1 = role1 self.role1 = role1
@ -44,8 +49,6 @@ class MissingMainFile(Exception):
self.rolefile = rolefile self.rolefile = rolefile
self.log = "fail to open main file <%(config)s>" % { 'rolefile' : rolefile} self.log = "fail to open main file <%(config)s>" % { 'rolefile' : rolefile}
class MissingAttributesFile(Exception): class MissingAttributesFile(Exception):
def __init__(self, attributesfile): def __init__(self, attributesfile):
self.attributesfile = attributesfile self.attributesfile = attributesfile