def test_parse(self):
     wc = WhatConfig('')
     wc.parse(CONFIG_TEXT)
     for plugin in PLUGINS:
         assert plugin in wc.plugins
     assert 'mydict' in wc.group_adapters
     assert 'myotherdict' in wc.group_adapters
     assert 'mydict' not in wc.permission_adapters
     assert 'myotherdict' in wc.permission_adapters
Esempio n. 2
0
def make_middleware_with_config(app,
                                global_conf,
                                config_file,
                                who_config_file='',
                                log_file=None,
                                log_level=None):
    """Override repoze.what.plugins.config:make_middleware_with_config
    Allows us to call a Baruwa modified authentication stark
    """
    if not who_config_file:
        who_config_file = config_file
    who_parser = WhoConfig(global_conf['here'])
    who_parser.parse(open(who_config_file))
    what_parser = WhatConfig(global_conf['here'])
    what_parser.parse(open(config_file))

    log_stream = None

    if log_file is not None:
        if log_file.lower() == 'stdout':
            log_stream = sys.stdout
        else:
            try:
                log_stream = open(log_file, 'wb')
            except IOError:
                log_stream = None

    if log_level is None:
        log_level = logging.INFO
    else:
        log_level = _LEVELS[log_level.lower()]

    return setup_auth(
        app,
        group_adapters=what_parser.group_adapters,
        permission_adapters=what_parser.permission_adapters,
        identifiers=who_parser.identifiers,
        authenticators=who_parser.authenticators,
        challengers=who_parser.challengers,
        mdproviders=who_parser.mdproviders,
        classifier=who_parser.request_classifier,
        challenge_decider=who_parser.challenge_decider,
        log_stream=log_stream,
        log_level=log_level,
        remote_user_key=who_parser.remote_user_key,
    )
Esempio n. 3
0
def make_middleware_with_config(app, global_conf, config_file, who_config_file="", log_file=None, log_level=None):
    """Override repoze.what.plugins.config:make_middleware_with_config
    Allows us to call a Baruwa modified authentication stark
    """
    if not who_config_file:
        who_config_file = config_file
    who_parser = WhoConfig(global_conf["here"])
    who_parser.parse(open(who_config_file))
    what_parser = WhatConfig(global_conf["here"])
    what_parser.parse(open(config_file))

    log_stream = None

    if log_file is not None:
        if log_file.lower() == "stdout":
            log_stream = sys.stdout
        else:
            try:
                log_stream = open(log_file, "wb")
            except IOError:
                log_stream = None

    if log_level is None:
        log_level = logging.INFO
    else:
        log_level = _LEVELS[log_level.lower()]

    return setup_auth(
        app,
        group_adapters=what_parser.group_adapters,
        permission_adapters=what_parser.permission_adapters,
        identifiers=who_parser.identifiers,
        authenticators=who_parser.authenticators,
        challengers=who_parser.challengers,
        mdproviders=who_parser.mdproviders,
        classifier=who_parser.request_classifier,
        challenge_decider=who_parser.challenge_decider,
        log_stream=log_stream,
        log_level=log_level,
        remote_user_key=who_parser.remote_user_key,
    )
Esempio n. 4
0
def make_middleware_with_config(app, global_conf, log_file=None):
    """Override repoze.what.plugins.config:make_middleware_with_config
    Allows us to call a Baruwa modified authentication stark and use
    single configuration file
    """
    who_parser = WhoConfig(global_conf['here'])
    who_parser.parse(open(global_conf['__file__']))
    what_parser = WhatConfig(global_conf['here'])
    what_parser.parse(open(global_conf['__file__']))
    log_level = 'DEBUG' if asbool(global_conf['debug']) else 'INFO'

    log_stream = None

    if log_file is not None:
        if log_file.lower() == 'stdout':
            log_stream = sys.stdout
        else:
            try:
                log_stream = open(log_file, 'wb')
            except IOError:
                log_stream = None

    if log_level is None:
        log_level = logging.INFO
    else:
        log_level = _LEVELS[log_level.lower()]

    return setup_auth(app,
                      group_adapters=what_parser.group_adapters,
                      permission_adapters=what_parser.permission_adapters,
                      identifiers=who_parser.identifiers,
                      authenticators=who_parser.authenticators,
                      challengers=who_parser.challengers,
                      mdproviders=who_parser.mdproviders,
                      classifier=who_parser.request_classifier,
                      challenge_decider=who_parser.challenge_decider,
                      log_stream = log_stream,
                      log_level = log_level,
                      remote_user_key = who_parser.remote_user_key,
                     )