Updated config style

This commit is contained in:
Pünkösd Marcell 2021-08-09 13:55:42 +02:00
parent b835b63092
commit e7f944ff44
2 changed files with 25 additions and 16 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import sentry_sdk import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask from flask import Flask
@ -11,34 +10,28 @@ from utils import register_all_error_handlers, storage
# import views # import views
from views import ObjectView from views import ObjectView
from config import Config
# Setup sentry # Setup sentry
SENTRY_DSN = os.environ.get("SENTRY_DSN") if Config.SENTRY_DSN:
if SENTRY_DSN:
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration()], integrations=[FlaskIntegration()],
_experiments={"auto_enabling_integrations": True},
traces_sample_rate=0,
send_default_pii=True, send_default_pii=True,
release=os.environ.get('RELEASE_ID', 'test'), release=Config.RELEASE_ID,
environment=os.environ.get('RELEASEMODE', 'dev') environment=Config.RELEASEMODE
) )
# create flask app # create flask app
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(Config)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1) app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# init stuff # init stuff
storage.init_app(app) storage.init_app(app)
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
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']
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)
# register error handlers # register error handlers
register_all_error_handlers(app) register_all_error_handlers(app)

16
storage_service/config.py Normal file
View File

@ -0,0 +1,16 @@
import os
class Config:
MINIO_ENDPOINT = os.environ['MINIO_ENDPOINT']
MINIO_ACCESS_KEY = os.environ['MINIO_ACCESS_KEY']
MINIO_SECRET_KEY = os.environ['MINIO_SECRET_KEY']
MINIO_BUCKET_NAME = os.environ['MINIO_BUCKET_NAME']
MINIO_SECURE = os.environ.get('MINIO_SECURE', False)
MINIO_REGION = os.environ.get('MINIO_REGION', None)
SECRET_KEY = os.environ.get('SECRET_KEY', os.urandom(12))
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")