Did stuff with the config
This commit is contained in:
parent
6eb2fe1879
commit
c8b491bd0b
@ -13,4 +13,5 @@ psycopg2-binary
|
|||||||
email_validator
|
email_validator
|
||||||
minio
|
minio
|
||||||
flask-minio
|
flask-minio
|
||||||
bleach
|
bleach
|
||||||
|
bcrypt
|
36
src/app.py
36
src/app.py
@ -7,7 +7,7 @@ from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
|||||||
from healthcheck import HealthCheck
|
from healthcheck import HealthCheck
|
||||||
from flask_cors import CORS
|
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 utils import health_database_status, security, user_datastore
|
||||||
from views import ItemView, ProfileView, UploadView, IndexView
|
from views import ItemView, ProfileView, UploadView, IndexView
|
||||||
|
|
||||||
@ -22,38 +22,25 @@ __copyright__ = "Copyright 2020, UnstableVortex Team"
|
|||||||
__module_name__ = "app"
|
__module_name__ = "app"
|
||||||
__version__text__ = "1"
|
__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(
|
sentry_sdk.init(
|
||||||
dsn=SENTRY_DSN,
|
dsn=Config.SENTRY_DSN,
|
||||||
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
|
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
|
||||||
traces_sample_rate=1.0,
|
traces_sample_rate=1.0,
|
||||||
send_default_pii=True,
|
send_default_pii=True,
|
||||||
release=RELEASE_ID,
|
release=Config.RELEASE_ID,
|
||||||
environment=RELEASEMODE,
|
environment=Config.RELEASEMODE,
|
||||||
_experiments={"auto_enabling_integrations": True}
|
_experiments={"auto_enabling_integrations": True}
|
||||||
)
|
)
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_URI
|
app.config.from_object(Config)
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
||||||
app.config['SECRET_KEY'] = SECRET_KEY
|
|
||||||
app.config['SECURITY_REGISTERABLE'] = True
|
|
||||||
|
|
||||||
health = HealthCheck()
|
health = HealthCheck()
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
security.init_app(app, user_datastore)
|
security.init_app(app, user_datastore)
|
||||||
CORS(app, origins=ALLOWED_ORIGINS)
|
CORS(app)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
for view in [ItemView, ProfileView, UploadView, IndexView]:
|
for view in [ItemView, ProfileView, UploadView, IndexView]:
|
||||||
view.register(app, trailing_slash=False)
|
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
|
@app.before_first_request
|
||||||
def init_db():
|
def init_db():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(
|
|
||||||
debug=bool(DEBUG),
|
|
||||||
port=int(PORT),
|
|
||||||
)
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
from .healthchecks import health_database_status
|
from .healthchecks import health_database_status
|
||||||
from .security import security, user_datastore
|
from .security import security, user_datastore
|
||||||
|
from .config import Config
|
@ -5,21 +5,24 @@ import os
|
|||||||
Configuration
|
Configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
__author__ = "@tormakris"
|
__author__ = "@tormakris"
|
||||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||||
__module_name__ = "config"
|
__module_name__ = "config"
|
||||||
__version__text__ = "1"
|
__version__text__ = "1"
|
||||||
|
|
||||||
|
|
||||||
PORT = os.environ.get("PORT", 8080)
|
class Config:
|
||||||
DEBUG = os.environ.get("DEBUG", True)
|
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")
|
SENTRY_DSN = os.environ.get("SENTRY_DSN")
|
||||||
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
RELEASE_ID = os.environ.get("RELEASE_ID", "test")
|
||||||
RELEASEMODE = os.environ.get("RELEASEMODE", "dev")
|
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")
|
# Some constant configured stuff configs
|
||||||
ALLOWED_ORIGINS = os.environ.get('ALLOWED_ORIGINS', '*')
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
SECURITY_REGISTERABLE = True
|
||||||
|
SECURITY_PASSWORD_HASH = "bcrypt"
|
||||||
|
@ -14,9 +14,6 @@ __version__text__ = "1"
|
|||||||
|
|
||||||
class ItemView(FlaskView):
|
class ItemView(FlaskView):
|
||||||
|
|
||||||
route_prefix = "/item/"
|
|
||||||
route_base = '/'
|
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -14,8 +14,5 @@ __version__text__ = "1"
|
|||||||
|
|
||||||
class ProfileView(FlaskView):
|
class ProfileView(FlaskView):
|
||||||
|
|
||||||
route_prefix = "/profile/"
|
|
||||||
route_base = '/'
|
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
pass
|
pass
|
||||||
|
@ -14,8 +14,5 @@ __version__text__ = "1"
|
|||||||
|
|
||||||
class UploadView(FlaskView):
|
class UploadView(FlaskView):
|
||||||
|
|
||||||
route_prefix = "/upload/"
|
|
||||||
route_base = '/'
|
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user