-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathapp.py
63 lines (54 loc) · 1.72 KB
/
app.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
from flask import Flask, render_template, Response
from flask_graphql import GraphQLView
from flask_cors import CORS
from flask_json import FlaskJSON
from flask_mail import Mail
from config import config
from helpers.database import db_session
from schema import schema
from healthcheck_schema import healthcheck_schema
from helpers.auth.authentication import Auth
from utilities.file_reader import read_log_file
mail = Mail()
def create_app(config_name):
app = Flask(__name__)
CORS(app)
FlaskJSON(app)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
mail.init_app(app)
@app.route("/", methods=['GET'])
def index():
return render_template('index.html')
@app.route("/logs", methods=['GET'])
@Auth.user_roles('Super Admin', 'REST')
def logs():
response = None
log_file = 'mrm.err.log'
try:
open(log_file) # trigger opening of file
response = Response(read_log_file(log_file), mimetype='text')
except FileNotFoundError: # pragma: no cover
message = 'Log file was not found'
response = Response(message, mimetype='text', status=404)
return response
app.add_url_rule(
'/mrm',
view_func=GraphQLView.as_view(
'mrm',
schema=schema,
graphiql=True # for having the GraphiQL interface
)
)
app.add_url_rule(
'/_healthcheck',
view_func=GraphQLView.as_view(
'_healthcheck',
schema=healthcheck_schema,
graphiql=True # for healthchecks
)
)
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
return app