Beispiel #1
0
    def setup_database_in_memory(self):
        engine = create_engine('sqlite:///:memory:')

        # Create blank databases
        metadata.create_all(engine)
        audit_metadata.create_all(engine)
        init_model(engine)

        return engine
Beispiel #2
0
    def setup_database_in_memory(self):
        engine = create_engine('sqlite://')

        # Create blank databases
        metadata.create_all(engine)
        audit_metadata.create_all(engine)
        init_model(engine)

        return engine
 def setUpClass(cls):
     # we need a clean Session context to setup new sqlite db
     # no matter what other unittests did
     Session.close_all()
     Session.remove()
     # Use an in memory empty Sqlite database
     super(TestConfigStoreCase, cls).setUpClass()
     cls.engine = create_engine('sqlite:///:memory:')
     metadata.create_all(cls.engine)
     init_model(cls.engine)
Beispiel #4
0
 def setUpClass(cls):
     # we need a clean Session context to setup new sqlite db
     # no matter what other unittests did
     Session.close_all()
     Session.remove()
     # Use an in memory empty Sqlite database
     super(TestConfigStoreCase, cls).setUpClass()
     cls.engine = create_engine('sqlite:///:memory:')
     metadata.create_all(cls.engine)
     init_model(cls.engine)
Beispiel #5
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config``
    object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[app_conf.get('custom_templates',
                                         os.path.join(root, 'templates')),
                            os.path.join(root, 'templates') ])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='linotp', paths=paths)

    config['linotp.root'] = root
    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = linotp.lib.helpers


    ## add per token a location for the mako template lookup
    ## @note: the location is defined in the .ini file by
    ##  the entry [linotpTokenModules]

    directories = paths['templates']

    ## add a template path for every token
    modules = get_token_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    ## add a template path for every resolver
    modules = get_resolver_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    unique_directories = _uniqify_list(directories)
    log.debug("[load_environment] Template directories: %r" % unique_directories)

    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=unique_directories,
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    # If we load the linotp.model here, the pylons.config is loaded with
    # the entries from the config file. if it is loaded at the top of the file,
    #the pylons.config does not contain the config file, yet.
    from linotp.model import init_model
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    from linotp.lib.audit.base import getAudit
    audit = getAudit()
    config['audit'] = audit

    ## setup Security provider definition
    try:
        log.debug('[load_environment] loading token list definition')
        g = config['pylons.app_globals']
        g.security_provider.load_config(config)
    except Exception as e:
        log.error("Failed to load security provider definition: %r" % e)
        raise e

    ## load the list of tokenclasses
    try:
        log.debug('[load_environment] loading token list definition')
        (tcl, tpl) = get_token_class_list()

        config['tokenclasses'] = tcl
        g.setTokenclasses(tcl)

        config['tokenprefixes'] = tpl
        g.setTokenprefixes(tpl)

    except Exception as e:
        log.error("Failed to load token class list: %r" % e)
        raise e

    ## load the list of resolvers
    try:
        log.debug('[load_environment] loading resolver list definition')
        (rclass, rname) = get_resolver_class_list()

        ## make this globaly avaliable
        g.setResolverClasses(rclass)
        g.setResolverTypes(rname)

    except Exception as exx:
        log.error("Faild to load the list of resolvers: %r" % exx)
        raise exx

    ## get the help url
    url = config.get("linotpHelp.url", None)
    if url == None:
        version = pkg_resources.get_distribution("linotp").version
        offline_url = "file:///usr/share/doc/linotpdoc/html/"
        # First try to get the help for this specific version
        url = "http://linotp.org/doc/%s/index.html" % version
        try:
            ## Try to open the online url with a timeout of 5 seconds
            ## If the system is definitively offline the request will return immediately
            urllib2.urlopen(url, timeout=5)
        except urllib2.HTTPError:
            # it seems the version does not exist, we set the latest
            url = "http://linotp.org/doc/latest/index.html"
            log.info("the Help URL for the version %s is not available, using the latest one: %s" % (version, url))
        except urllib2.URLError:
            # it seems we are offline, using an offline url
            log.warning("it seems we are offline, so using the offline url %s" % offline_url)
            url = offline_url
    config['help_url'] = url

    log.debug("[load_environment] done")
    return
