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

implementing loading backends

* fix conf file
* add exceptions
* fix modules skeletons
This commit is contained in:
kakwa 2015-05-20 14:21:43 +02:00
parent 6a610c079e
commit 1e5f057e36
6 changed files with 38 additions and 9 deletions

View File

@ -66,7 +66,7 @@ roles.file = '/etc/ldapcherry/roles.yml'
[backends] [backends]
ldap.module = 'ldapcherry.backends.ldap' ldap.module = 'ldapcherry.backend.ldap'
ldap.groupdn = 'ou=group,dc=example,dc=com' ldap.groupdn = 'ou=group,dc=example,dc=com'
ldap.people = 'ou=group,dc=example,dc=com' ldap.people = 'ou=group,dc=example,dc=com'
ldap.authdn = 'cn=ldapcherry,dc=example,dc=com' ldap.authdn = 'cn=ldapcherry,dc=example,dc=com'
@ -76,7 +76,7 @@ ldap.ca = '/etc/dnscherry/TEST-cacert.pem'
ldap.starttls = 'on' ldap.starttls = 'on'
ldap.checkcert = 'off' ldap.checkcert = 'off'
ad.module = 'ldapcherry.backends.ad' ad.module = 'ldapcherry.backend.samba4'
ad.auth = 'Administrator' ad.auth = 'Administrator'
ad.password = 'password' ad.password = 'password'

View File

@ -87,6 +87,7 @@ class LdapCherry(object):
def _init_backends(self, config): def _init_backends(self, config):
self.backends_params = {} self.backends_params = {}
self.backends = {}
for entry in config['backends']: for entry in config['backends']:
# split at the first dot # split at the first dot
backend, sep, param = entry.partition('.') backend, sep, param = entry.partition('.')
@ -94,6 +95,21 @@ class LdapCherry(object):
if not backend in self.backends_params: if not backend in self.backends_params:
self.backends_params[backend] = {} self.backends_params[backend] = {}
self.backends_params[backend][param] = value 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): 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')
@ -209,11 +225,6 @@ class LdapCherry(object):
self.temp_error = self.temp_lookup.get_template('error.tmpl') self.temp_error = self.temp_lookup.get_template('error.tmpl')
self.temp_login = self.temp_lookup.get_template('login.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) self.roles_file = self._get_param('roles', 'roles.file', config)
cherrypy.log.error( cherrypy.log.error(

View File

@ -5,6 +5,8 @@
# LdapCherry # LdapCherry
# Copyright (c) 2014 Carpentier Pierre-Francois # Copyright (c) 2014 Carpentier Pierre-Francois
import ldapcherry.backend
class Backend(ldapcherry.backend.Backend): class Backend(ldapcherry.backend.Backend):
def __init__(self, config, logger): def __init__(self, config, logger):

View File

@ -5,3 +5,9 @@
# LdapCherry # LdapCherry
# Copyright (c) 2014 Carpentier Pierre-Francois # Copyright (c) 2014 Carpentier Pierre-Francois
import ldapcherry.backend
class Backend(ldapcherry.backend.Backend):
def __init__(self, config, logger):
pass

View File

@ -54,6 +54,16 @@ class MissingAttributesFile(Exception):
self.attributesfile = attributesfile self.attributesfile = attributesfile
self.log = "fail to open attributes file <%(attributesfile)s>" % { '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): class WrongAttributeType(Exception):
def __init__(self, key, section, ymlfile): def __init__(self, key, section, ymlfile):
self.key = key self.key = key

View File

@ -66,7 +66,7 @@ roles.file = './tests/cfg/roles.yml'
[backends] [backends]
ldap.module = 'ldapcherry.backends.ldap' ldap.module = 'ldapcherry.backend.ldap'
ldap.groupdn = 'ou=group,dc=example,dc=com' ldap.groupdn = 'ou=group,dc=example,dc=com'
ldap.people = 'ou=group,dc=example,dc=com' ldap.people = 'ou=group,dc=example,dc=com'
ldap.authdn = 'cn=ldapcherry,dc=example,dc=com' ldap.authdn = 'cn=ldapcherry,dc=example,dc=com'
@ -76,7 +76,7 @@ ldap.ca = '/etc/dnscherry/TEST-cacert.pem'
ldap.starttls = 'on' ldap.starttls = 'on'
ldap.checkcert = 'off' ldap.checkcert = 'off'
ad.module = 'ldapcherry.backends.ad' ad.module = 'ldapcherry.backend.samba4'
ad.auth = 'Administrator' ad.auth = 'Administrator'
ad.password = 'password' ad.password = 'password'