Beispiel #1
0
def init_plugin(name, module=None, optional=False):
    """
    Installs a plug-in specified by the supplied name (or name and module).

    arguments:
    name -- a name of the plugin
    module -- if supplied then name->module inference is skipped and init_plugin
              uses this module as a source of the plug-in
    optional -- if True then the module is installed only if it is configured
    """
    if not optional or has_configured_plugin(name):
        try:
            if module is None:
                if not settings.contains('plugins', name):
                    raise PluginException(
                        'Missing configuration for the "%s" plugin' % name)
                plugin_module = plugins.load_plugin_module(
                    settings.get('plugins', name)['module'])
            else:
                plugin_module = module
            plugins.install_plugin(name, plugin_module, settings)
        except ImportError as e:
            logging.getLogger(__name__).warn(
                'Plugin [%s] configured but following error occurred: %r' %
                (name, e))
        except (PluginException, Exception) as e:
            logging.getLogger(__name__).critical(
                'Failed to initiate plug-in %s: %s' % (name, e))
            raise e
    else:
        plugins.add_missing_plugin(name)
Beispiel #2
0
def create_instance(conf, db, sessions):
    auth_conf = conf.get('plugins', 'auth')
    corparch_conf = conf.get('plugins', 'corparch')
    corplist_file = corparch_conf['lindat:file']
    if not os.path.exists(corplist_file):
        raise PluginException("Corplist file [%s] in lindat_auth does not exist!" % corplist_file)
    corplist = _load_corplist(corplist_file)

    # use different shard for the user storage
    auth_db = db.get_instance('auth')

    # this can get handy when federated login is not possible
    failover_auth = LocalFailover()

    return FederatedAuthWithFailover(
        corplist=corplist,
        db=auth_db,
        sessions=sessions,
        conf=auth_conf,
        failover=failover_auth
    )