Beispiel #6
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config``
    object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[app_conf.get('custom_templates',
                                         os.path.join(root, 'templates')),
                            os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='linotp', paths=paths)

    config['linotp.root'] = root
    config['routes.map'] = make_map(global_conf, app_conf)
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = linotp.lib.helpers

    # add per token a location for the mako template lookup
    # @note: the location is defined in the .ini file by
    # the entry [linotpTokenModules]

    directories = paths['templates']

    import linotp.tokens as token_package

    token_package_path = os.path.dirname(token_package.__file__)
    directories.append(token_package_path)

    for token_package_sub_path, _subdir, _files in os.walk(token_package_path):
        directories.append(token_package_sub_path)

    # add a template path for every resolver
    resolver_module_path = UserIdResolver.__file__
    directories.append(resolver_module_path)

    unique_directories = _uniqify_list(directories)
    log.debug("[load_environment] Template directories: %r" % unique_directories)

    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=unique_directories,
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    # If we load the linotp.model here, the pylons.config is loaded with
    # the entries from the config file. if it is loaded at the top of the file,
    # the pylons.config does not contain the config file, yet.
    from linotp.model import init_model
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    from linotp.lib.audit.base import getAudit
    audit = getAudit(config)
    config['audit'] = audit

    # setup Security provider definition
    try:
        log.debug('[load_environment] loading token list definition')
        g = config['pylons.app_globals']
        g.security_provider.load_config(config)
    except Exception as e:
        log.exception("Failed to load security provider definition: %r" % e)
        raise e

    # get the help url
    url = config.get("linotpHelp.url", None)
    if url is None:
        version = pkg_resources.get_distribution("linotp").version
        # First try to get the help for this specific version
        url = "https://linotp.org/doc/%s/index.html" % version
    config['help_url'] = url

    log.debug("[load_environment] done")

    return config
Beispiel #7
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config``
    object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[
                     app_conf.get('custom_templates',
                                  os.path.join(root, 'templates')),
                     os.path.join(root, 'templates')
                 ])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='linotp', paths=paths)

    config['linotp.root'] = root
    config['routes.map'] = make_map(global_conf, app_conf)
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = linotp.lib.helpers

    # add per token a location for the mako template lookup
    # @note: the location is defined in the .ini file by
    # the entry [linotpTokenModules]

    directories = paths['templates']

    # add a template path for every token
    modules = get_token_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    # add a template path for every resolver
    modules = get_resolver_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    unique_directories = _uniqify_list(directories)
    log.debug("[load_environment] Template directories: %r" %
              unique_directories)

    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=unique_directories,
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8',
        default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    # If we load the linotp.model here, the pylons.config is loaded with
    # the entries from the config file. if it is loaded at the top of the file,
    # the pylons.config does not contain the config file, yet.
    from linotp.model import init_model
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    from linotp.lib.audit.base import getAudit
    audit = getAudit()
    config['audit'] = audit

    # setup Security provider definition
    try:
        log.debug('[load_environment] loading token list definition')
        g = config['pylons.app_globals']
        g.security_provider.load_config(config)
    except Exception as e:
        log.error("Failed to load security provider definition: %r" % e)
        raise e

    # load the list of tokenclasses
    try:
        log.debug('[load_environment] loading token list definition')
        (tcl, tpl) = get_token_class_list()

        config['tokenclasses'] = tcl
        g.setTokenclasses(tcl)

        config['tokenprefixes'] = tpl
        g.setTokenprefixes(tpl)

    except Exception as e:
        log.error("Failed to load token class list: %r" % e)
        raise e

    # load the list of resolvers
    try:
        log.debug('[load_environment] loading resolver list definition')
        (rclass, rname) = get_resolver_class_list()

        # make this globaly avaliable
        g.setResolverClasses(rclass)
        g.setResolverTypes(rname)

    except Exception as exx:
        log.error("Faild to load the list of resolvers: %r" % exx)
        raise exx

    # get the help url
    url = config.get("linotpHelp.url", None)
    if url is None:
        version = pkg_resources.get_distribution("linotp").version
        # First try to get the help for this specific version
        url = "http://linotp.org/doc/%s/index.html" % version
    config['help_url'] = url

    log.debug("[load_environment] done")
    return config
