Ejemplo n.º 1
0
def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val):
    environ = {env_var: env_val} if env_var else {}
    settings_from_conf = {'h.db_session_checks': True}

    config = configure(environ=environ, settings=settings_from_conf)

    assert config.registry.settings[setting_name] == setting_val
Ejemplo n.º 2
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.Client, name='feature', reify=True)

    config.set_authorization_policy(ACLAuthorizationPolicy())

    policy = MultiAuthenticationPolicy([
        TokenAuthenticationPolicy(callback=groupfinder),
        SessionAuthenticationPolicy(callback=groupfinder),
    ])
    config.set_authentication_policy(policy)

    config.include('h.auth')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include models and db to set up sqlalchemy metadata.
    config.include('h.models')
    config.include('h.db')
    config.include('h.api.db')

    # We have to include search to set up the `request.es` property.
    config.include('h.api.search')

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 3
0
Archivo: websocket.py Proyecto: gnott/h
def create_app(global_config, **settings):
    config = configure(settings=settings)
    config.include('pyramid_services')

    config.include('h.auth')
    # Override the default authentication policy.
    config.set_authentication_policy('h.auth.WEBSOCKET_POLICY')

    config.include('h.authz')
    config.include('h.db')
    config.include('h.session')
    config.include('h.search')
    config.include('h.sentry')
    config.include('h.services')
    config.include('h.stats')

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include('h.links')

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route('ws', '/ws')
    config.add_route('annotation', '/a/{id}', static=True)
    config.add_route('api.annotation', '/api/annotations/{id}', static=True)

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 4
0
def create_app(global_config, **settings):
    config = configure(settings=settings)
    config.include('pyramid_services')

    config.include('h.auth')
    # Override the default authentication policy.
    config.set_authentication_policy('h.auth.WEBSOCKET_POLICY')

    config.include('h.authz')
    config.include('h.db')
    config.include('h.session')
    config.include('h.search')
    config.include('h.sentry')
    config.include('h.services')
    config.include('h.stats')

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include('h.links')

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route('ws', '/ws')
    config.add_route('annotation', '/a/{id}', static=True)
    config.add_route('api.annotation', '/api/annotations/{id}', static=True)

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 5
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.Client, name='feature', reify=True)

    config.set_authorization_policy(ACLAuthorizationPolicy())

    policy = MultiAuthenticationPolicy([
        TokenAuthenticationPolicy(callback=groupfinder),
        SessionAuthenticationPolicy(callback=groupfinder),
    ])
    config.set_authentication_policy(policy)

    config.include('h.auth')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include models and db to set up sqlalchemy metadata.
    config.include('h.models')
    config.include('h.db')
    config.include('h.api.db')

    # We have to include search to set up the `request.es` property.
    config.include('h.api.search')

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 6
0
def create_app(_global_config, **settings):
    config = configure(settings=settings)

    if os.environ.get("KILL_SWITCH_WEBSOCKET"):
        log.warning("Websocket kill switch has been enabled.")
        log.warning(
            "The switch is the environment variable 'KILL_SWITCH_WEBSOCKET'")
        log.warning(
            "No websocket functionality will work until the switch is disabled"
        )

        # Add views to return messages so we don't get confused between
        # disabled and missing end-points in the logs
        config.scan("h.streamer.kill_switch_views")

        # Quit out early without configuring any routes etc.
        return config.make_wsgi_app()

    config.include("pyramid_services")

    config.include("h.auth")
    # Override the default authentication policy.
    config.set_authentication_policy("h.auth.WEBSOCKET_POLICY")

    config.include("h.authz")
    config.include("h.db")
    config.include("h.session")
    config.include("h.services")

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include("h.links")

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route("ws", "/ws")
    config.add_route("annotation", "/a/{id}", static=True)
    config.add_route("api.annotation", "/api/annotations/{id}", static=True)

    config.scan("h.streamer.views")
    config.scan("h.streamer.streamer")
    config.add_tween(
        "h.streamer.tweens.close_db_session_tween_factory",
        over=["pyramid_exclog.exclog_tween_factory", pyramid.tweens.EXCVIEW],
    )

    # Configure sentry
    config.add_settings({
        "h_pyramid_sentry.filters": SENTRY_FILTERS,
        "h_pyramid_sentry.celery_support": True,
    })

    config.include("h_pyramid_sentry")

    # Add support for logging exceptions whenever they arise
    config.include("pyramid_exclog")
    config.add_settings({"exclog.extra_info": True})

    return config.make_wsgi_app()
