-
Notifications
You must be signed in to change notification settings - Fork 12
/
pymm_run.py
executable file
·84 lines (64 loc) · 2.82 KB
/
pymm_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import argparse
from eve import Eve
from flask import redirect
from matchminer.elasticsearch import reset_elasticsearch
from matchminer.utilities import *
from matchminer.custom import blueprint
from matchminer import settings, security
from matchminer.events import register_hooks
from matchminer.validation import ConsentValidatorEve
from matchminer.components.oncore.oncore_app import oncore_blueprint
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s', )
cur_dir = os.path.dirname(os.path.realpath(__file__))
static_dir = os.path.join(cur_dir, 'static')
settings_file = os.path.join(cur_dir, "matchminer/settings.py")
if settings.NO_AUTH:
logging.warning("NO AUTHENTICATION IS ENABLED - SKIPPING HIPAA LOGGING")
app = Eve(settings=settings_file,
static_folder=static_dir,
static_url_path='',
validator=ConsentValidatorEve)
else:
app = Eve(settings=settings_file,
static_folder=static_dir,
static_url_path='',
auth=security.TokenAuth,
validator=ConsentValidatorEve)
app.config['SAML_PATH'] = os.path.join(cur_dir, 'saml')
app.config['SECRET_KEY'] = SAML_SECRET
app.register_blueprint(blueprint)
app.register_blueprint(oncore_blueprint)
register_hooks(app)
@app.after_request
def after_request(response):
# dont use these headers because IE11 doesn't like them with fonts.
if response.content_type != 'application/json':
response.headers.add('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0')
response.headers.add('Pragma', 'no-cache')
return response
@app.errorhandler(401)
def error_handle_401(err):
return make_response("unauthorized access", 497)
@app.errorhandler(501)
def redirect_response(err):
logging.info("redirected to: %s" % err)
return make_response(redirect(err))
def run_server(args):
os.environ['NO_AUTH'] = str(args.no_auth)
app.run(host='0.0.0.0', port=settings.API_PORT, threaded=True)
# main
if __name__ == '__main__':
main_p = argparse.ArgumentParser()
subp = main_p.add_subparsers(help='sub-command help')
subp_p = subp.add_parser('serve', help='runs webserver')
subp_p.add_argument("-d", dest='debug', action='store_const', const=True, default=False)
subp_p.add_argument("--no-auth", dest='no_auth', action='store_const', const=True,
default=False)
subp_p.set_defaults(func=run_server)
subp_p = subp.add_parser('reset-elasticsearch', help='resets elasticsearch')
subp_p.set_defaults(func=lambda x: reset_elasticsearch())
subp_p = subp.add_parser('reannotate-trials', help='regenerates elasticsearch fields on all trials')
subp_p.set_defaults(func=lambda x: reannotate_trials())
args = main_p.parse_args()
args.func(args)