Did stuff with the config

This commit is contained in:
Pünkösd Marcell 2020-11-27 23:57:21 +01:00
parent 6eb2fe1879
commit c8b491bd0b
7 changed files with 23 additions and 47 deletions

View File

@ -14,3 +14,4 @@ email_validator
minio
flask-minio
bleach
bcrypt

View File

@ -7,7 +7,7 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from healthcheck import HealthCheck
from flask_cors import CORS
from utils.config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, PORT, DEBUG, SECRET_KEY, ALLOWED_ORIGINS, SQLALCHEMY_URI
from utils import Config
from utils import health_database_status, security, user_datastore
from views import ItemView, ProfileView, UploadView, IndexView
@ -22,38 +22,25 @@ __copyright__ = "Copyright 2020, UnstableVortex Team"
__module_name__ = "app"
__version__text__ = "1"
if SENTRY_DSN:
# The Flask application is not loaded yet, so we are accessing directly to the configuration values
if Config.SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
dsn=Config.SENTRY_DSN,
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
traces_sample_rate=1.0,
send_default_pii=True,
release=RELEASE_ID,
environment=RELEASEMODE,
release=Config.RELEASE_ID,
environment=Config.RELEASEMODE,
_experiments={"auto_enabling_integrations": True}
)
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = SECRET_KEY
app.config['SECURITY_REGISTERABLE'] = True
app.config.from_object(Config)
health = HealthCheck()
db.init_app(app)
security.init_app(app, user_datastore)
CORS(app, origins=ALLOWED_ORIGINS)
formatter = logging.Formatter(
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
CORS(app)
for view in [ItemView, ProfileView, UploadView, IndexView]:
view.register(app, trailing_slash=False)
@ -65,10 +52,3 @@ app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
@app.before_first_request
def init_db():
db.create_all()
if __name__ == "__main__":
app.run(
debug=bool(DEBUG),
port=int(PORT),
)

View File

@ -1,2 +1,3 @@
from .healthchecks import health_database_status
from .security import security, user_datastore
from .config import Config

View File

@ -5,21 +5,24 @@ import os
Configuration
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "config"
__version__text__ = "1"
PORT = os.environ.get("PORT", 8080)
DEBUG = os.environ.get("DEBUG", True)
class Config:
SQLALCHEMY_DATABASE_URI = os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite://")
SECRET_KEY = os.environ.get("SECRET_KEY", os.urandom(12))
CORS_ORIGINS = os.environ.get("ALLOWED_ORIGINS", "*")
SENTRY_DSN = os.environ.get("SENTRY_DSN")
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
SQLALCHEMY_URI = os.environ.get("SQLALCHEMY_URI", "sqlite://")
SECURITY_PASSWORD_SALT = os.environ.get("SECURITY_PASSWORD_SALT") # That's pepper actually
SECRET_KEY = os.getenv("SECRET_KEY")
ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')
# Some constant configured stuff configs
SQLALCHEMY_TRACK_MODIFICATIONS = False
SECURITY_REGISTERABLE = True
SECURITY_PASSWORD_HASH = "bcrypt"

View File

@ -14,9 +14,6 @@ __version__text__ = "1"
class ItemView(FlaskView):
route_prefix = "/item/"
route_base = '/'
def index(self):
pass

View File

@ -14,8 +14,5 @@ __version__text__ = "1"
class ProfileView(FlaskView):
route_prefix = "/profile/"
route_base = '/'
def index(self):
pass

View File

@ -14,8 +14,5 @@ __version__text__ = "1"
class UploadView(FlaskView):
route_prefix = "/upload/"
route_base = '/'
def index(self):
pass