Skip to content

Commit

Permalink
Merge branch 'master' into ORCIDHUB-209
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2000 authored Oct 10, 2017
2 parents 8ec64b0 + d9962f0 commit b405e20
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
9 changes: 8 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.*
*.db
tags
tags.tmp
backup*
masterdb
pgdata
pgdata*
venv
orcid
htmlcov
archive
tests
swagger.json

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ RUN yum -y update \
&& rm -rf __db* \
&& rpm --rebuilddb \
&& yum -y clean all \
&& rm -rf /var/cache/yum \
&& rm -rf $HOME/.pip/cache \
&& rm -rf /var/cache/*/* /anaconda-post.log \
&& rm -f /swagger-codegen-cli.jar /orcid_swagger.json \
Expand Down
13 changes: 7 additions & 6 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ LABEL maintainer="The University of Auckland" \

COPY dev_requirements.txt /dev_requirements.txt
ADD https://github.com/zaproxy/zaproxy/releases/download/2.6.0/ZAP_2.6.0_Linux.tar.gz ZAP_Linux.tar.gz
ADD http://anduin.linuxfromscratch.org/BLFS/OpenJDK/OpenJDK-1.8.0.141/OpenJDK-1.8.0.141-x86_64-bin.tar.xz OpenJDK.tar.gz.xz
ADD http://anduin.linuxfromscratch.org/BLFS/OpenJDK/OpenJDK-1.8.0.141/OpenJDK-1.8.0.141-x86_64-bin.tar.xz OpenJDK.tar.xz

RUN yum -y update \
&& yum -y install install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm \
&& yum -y install \
postgresql96 \
postgresql96 \
python36u-pip \
git \
&& tar -xzf ZAP_Linux.tar.gz -C /tmp \
&& tar -xf OpenJDK.tar.gz.xz -C /tmp \
&& pip3.6 install -U git+https://github.com/Royal-Society-of-New-Zealand/zap-cli \
&& tar -xzf ZAP_Linux.tar.gz -C /tmp \
&& tar -xf OpenJDK.tar.xz -C /tmp \
&& pip3.6 install -U git+https://github.com/Royal-Society-of-New-Zealand/zap-cli \
&& pip3.6 install -U flake8_docstrings pytest-cov coveralls pyyaml \
&& pip3.6 install -U -r /dev_requirements.txt \
&& cd /var/lib/rpm \
&& rm -rf __db* \
&& rpm --rebuilddb \
&& yum -y clean all \
&& rm -rf /var/cache/yum \
&& rm -rf $HOME/.pip/cache \
&& rm -rf ZAP_Linux.tar.gz \
&& rm -rf OpenJDK.tar.gz.xz \
&& rm -rf OpenJDK.tar.xz \
&& rm -rf /var/cache/*/* /anaconda-post.log /dev_requirements.txt


Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME = orcidhub/app
VERSION = 0.16
VERSION = 0.17

.PHONY: all build test tag_latest

Expand Down
7 changes: 2 additions & 5 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

from config import * # noqa: F401, F403
from failover import PgDbWithFailover

# from raven.contrib.flask import Sentry

##from raven.contrib.flask import Sentry
from raven.contrib.flask import Sentry

app = Flask(__name__)
app.config.from_object(__name__)
Expand All @@ -34,7 +31,7 @@
app, name="NZ ORCiD Hub", template_mode="bootstrap3", base_template="admin/master.html")

# https://sentry.io/orcid-hub/nz-orcid-hub-dev/getting-started/python-flask/
# sentry = Sentry(app, dsn=SENTRY_DSN)
sentry = Sentry(app, logging=True, level=logging.DEBUG if ENV == "dev" else logging.ERROR)

login_manager = flask_login.LoginManager()
login_manager.login_view = "login"
Expand Down
13 changes: 9 additions & 4 deletions authcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
from urllib.parse import quote, unquote, urlparse

import requests
from flask import (abort, current_app, flash, redirect, render_template, request, session, url_for)
from flask import (abort, current_app, flash, g, redirect, render_template, request, session,
url_for)
from flask_login import current_user, login_required, login_user, logout_user
from flask_mail import Message
from oauthlib.oauth2 import rfc6749
from requests_oauthlib import OAuth2Session
from werkzeug.urls import iri_to_uri

import orcid_client
from application import app, db, mail
from application import app, db, mail, sentry
from config import (APP_DESCRIPTION, APP_NAME, APP_URL, AUTHORIZATION_BASE_URL, CRED_TYPE_PREMIUM,
ENV, EXTERNAL_SP, MEMBER_API_FORM_BASE_URL, NOTE_ORCID, ORCID_API_BASE,
ORCID_BASE_URL, ORCID_CLIENT_ID, ORCID_CLIENT_SECRET, SCOPE_ACTIVITIES_UPDATE,
Expand Down Expand Up @@ -773,9 +774,13 @@ def uoa_slo():
@app.errorhandler(500)
def internal_error(error):
"""Handle internal error."""
app.logger.exception("Unhandle exception occured.")
trace = traceback.format_exc()
return render_template("http500.html", error_message=str(error), trace=trace)
return render_template(
"http500.html",
trace=trace,
error_message=str(error),
event_id=g.sentry_event_id,
public_dsn=sentry.client.get_public_dsn("https"))


@app.route("/orcid/login/")
Expand Down
3 changes: 2 additions & 1 deletion backup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ TS_LABEL=$(date +%FT%s)
PATH=/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:$HOME/.local/bin:$HOME/bin:$PATH:/usr/local/bin

[ ! -f docker-compose.yml ] && cd $HOME
docker-compose exec -T db psql -U postgres -c "VACUUM FULL ANALYZE; SELECT pg_start_backup('$TS_LABEL', false);"
docker-compose exec -T db psql -U postgres -c "VACUUM FULL ANALYZE;"
docker-compose exec -T db psql -U postgres -c "SELECT pg_start_backup('$TS_LABEL', false);"
tar cjf ./backup/$TS_LABEL.tar.bz2 ./pgdata ; mv ./backup/$TS_LABEL.tar.bz2 ./archive/
docker-compose exec -T db psql -U postgres -c "SELECT pg_stop_backup();"
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
- SECRET_KEY
- ORCID_CLIENT_ID
- ORCID_CLIENT_SECRET
- SENTRY_DSN
domainname: orcidhub.org.nz
hostname: app
ports:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ wtf-peewee
pycountry
html2text
tablib
raven
raven[flask]
17 changes: 16 additions & 1 deletion templates/http500.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ <h1>Webservice currently unavailable <small>Error: <br />{{error_message}}</smal
<p class="lead">An unexpected condition was encountered.<br />
Our service team has been dispatched to bring it back online.</p>
</div>
{% if trace %}
{% if config.ENV != "prod" and trace %}
<div class="container">
<h1>Details</h1>
<pre>{{trace}}</pre>
</div>
{% endif %}
{% if event_id %}
<script src="https://cdn.ravenjs.com/2.3.0/raven.min.js"></script>
<script>
Raven.showReportDialog({
eventId: '{{ event_id }}',
dsn: '{{ public_dsn }}'
{% if current_user.is_authenticated %},
user: {
name: '{{ current_user.name }}',
email: '{{ current_user.email }}'
}
{% endif %}
});
</script>
{% endif %}
</div>
{% endblock %}

0 comments on commit b405e20

Please sign in to comment.