Beispiel #8
0
 def setUpClass(cls):
     # Use an in memory empty Sqlite database
     super(TestConfigStoreCase, cls).setUpClass()
     cls.engine = create_engine('sqlite:///:memory:')
     metadata.create_all(cls.engine)
     init_model(cls.engine)
Beispiel #9
0
def load_environment(global_conf, app_conf):
    """
    Configure the Pylons environment via the ``pylons.config``
    object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[
                     app_conf.get('custom_templates',
                                  os.path.join(root, 'templates')),
                     os.path.join(root, 'templates')
                 ])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='linotp', paths=paths)

    config['linotp.root'] = root
    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = linotp.lib.helpers

    ## add per token a location for the mako template lookup
    ## @note: the location is defined in the .ini file by
    ##  the entry [linotpTokenModules]

    directories = paths['templates']

    ## add a template path for every token
    modules = get_token_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    ## add a template path for every resolver
    modules = get_resolver_module_list()
    for module in modules:
        mpath = os.path.dirname(module.__file__)
        directories.append(mpath)

    unique_directories = _uniqify_list(directories)
    log.debug("[load_environment] Template directories: %r" %
              unique_directories)

    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=unique_directories,
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8',
        default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    # If we load the linotp.model here, the pylons.config is loaded with
    # the entries from the config file. if it is loaded at the top of the file,
    #the pylons.config does not contain the config file, yet.
    from linotp.model import init_model
    engine = engine_from_config(config, 'sqlalchemy.')
    init_model(engine)

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)

    from linotp.lib.audit.base import getAudit
    audit = getAudit()
    config['audit'] = audit

    ## setup Security provider definition
    try:
        log.debug('[load_environment] loading token list definition')
        g = config['pylons.app_globals']
        g.security_provider.load_config(config)
    except Exception as e:
        log.error("Failed to load security provider definition: %r" % e)
        raise e

    ## load the list of tokenclasses
    try:
        log.debug('[load_environment] loading token list definition')
        (tcl, tpl) = get_token_class_list()

        config['tokenclasses'] = tcl
        g.setTokenclasses(tcl)

        config['tokenprefixes'] = tpl
        g.setTokenprefixes(tpl)

    except Exception as e:
        log.error("Failed to load token class list: %r" % e)
        raise e

    ## load the list of resolvers
    try:
        log.debug('[load_environment] loading resolver list definition')
        (rclass, rname) = get_resolver_class_list()

        ## make this globaly avaliable
        g.setResolverClasses(rclass)
        g.setResolverTypes(rname)

    except Exception as exx:
        log.error("Faild to load the list of resolvers: %r" % exx)
        raise exx

    ## get the help url
    url = config.get("linotpHelp.url", None)

    ## this is a quick hack for the test setup :-(
    ## the big one should handle the timeout when help button
    ## is pressed
    version = pkg_resources.get_distribution("linotp").version
    if not (url) and 'dev' in version:
        url = "file:///usr/share/doc/linotpdoc/html/"

    if url == None:
        version = pkg_resources.get_distribution("linotp").version
        offline_url = "file:///usr/share/doc/linotpdoc/html/"
        # First try to get the help for this specific version
        url = "http://linotp.org/doc/%s/index.html" % version
        try:
            ## Try to open the online url with a timeout of 5 seconds
            ## If the system is definitively offline the request will return immediately
            urllib2.urlopen(url, timeout=5)
        except urllib2.HTTPError:
            # it seems the version does not exist, we set the latest
            url = "http://linotp.org/doc/latest/index.html"
            log.info(
                "the Help URL for the version %s is not available, using the latest one: %s"
                % (version, url))
        except urllib2.URLError:
            # it seems we are offline, using an offline url
            log.warning(
                "it seems we are offline, so using the offline url %s" %
                offline_url)
            url = offline_url
    config['help_url'] = url

    log.debug("[load_environment] done")
    return