Skip to content
This repository was archived by the owner on Dec 5, 2018. It is now read-only.

Commit 79af3b2

Browse files
author
Ubuntu
committed
Merge branch 'release/1.0.2'
2 parents 8201049 + 26b83b5 commit 79af3b2

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

luigi-interface/monitor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def getTouchfile(bucket_name, touchfile_name):
2424
# Luigi Scraping below
2525
#
2626
def getJobList():
27-
server = os.getenv("LUIGI_SERVER") + ":8082/api/"
27+
server = os.getenv("LUIGI_SERVER") + ":" + os.getenv("LUIGI_PORT", "8082") + "/api/"
2828
#print "SERVER:", server
2929
running_url = server + "task_list?data=%7B%22status%22%3A%22RUNNING%22%2C%22upstream_status%22%3A%22%22%2C%22search%22%3A%22%22%7D"
3030
batch_url = server + "task_list?data=%7B%22status%22%3A%22BATCH_RUNNING%22%2C%22upstream_status%22%3A%22%22%2C%22search%22%3A%22%22%7D"
@@ -84,7 +84,7 @@ def get_consonance_status(consonance_uuid):
8484
# Database initialization, creation if table doesn't exist
8585
#
8686
# Change echo to True to show SQL code... unnecessary
87-
db = create_engine('postgresql://{}:{}@db/monitor'.format(os.getenv("POSTGRES_USER"), os.getenv("POSTGRES_PASSWORD")), echo=False)
87+
db = create_engine('postgresql://{}:{}@db/{}'.format(os.getenv("POSTGRES_USER"), os.getenv("POSTGRES_PASSWORD"), os.getenv("POSTGRES_DB")), echo=False)
8888
conn = db.connect()
8989
metadata = MetaData(db)
9090
luigi = Table('luigi', metadata,
@@ -146,7 +146,7 @@ def get_consonance_status(consonance_uuid):
146146
try:
147147
status_json = get_consonance_status(jsonMetadata['consonance_job_uuid'])
148148
except:
149-
# Add consonance job uuid print t ocstderr,
149+
# Add consonance job uuid print to stderr,
150150
# print job uuid and time when it happeneds
151151
status_json = {
152152
'create_timestamp' : job_dict['start_time'],
@@ -197,11 +197,12 @@ def get_consonance_status(consonance_uuid):
197197
#
198198
# This should be accomplished by:
199199
#
200-
# Select all from the table, pipe it into a list
200+
# Select all from the table, pipe results into a list
201201
#
202202
# for job in list
203203
# consonance status using job.consonance_uuid
204204
# update that job using the information from status return
205+
#
205206
select_query = select([luigi])
206207
select_result = conn.execute(select_query)
207208
result_list = [dict(row) for row in select_result]
@@ -228,6 +229,7 @@ def get_consonance_status(consonance_uuid):
228229
created = status_json['create_timestamp']
229230
updated = status_json['update_timestamp']
230231

232+
# DEBUG to check if state, created, and updated are collected
231233
#print "STATE:", state
232234
#print "CREATED:", created
233235
#print "UPDATED:", updated

mapi.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from flask import Flask, jsonify, request
1+
from flask import Flask, jsonify, request, session
2+
from flask_login import LoginManager, login_required, \
3+
current_user, UserMixin
24
import json
5+
from flask_sqlalchemy import SQLAlchemy
36
from flask_cors import CORS, cross_origin
47
from flask_migrate import Migrate
58
import flask_excel as excel
@@ -22,18 +25,51 @@
2225
# import json
2326
class Config(object):
2427
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
25-
28+
SQLALCHEMY_BINDS = {
29+
'login-db': 'postgresql://{}:{}@login-db/{}'.format(os.getenv("L_POSTGRES_USER"), os.getenv("L_POSTGRES_PASSWORD"), os.getenv("L_POSTGRES_DB"))
30+
}
31+
SECRET_KEY = os.environ.get("SECRET_KEY") or "somethingsecret"
2632

2733
apache_path = os.environ.get("APACHE_PATH", "")
2834
es_service = os.environ.get("ES_SERVICE", "localhost")
2935

3036
app = Flask(__name__)
3137
app.config.from_object(Config)
38+
login_db = SQLAlchemy(app)
39+
login_manager = LoginManager(app)
40+
login_manager.login_view = "login"
41+
login_manager.session_protection = "strong"
3242
db.init_app(app)
3343
migrate = Migrate(app, db)
3444
#es = Elasticsearch()
3545
es = Elasticsearch(['http://'+es_service+':9200/'])
46+
47+
""" DB Models """
48+
class User(login_db.Model, UserMixin):
49+
__tablename__ = "users"
50+
__bind_key__ = "login-db"
51+
id = login_db.Column(login_db.Integer, primary_key=True)
52+
email = login_db.Column(login_db.String(100), unique=True, nullable=False)
53+
name = login_db.Column(login_db.String(100), nullable=True)
54+
avatar = login_db.Column(login_db.String(200))
55+
access_token = login_db.Column(login_db.String(5000))
56+
redwood_token = login_db.Column(login_db.String(5000))
57+
tokens = login_db.Column(login_db.Text)
58+
created_at = login_db.Column(login_db.DateTime, default=datetime.datetime.utcnow())
59+
60+
@login_manager.user_loader
61+
def load_user(user_id):
62+
return User.query.get(int(user_id))
63+
64+
@app.route('/login')
65+
def login():
66+
if current_user.is_authenticated:
67+
redirect('https://{}'.format(os.getenv('DCC_DASHBOARD_HOST')))
68+
else:
69+
redirect('https://{}/login'.format(os.getenv('DCC_DASHBOARD_HOST')))
70+
3671
@app.route('/invoices')
72+
@login_required
3773
@cross_origin()
3874
def find_invoices():
3975
project = str(request.args.get('project'))
@@ -1514,6 +1550,7 @@ def get_manifes_full():
15141550

15151551
#Get the manifest. You need to pass on the filters
15161552
@app.route('/action/service')
1553+
@login_required
15171554
@cross_origin()
15181555
def get_action_service():
15191556
db = create_engine('postgresql://{}:{}@db/monitor'.format(os.getenv("POSTGRES_USER"), os.getenv("POSTGRES_PASSWORD")), echo=False)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Flask-Migrate==2.0.0
1919
Flask-Script==2.0.5
2020
Flask-SQLAlchemy==2.1
2121
active_alchemy==1.0.0
22+
flask-login==0.4.0
2223
funcsigs==1.0.2
2324
futures==3.0.5
2425
idna==2.2

0 commit comments

Comments
 (0)