Exemple #1
0
def build_app_v2():
    """Building routes and forming the root freezer-api app
    This uses the 'middleware' named argument to specify middleware for falcon
    instead of the 'before' and 'after' hooks that were removed after 0.3.0
    (both approaches were available for versions 0.2.0 - 0.3.0)
    :return: falcon WSGI app
    """
    # injecting FreezerContext & hooks
    middleware_list = [
        utils.FuncMiddleware(hook) for hook in utils.before_hooks()
    ]
    middleware_list.append(middleware.RequireJSON())
    middleware_list.append(middleware.JSONTranslator())

    app = falcon.API(middleware=middleware_list)
    db = driver.get_db()

    # setup freezer policy
    policy.setup_policy(CONF)

    for exception_class in freezer_api_exc.exception_handlers_catalog:
        app.add_error_handler(exception_class, exception_class.handle)

    endpoint_catalog = [('', v2.public_endpoints(db))]
    for version_path, endpoints in endpoint_catalog:
        for route, resource in endpoints:
            app.add_route(version_path + route, resource)

    return app
Exemple #2
0
def api_versions(conf=None):
    """API version negotiation app
    :return: Falcon WSGI app
    """
    middleware_list = list()
    middleware_list.append(middleware.RequireJSON())
    middleware_list.append(middleware.JSONTranslator())
    app = falcon.API(middleware=middleware_list)
    app.add_route('/', Resource())
    return app
Exemple #3
0
def build_app_v1():
    """Building routes and forming the root freezer-api app

    This uses the 'middleware' named argument to specify middleware for falcon
    instead of the 'before' and 'after' hooks that were removed after 0.3.0
    (both approaches were available for versions 0.2.0 - 0.3.0)

    :return: falcon WSGI app
    """
    # injecting FreezerContext & hooks
    middleware_list = [
        utils.FuncMiddleware(hook) for hook in utils.before_hooks()
    ]
    middleware_list.append(middleware.RequireJSON())
    middleware_list.append(middleware.JSONTranslator())

    # The signature of falcon.API() differs between versions, suppress pylint:
    # pylint: disable=unexpected-keyword-arg
    app = falcon.API(middleware=middleware_list)

    app = configure_app(app)
    return app
Exemple #4
0
def build_app_v0():
    """Instantiate the root freezer-api app

    Old versions of falcon (< 0.2.0) don't have a named 'middleware' argument.
    This was introduced in version 0.2.0b1, so before that we need to instead
    provide "before" hooks (request processing) and "after" hooks (response
    processing).

    :return: falcon WSGI app
    """

    # injecting FreezerContext & hooks
    before_hooks = utils.before_hooks() + [
        middleware.RequireJSON().as_before_hook()
    ]
    after_hooks = [middleware.JSONTranslator().as_after_hook()]
    # The signature of falcon.API() differs between versions, suppress pylint:
    # pylint: disable=unexpected-keyword-arg
    app = falcon.API(before=before_hooks, after=after_hooks)

    app = configure_app(app)
    return app