Ejemplo n.º 7
0
def config():
    from h.config import configure

    config = configure()
    config.registry.settings.update(TEST_SETTINGS)
    _drop_indices(settings=config.registry.settings)
    config.include('h.app')
    config.include('h.session')
    return config
Ejemplo n.º 8
0
def config():
    from h.config import configure

    config = configure()
    config.registry.settings.update(TEST_SETTINGS)
    _drop_indices(settings=config.registry.settings)
    config.include('h.app')
    config.include('h.session')
    return config
Ejemplo n.º 9
0
Archivo: app.py Proyecto: hashin/h
def create_app(global_config, **settings):
    """
    Create the h WSGI application.

    This function serves as a paste app factory.
    """
    config = configure(settings=settings)
    config.include(__name__)
    return config.make_wsgi_app()
Ejemplo n.º 10
0
def create_app(global_config, **settings):
    """
    Create the h WSGI application.

    This function serves as a paste app factory.
    """
    config = configure(settings=settings)
    config.include(__name__)
    return config.make_wsgi_app()
Ejemplo n.º 11
0
def config():
    from h.config import configure
    from h.db import Session

    # Expire any previous database session
    Session.remove()

    config = configure()
    config.registry.settings.update(TEST_SETTINGS)
    _drop_indices(settings=config.registry.settings)
    config.include('h.app')
    config.include('h.session')
    return config
Ejemplo n.º 12
0
def config():
    from h.config import configure
    from h.db import Session

    # Expire any previous database session
    Session.remove()

    config = configure()
    config.registry.settings.update(TEST_SETTINGS)
    _drop_indices(settings=config.registry.settings)
    config.include('h.app')
    config.include('h.session')
    return config
Ejemplo n.º 13
0
def test_configure_updates_settings_from_env_vars(env_var, env_val,
                                                  setting_name, setting_val):
    environ = {env_var: env_val} if env_var else {}
    settings_from_conf = {
        "h.db_session_checks": True,
        # Required settings
        "es.url": "https://es6-search-cluster",
        "secret_key": "notasecret",
        "sqlalchemy.url": "postgres://user@dbhost/dbname",
    }

    config = configure(environ=environ, settings=settings_from_conf)

    assert config.registry.settings[setting_name] == setting_val
Ejemplo n.º 14
0
def test_configure_updates_settings_from_env_vars(env_var, env_val, setting_name, setting_val):
    environ = {env_var: env_val} if env_var else {}
    settings_from_conf = {'h.db_session_checks': True,

                          # Required settings
                          'es.host': 'https://es1-search-cluster',
                          'es.url': 'https://es6-search-cluster',
                          'secret_key': 'notasecret',
                          'sqlalchemy.url': 'postgres://user@dbhost/dbname',
                          }

    config = configure(environ=environ, settings=settings_from_conf)

    assert config.registry.settings[setting_name] == setting_val
