storage-service/storage_service/app.py

54 lines
1.5 KiB
Python
Raw Normal View History

2020-03-25 00:19:12 +01:00
#!/usr/bin/env python3
import os
2020-03-31 19:47:12 +02:00
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
2020-03-25 00:19:12 +01:00
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
# import stuff
2020-03-25 01:57:54 +01:00
from utils import register_all_error_handlers, storage
2020-03-25 00:19:12 +01:00
# import views
from views import ObjectView
2020-03-31 19:47:12 +02:00
# Setup sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[FlaskIntegration()],
2020-10-19 22:29:20 +02:00
traces_sample_rate=1.0,
2020-03-31 19:47:12 +02:00
send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'),
2020-10-19 22:29:20 +02:00
environment=os.environ.get('RELEASEMODE', 'dev'),
_experiments={"auto_enabling_integrations": True}
2020-03-31 19:47:12 +02:00
)
2020-03-25 00:19:12 +01:00
# create flask app
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
2020-03-25 01:57:54 +01:00
# init stuff
storage.init_app(app)
2020-03-25 00:19:12 +01:00
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
2020-03-25 01:57:54 +01:00
app.config['MINIO_ENDPOINT'] = os.environ['MINIO_ENDPOINT']
app.config['MINIO_ACCESS_KEY'] = os.environ['MINIO_ACCESS_KEY']
app.config['MINIO_SECRET_KEY'] = os.environ['MINIO_SECRET_KEY']
2020-03-25 04:02:26 +01:00
app.config['MINIO_BUCKET_NAME'] = os.environ['MINIO_BUCKET_NAME']
app.config['MINIO_SECURE'] = os.environ.get('MINIO_SECURE', False)
app.config['MINIO_REGION'] = os.environ.get('MINIO_REGION', None)
2020-03-25 01:57:54 +01:00
2020-03-25 00:19:12 +01:00
# register error handlers
register_all_error_handlers(app)
# register views
for view in [ObjectView]:
2020-03-25 01:57:54 +01:00
view.register(app, trailing_slash=False)
2020-03-25 00:19:12 +01:00
2020-03-25 01:57:54 +01:00
# start debugging if needed
2020-03-25 00:19:12 +01:00
if __name__ == "__main__":
2020-03-25 01:57:54 +01:00
app.run(debug=True)