mirror of
https://github.com/kakwa/ldapcherry
synced 2025-07-04 04:17:43 +02:00
implementing loading backends
* fix conf file * add exceptions * fix modules skeletons
This commit is contained in:
parent
6a610c079e
commit
1e5f057e36
6 changed files with 38 additions and 9 deletions
|
@ -87,6 +87,7 @@ class LdapCherry(object):
|
|||
|
||||
def _init_backends(self, config):
|
||||
self.backends_params = {}
|
||||
self.backends = {}
|
||||
for entry in config['backends']:
|
||||
# split at the first dot
|
||||
backend, sep, param = entry.partition('.')
|
||||
|
@ -94,6 +95,21 @@ class LdapCherry(object):
|
|||
if not backend in self.backends_params:
|
||||
self.backends_params[backend] = {}
|
||||
self.backends_params[backend][param] = value
|
||||
for backend in self.backends_params:
|
||||
params = self.backends_params[backend]
|
||||
# Loading the backend module
|
||||
try:
|
||||
module = params['module']
|
||||
except:
|
||||
raise MissingParameter('backends', backend + '.module')
|
||||
try:
|
||||
bc = __import__(module, globals(), locals(), ['Backend'], -1)
|
||||
except:
|
||||
raise BackendModuleLoadingFail(module)
|
||||
try:
|
||||
self.backends[backend] = bc.Backend(params, cherrypy.log)
|
||||
except:
|
||||
raise BackendModuleInitFail(module)
|
||||
|
||||
def _set_access_log(self, config, level):
|
||||
access_handler = self._get_param('global', 'log.access_handler', config, 'syslog')
|
||||
|
@ -209,11 +225,6 @@ class LdapCherry(object):
|
|||
self.temp_error = self.temp_lookup.get_template('error.tmpl')
|
||||
self.temp_login = self.temp_lookup.get_template('login.tmpl')
|
||||
|
||||
# loading the authentification module
|
||||
#auth_module = self._get_param('auth', 'auth.module', config)
|
||||
#auth = __import__(auth_module, globals(), locals(), ['Auth'], -1)
|
||||
#self.auth = auth.Auth(config['auth'], cherrypy.log)
|
||||
|
||||
|
||||
self.roles_file = self._get_param('roles', 'roles.file', config)
|
||||
cherrypy.log.error(
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
# LdapCherry
|
||||
# Copyright (c) 2014 Carpentier Pierre-Francois
|
||||
|
||||
import ldapcherry.backend
|
||||
|
||||
class Backend(ldapcherry.backend.Backend):
|
||||
|
||||
def __init__(self, config, logger):
|
||||
|
|
|
@ -5,3 +5,9 @@
|
|||
# LdapCherry
|
||||
# Copyright (c) 2014 Carpentier Pierre-Francois
|
||||
|
||||
import ldapcherry.backend
|
||||
|
||||
class Backend(ldapcherry.backend.Backend):
|
||||
|
||||
def __init__(self, config, logger):
|
||||
pass
|
||||
|
|
|
@ -54,6 +54,16 @@ class MissingAttributesFile(Exception):
|
|||
self.attributesfile = attributesfile
|
||||
self.log = "fail to open attributes file <%(attributesfile)s>" % { 'attributesfile' : attributesfile}
|
||||
|
||||
class BackendModuleLoadingFail(Exception):
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.log = "fail to load module <%(module)s>" % {'module': module}
|
||||
|
||||
class BackendModuleInitFail(Exception):
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.log = "fail to init module <%(module)s>" % {'module': module}
|
||||
|
||||
class WrongAttributeType(Exception):
|
||||
def __init__(self, key, section, ymlfile):
|
||||
self.key = key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue