2020-11-27 03:52:17 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from flask import Flask
|
|
|
|
import sentry_sdk
|
|
|
|
from sentry_sdk.integrations.flask import FlaskIntegration
|
|
|
|
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
|
|
|
from healthcheck import HealthCheck
|
2020-11-27 04:18:09 +01:00
|
|
|
from flask_cors import CORS
|
2020-11-28 01:28:19 +01:00
|
|
|
from flask_mail import Mail
|
2020-11-27 03:52:17 +01:00
|
|
|
|
2020-11-27 23:57:21 +01:00
|
|
|
from utils import Config
|
2020-11-28 00:44:52 +01:00
|
|
|
from utils import health_database_status, init_security_real_good
|
2020-11-28 06:17:45 +01:00
|
|
|
from utils import storage
|
2020-11-28 19:24:58 +01:00
|
|
|
from views import ItemView, ProfileView, UploadView, IndexView, ContentView
|
2020-11-27 03:52:17 +01:00
|
|
|
|
2020-11-27 21:13:00 +01:00
|
|
|
from models import db
|
|
|
|
|
2020-11-27 03:52:17 +01:00
|
|
|
"""
|
|
|
|
Main Flask entrypoint
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = "@tormakris"
|
|
|
|
__copyright__ = "Copyright 2020, UnstableVortex Team"
|
|
|
|
__module_name__ = "app"
|
|
|
|
__version__text__ = "1"
|
|
|
|
|
2020-11-27 23:57:21 +01:00
|
|
|
# The Flask application is not loaded yet, so we are accessing directly to the configuration values
|
|
|
|
if Config.SENTRY_DSN:
|
2020-11-27 03:52:17 +01:00
|
|
|
sentry_sdk.init(
|
2020-11-27 23:57:21 +01:00
|
|
|
dsn=Config.SENTRY_DSN,
|
2020-11-27 03:52:17 +01:00
|
|
|
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
|
|
|
|
traces_sample_rate=1.0,
|
|
|
|
send_default_pii=True,
|
2020-11-27 23:57:21 +01:00
|
|
|
release=Config.RELEASE_ID,
|
|
|
|
environment=Config.RELEASEMODE,
|
2020-11-27 03:52:17 +01:00
|
|
|
_experiments={"auto_enabling_integrations": True}
|
|
|
|
)
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
2020-11-27 23:57:21 +01:00
|
|
|
app.config.from_object(Config)
|
2020-11-27 03:52:17 +01:00
|
|
|
|
|
|
|
health = HealthCheck()
|
|
|
|
db.init_app(app)
|
2020-11-28 00:44:52 +01:00
|
|
|
init_security_real_good(app)
|
2020-11-27 23:57:21 +01:00
|
|
|
CORS(app)
|
2020-11-28 01:28:19 +01:00
|
|
|
Mail(app)
|
2020-11-28 06:17:45 +01:00
|
|
|
storage.init_app(app)
|
2020-11-27 03:52:17 +01:00
|
|
|
|
2020-11-28 19:24:58 +01:00
|
|
|
for view in [ItemView, ProfileView, UploadView, IndexView, ContentView]:
|
2020-11-27 04:10:54 +01:00
|
|
|
view.register(app, trailing_slash=False)
|
2020-11-27 03:52:17 +01:00
|
|
|
|
|
|
|
health.add_check(health_database_status)
|
|
|
|
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
|
|
|
|
|
|
|
|
|
|
|
@app.before_first_request
|
|
|
|
def init_db():
|
|
|
|
db.create_all()
|