Ejemplo n.º 15
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.Client, name='feature', reify=True)

    config.include('pyramid_services')

    config.include('h.auth')
    # Override the default authentication policy.
    config.set_authentication_policy('h.auth.WEBSOCKET_POLICY')

    config.include('h.authz')
    config.include('h.session')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include models and db to set up sqlalchemy metadata.
    config.include('h.models')
    config.include('h.db')

    # We have to include parts of the `memex` package in order to provide,
    # among other things:
    #
    #   - the links service
    #   - the default presenters (and their link registrations)
    #   - the `request.es` property
    config.include('memex.links')
    config.include('memex.presenters')
    config.include('memex.search')

    # accounts provides the UserService
    config.include('h.accounts')

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include('h.links')

    # We have to include nipsa to provide the NIPSA service
    config.include('h.nipsa')

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route('ws', '/ws')
    config.add_route('annotation', '/a/{id}', static=True)
    config.add_route('api.annotation', '/api/annotations/{id}', static=True)

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 16
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.Client, name="feature", reify=True)

    config.include("pyramid_services")

    config.include("h.auth")
    # Override the default authentication policy.
    config.set_authentication_policy("h.auth.WEBSOCKET_POLICY")

    config.include("h.authz")
    config.include("h.session")
    config.include("h.sentry")
    config.include("h.stats")

    # We have to include models and db to set up sqlalchemy metadata.
    config.include("h.models")
    config.include("h.db")

    # We have to include parts of the `memex` package in order to provide,
    # among other things:
    #
    #   - the links service
    #   - the default presenters (and their link registrations)
    #   - the `request.es` property
    config.include("memex.links")
    config.include("memex.presenters")
    config.include("memex.search")

    # accounts provides the UserService
    config.include("h.accounts")

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include("h.links")

    # We have to include nipsa to provide the NIPSA service
    config.include("h.nipsa")

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route("ws", "/ws")
    config.add_route("annotation", "/a/{id}", static=True)
    config.add_route("api.annotation", "/api/annotations/{id}", static=True)

    config.include("h.streamer")

    return config.make_wsgi_app()
Ejemplo n.º 17
0
def test_configure_updates_settings_from_env_vars(env_var, env_val,
                                                  setting_name, setting_val):
    environ = {env_var: env_val} if env_var else {}
    settings_from_conf = {
        'h.db_session_checks': True,

        # Required settings
        'es.url': 'https://es6-search-cluster',
        'secret_key': 'notasecret',
        'sqlalchemy.url': 'postgres://user@dbhost/dbname',
    }

    config = configure(environ=environ, settings=settings_from_conf)

    assert config.registry.settings[setting_name] == setting_val
Ejemplo n.º 18
0
def test_configure_updates_settings_from_env_vars(
    env_var, env_val, setting_name, setting_val
):
    environ = {env_var: env_val} if env_var else {}
    settings_from_conf = {
        "h.db_session_checks": True,
        # Required settings
        "es.url": "https://es6-search-cluster",
        "secret_key": "notasecret",
        "sqlalchemy.url": "postgres://user@dbhost/dbname",
    }

    config = configure(environ=environ, settings=settings_from_conf)

    assert config.registry.settings[setting_name] == setting_val
Ejemplo n.º 19
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.Client, name='feature', reify=True)

    config.include('pyramid_services')

    config.include('h.auth')
    # Override the default authentication policy.
    config.set_authentication_policy('h.auth.WEBSOCKET_POLICY')

    config.include('h.authz')
    config.include('h.session')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include models and db to set up sqlalchemy metadata.
    config.include('h.models')
    config.include('h.db')

    # We have to include parts of the `memex` package in order to provide,
    # among other things:
    #
    #   - the links service
    #   - the default presenters (and their link registrations)
    #   - the `request.es` property
    config.include('memex.links')
    config.include('memex.presenters')
    config.include('memex.search')

    # accounts provides the UserService
    config.include('h.accounts')

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include('h.links')

    # We have to include nipsa to provide the NIPSA service
    config.include('h.nipsa')

    # And finally we add static routes which can be used for URL generation
    # within the websocket server.
    config.add_route('annotation', '/a/{id}', static=True)
    config.add_route('api.annotation', '/api/annotations/{id}', static=True)

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 20
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_tween(
        "h.streamer.close_db_session_tween_factory",
        over=["pyramid_exclog.exclog_tween_factory", pyramid.tweens.EXCVIEW],
    )

    config.include("pyramid_services")

    config.include("h.auth")
    # Override the default authentication policy.
    config.set_authentication_policy("h.auth.WEBSOCKET_POLICY")

    config.include("h.authz")
    config.include("h.db")
    config.include("h.session")
    config.include("h.services")
    config.include("h.stats")

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include("h.links")

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route("ws", "/ws")
    config.add_route("annotation", "/a/{id}", static=True)
    config.add_route("api.annotation", "/api/annotations/{id}", static=True)

    config.include("h.streamer")

    # Configure sentry
    config.add_settings(
        {
            "h_pyramid_sentry.filters": SENTRY_FILTERS,
            "h_pyramid_sentry.celery_support": True,
        }
    )

    config.include("h_pyramid_sentry")

    # Add support for logging exceptions whenever they arise
    config.include("pyramid_exclog")
    config.add_settings({"exclog.extra_info": True})

    return config.make_wsgi_app()
