hooks.py 1.21 KB
Newer Older
1
"""cube hooks
2 3 4 5 6 7 8

:organization: Logilab
:copyright: 2009-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
__docformat__ = "restructuredtext en"
9
import os.path as osp
10 11 12 13 14 15

from cubicweb.server import hook

from cubes.apachekerberos.authplugin import XRemoteUserAuthentifier

class ServerStartupHook(hook.Hook):
16
    """register authentifier at startup"""
17 18 19 20 21 22
    __regid__ = 'xremoteuserinit'
    events = ('server_startup',)

    def __call__(self):
        # XXX use named args and inner functions to avoid referencing globals
        # which may cause reloading pb
23
        self.debug('registering kerberos authentifier')
24
        self.repo.system_source.add_authentifier(XRemoteUserAuthentifier())
25

26
CONFENTRY = 'secret-key-filepath'
27
def registration_callback(vreg):
28
    fpath = vreg.config.get(CONFENTRY)
29
    if fpath is None or not osp.exists(fpath):
30
        msg = 'invalid or missing value for the %s' % CONFENTRY
31
        vreg.error(msg)
32 33 34 35
    else:
        vreg.register(ServerStartupHook)
        vreg.config._secret = open(fpath, 'rb').read().strip()
        vreg.debug('loaded secret key')