Skip to content

Commit

Permalink
Add Babel and Repoze to the Flask middleware stack
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Mar 30, 2016
1 parent 4e11348 commit 0f496d4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions ckan/config/middleware.py
Expand Up @@ -27,6 +27,7 @@
from flask import _request_ctx_stack
from werkzeug.exceptions import HTTPException
from werkzeug.test import create_environ, run_wsgi_app
from flask.ext.babel import Babel

from ckan.plugins import PluginImplementations
from ckan.plugins.interfaces import IMiddleware
Expand All @@ -45,7 +46,7 @@ def make_app(conf, full_stack=True, static_files=True, **app_conf):
# /__invite__/, and handle can_handle_request requests.

pylons_app = make_pylons_stack(conf, full_stack, static_files, **app_conf)
flask_app = make_flask_stack(conf)
flask_app = make_flask_stack(conf, **app_conf)

app = AskAppDispatcherMiddleware({'pylons_app': pylons_app, 'flask_app': flask_app})

Expand Down Expand Up @@ -201,12 +202,16 @@ def make_pylons_stack(conf, full_stack=True, static_files=True, **app_conf):
return app


def make_flask_stack(conf):
def make_flask_stack(conf, **app_conf):
""" This has to pass the flask app through all the same middleware that
Pylons used """

app = CKANFlask(__name__)

# Do all the Flask-specific stuff before adding other middlewares

Babel(app)

@app.route('/hello', methods=['GET'])
def hello_world():
return 'Hello World, this is served by Flask'
Expand All @@ -215,6 +220,25 @@ def hello_world():
def hello_world_post():
return 'Hello World, this was posted to Flask'

# Start other middleware

# Initialize repoze.who
who_parser = WhoConfig(conf['here'])
who_parser.parse(open(app_conf['who.config_file']))

app = PluggableAuthenticationMiddleware(
app,
who_parser.identifiers,
who_parser.authenticators,
who_parser.challengers,
who_parser.mdproviders,
who_parser.request_classifier,
who_parser.challenge_decider,
logging.getLogger('repoze.who'),
logging.WARN, # ignored
who_parser.remote_user_key
)

return app


Expand Down

0 comments on commit 0f496d4

Please sign in to comment.