Ejemplo n.º 21
0
Archivo: websocket.py Proyecto: 0b01/h
def create_app(global_config, **settings):
    config = configure(settings=settings)

    # We need to include `h.models` before pretty much everything else to
    # avoid the possibility that one of the imports below directly or
    # indirectly imports `memex.models`. See the comment at the top of
    # `h.models` for details.
    #
    # FIXME: h modules should not access `memex.models`, even indirectly,
    # except through `h.models`.
    config.include('h.models')

    config.include('pyramid_services')

    config.include('h.auth')
    # Override the default authentication policy.
    config.set_authentication_policy('h.auth.WEBSOCKET_POLICY')

    config.include('h.authz')
    config.include('h.db')
    config.include('h.session')
    config.include('h.search')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include parts of the `memex` package in order to provide
    # the links service.
    config.include('memex.links')

    # We include links in order to set up the alternative link registrations
    # for annotations.
    config.include('h.links')

    # Access to services
    config.include('h.services')

    # And finally we add routes. Static routes are not resolvable by HTTP
    # clients, but can be used for URL generation within the websocket server.
    config.add_route('ws', '/ws')
    config.add_route('annotation', '/a/{id}', static=True)
    config.add_route('api.annotation', '/api/annotations/{id}', static=True)

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 22
0
def create_app(global_config, **settings):
    config = configure(settings=settings)

    config.add_request_method(features.flag_enabled, name='feature')

    config.include('h.auth')
    config.include('h.sentry')
    config.include('h.stats')

    # We have to include models and db to set up sqlalchemy metadata.
    config.include('h.models')
    config.include('h.db')
    config.include('h.api.db')

    # We have to include search to set up the `request.es` property.
    config.include('h.api.search')

    config.include('h.streamer')

    return config.make_wsgi_app()
Ejemplo n.º 23
0
def test_configure_generates_secret_key_if_missing():
    config = configure(environ={}, settings={})

    assert 'secret_key' in config.registry.settings
Ejemplo n.º 24
0
def test_configure_doesnt_override_secret_key():
    config = configure(environ={}, settings={'secret_key': 'foobar'})

    assert config.registry.settings['secret_key'] == 'foobar'
Ejemplo n.º 25
0
def test_configure_generates_secret_key_if_missing():
    config = configure(environ={}, settings={})

    assert 'secret_key' in config.registry.settings
Ejemplo n.º 26
0
def test_missing_secrets_doesnt_override_redis_sessions_secret():
    config = configure(environ={}, settings={'redis.sessions.secret': 'isset'})

    assert config.registry.settings['redis.sessions.secret'] == 'isset'
Ejemplo n.º 27
0
def test_configure_generates_redis_sessions_secret_if_missing():
    config = configure(environ={}, settings={})

    assert 'redis.sessions.secret' in config.registry.settings
Ejemplo n.º 28
0
def test_configure_doesnt_override_secret_key():
    config = configure(environ={}, settings={'secret_key': 'foobar'})

    assert config.registry.settings['secret_key'] == 'foobar'
Ejemplo n.º 29
0
Archivo: conftest.py Proyecto: jazahn/h
def config():
    from h.config import configure
    _drop_indices(settings=TEST_SETTINGS)
    config = configure(settings=TEST_SETTINGS)
    config.include('h.app')
    return config