Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Walt Shands committed Nov 3, 2017
2 parents 0655577 + 6e315f9 commit e6c69ad
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
60 changes: 58 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from flask import Flask, url_for, redirect, \
render_template, session, request, Response, \
flash, get_flashed_messages
flash, get_flashed_messages, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, login_required, login_user, \
logout_user, current_user, UserMixin
from decode_cookie import decodeFlaskCookie
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from models import get_all
Expand Down Expand Up @@ -175,7 +176,7 @@ def burndown():
total_jobs = [int(x.total_jobs) for x in get_all()]
finished_jobs = [int(x.finished_jobs) for x in get_all()]
captured_dates = [x.captured_date for x in get_all()]
return (total_jobs, finished_jobs, captured_dates)
return total_jobs, finished_jobs, captured_dates


@app.route('/')
Expand All @@ -186,6 +187,54 @@ def index():
return html_rend('index')


def parse_token():
"""
Parses the Authorization token from the request header
:return: the bearer and token string
"""
authorization_header = request.headers.get("Authorization", None)
assert authorization_header is not None, "No Authorization header in the request"
parts = authorization_header.split()
# Return the bearer and token string
return parts[0], parts[1]


@app.route('/check_session/<cookie>')
def check_session(cookie):
if not request.headers.get("Authorization", None):
return jsonify({"error": "No Authorization header in the request"})
else:
# Make sure the auth token is the right one
try:
bearer, auth_token = parse_token()
assert bearer == "Bearer", "Authorization must start with Bearer"
assert auth_token == os.getenv("LOG_IN_TOKEN", 'ITS_A_SECRET!')
except AssertionError as e:
response = {
'error': e.message
}
return jsonify(response)
# Now look at the cookie
decoded_cookie = decodeFlaskCookie(os.getenv('SECRET_KEY', 'somethingsecret'), cookie)
try:
assert (decoded_cookie.viewkeys()
>= {'user_id', '_fresh'}), "Cookie not valid; does not have necessary fields"
assert (User.query.get(int(decoded_cookie['user_id'])) is not None), "No user with {}".format(
decoded_cookie['user_id'])
logged_user = User.query.get(int(decoded_cookie['user_id']))
response = {
'email': logged_user.email,
'name': logged_user.name,
'avatar': logged_user.avatar,
'redwood_token': logged_user.redwood_token
}
except AssertionError as e:
response = {
'error': e.message
}
return jsonify(response)


@app.route('/<name>.html')
def html_rend(name):
"""
Expand Down Expand Up @@ -215,6 +264,8 @@ def html_rend(name):
total_jobs=total_jobs,
finished_jobs=finished_jobs,
captured_dates=captured_dates)
if name == 'boardwalk':
return boardwalk()
return render_template(name + '.html')


Expand Down Expand Up @@ -247,6 +298,11 @@ def html_rend_file_browser():
return redirect(url_for('html_rend', name='file_browser'))


@app.route('/boardwalk')
def boardwalk():
return redirect(url_for('boardwalk'))


@app.route('/token')
def token():
"""
Expand Down
4 changes: 4 additions & 0 deletions bdPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@
"{}:{}".format(x.captured_date.hour,
x.captured_date.minute)) for x in get_all()]
print "Total Jobs: {} Finished Jobs: {}".format(total_jobs, finished_jobs)

session.close_all()
engine.dispose()

36 changes: 36 additions & 0 deletions decode_cookie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
from flask.sessions import SecureCookieSessionInterface
from itsdangerous import URLSafeTimedSerializer

# Adapted from here: https://gist.github.com/aescalana/7e0bc39b95baa334074707f73bc64bfe


class SimpleSecureCookieSessionInterface(SecureCookieSessionInterface):
# Override method
# Take secret_key instead of an instance of a Flask app
def get_signing_serializer(self, secret_key):
if not secret_key:
return None
signer_kwargs = dict(
key_derivation=self.key_derivation,
digest_method=self.digest_method
)
return URLSafeTimedSerializer(secret_key, salt=self.salt,
serializer=self.serializer,
signer_kwargs=signer_kwargs)


def decodeFlaskCookie(secret_key, cookieValue):
sscsi = SimpleSecureCookieSessionInterface()
signingSerializer = sscsi.get_signing_serializer(secret_key)
return signingSerializer.loads(cookieValue)


# Keep in mind that flask uses unicode strings for the
# dictionary keys
def encodeFlaskCookie(secret_key, cookieDict):
sscsi = SimpleSecureCookieSessionInterface()
signingSerializer = sscsi.get_signing_serializer(secret_key)
return signingSerializer.dumps(cookieDict)


13 changes: 11 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from time import sleep

Base = declarative_base()

Expand All @@ -28,6 +29,11 @@ def initialize_table():
session = sessionmaker()
session.configure(bind=engine)
Base.metadata.create_all(engine)
# We have sleep here because it appears that the call to create call is non-blocking
# so we need to wait a little bit for the subprocess to create the table.
sleep(5)
session.close_all()
engine.dispose()


def get_all():
Expand All @@ -40,5 +46,8 @@ def get_all():
session = sessionmaker()
session.configure(bind=engine)
s = session()
q = s.query(Burndown).order_by(Burndown.captured_date.asc()).all()
return q
query_object = s.query(Burndown).order_by(Burndown.captured_date.asc()).all()
query_list = [x for x in query_object]
session.close_all()
engine.dispose()
return query_list
Binary file modified static/img/CGL_Team_Pics_Carlos_Espinosa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1 class="md-display-1" style="color:#FF6B6B;">Staff</h1>
</div>
</div>
<div class="flex-75" style="padding:0px">
<p class="md-body-1" style="margin-top:0px"> Carlos is a Software Engineer at the Computational Genomics Platform (CGP). He has been heavily involved in DevOps work, focused on integration and deployment using technologies such as Docker and docker-compose. He also worked on the web service that powers the Platform's file browser. Carlos has a B.A. in Computer Science and a B.S. in Molecular, Cell, &amp; Developmental Biology from UCSC.</p>
<p class="md-body-1" style="margin-top:0px"> Carlos is a Software Engineer at the Computational Genomics Platform (CGP). He has been heavily involved in DevOps work, focused on integration and deployment using technologies such as Docker and docker-compose. He worked on the web service that powers the Platform's file browser and has been involved in prototyping a file viewer for HCA (Human Cell Atlas). His work uses Python, Flask/Chalice, and Elasticsearch. Carlos has a B.A. in Computer Science and a B.S. in Molecular, Cell, &amp; Developmental Biology from UCSC.</p>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<a href="file_browser.html">Browser</a>
</cc-toolbar-nav-item>
<cc-toolbar-nav-item {% block page_Boardwalk %}{% endblock %}>
<a href="boardwalk.html">Boardwalk</a>
<a href="boardwalk">Boardwalk</a>
</cc-toolbar-nav-item>
<cc-toolbar-nav-item {% block page_Redwood %}{% endblock %}>
<a href="redwood.html">Redwood</a>
Expand Down

0 comments on commit e6c69ad

Please sign in to comment.