Skip to content

Commit

Permalink
Run via gunicorn. Configure logging to use gunicorn default.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffFranklin committed Apr 26, 2019
1 parent d81b509 commit 0cbacb4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ WORKDIR /app
COPY . /app
ENV FLASK_APP=app.py

CMD ["flask", "run", "--host=0.0.0.0"]
CMD ["gunicorn", "--worker-class", "eventlet", "--bind", ":5000", "app:app"]
18 changes: 15 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from flask import Flask, Response, request, session, abort, redirect
from flask.logging import default_handler
import flask
from werkzeug.middleware.proxy_fix import ProxyFix
import uw_saml2
from urllib.parse import urljoin
from datetime import timedelta
import os
import secrets
import logging


def configure_logging():
gunicorn_logger = logging.getLogger('gunicorn.error')
level = logging.DEBUG
if gunicorn_logger:
level = gunicorn_logger.level
logging.getLogger().setLevel(level)
logging.getLogger('uw_saml2').addHandler(default_handler)


configure_logging()
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_prefix=1)
POSTBACK_ROUTE = '/login'
Expand All @@ -22,7 +36,7 @@
)


@app.route('/status')
@app.route('/status') # if we add any more options then refactor all this.
@app.route('/status/2fa')
@app.route('/status/group/<group>')
@app.route('/status/group/<group>/2fa')
Expand Down Expand Up @@ -79,7 +93,6 @@ def login_redirect(return_to=''):
return_to - the path to redirect back to after authentication. This and
the request.query_string are set on the SAML RelayState.
"""
app.logger.error(f'URL ROOT {request.url_root}')
query_string = '?' + request.query_string.decode()
if query_string == '?':
query_string = ''
Expand All @@ -105,7 +118,6 @@ def login():
session['userid'] = attributes['uwnetid']
session['groups'] = attributes.get('groups', [])
session['has_2fa'] = attributes.get('two_factor')
app.logger.info(attributes)
relay_state = request.form.get('RelayState')
if relay_state and relay_state.startswith('/'):
return redirect(urljoin(request.url_root, request.form['RelayState']))
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ services:
image: mynginx
ports: ["443:443"]
volumes:
- ./test/nginx/server.conf:/etc/nginx/conf.d/server.conf
- ./test/nginx/server.conf:/etc/nginx/conf.d/server.conf
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Werkzeug>=0.15
flask
uw-saml[python3-saml]>=1.0.3
gunicorn[eventlet]

0 comments on commit 0cbacb4

Please sign in to comment.