diff --git a/docker-compose.yml b/docker-compose.yml index 651e4afa9..39cfa2100 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: environment: - DATABASE_URL=postgresql://postgres@postgres:5432 - REDIS_URL=redis://redis + - ENFORCE_PRODUCTION=False links: - "redis" - "postgres" diff --git a/env b/env index 781ce8bf9..33b81643d 100644 --- a/env +++ b/env @@ -2,7 +2,7 @@ MASTER_KEY=blahblahblah DOMAIN=localhost SITE_ID=TheMotte SITE_TITLE=The Motte -ENFORCE_PRODUCTION=False +ENFORCE_PRODUCTION=True GIPHY_KEY=blahblahblah DISCORD_SERVER_ID=blahblahblah DISCORD_CLIENT_ID=blahblahblah diff --git a/files/__main__.py b/files/__main__.py index a3b361313..0cec70e29 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -4,6 +4,7 @@ import gevent.monkey gevent.monkey.patch_all() from os import environ, path import secrets +from files.helpers.strings import bool_from_string from flask import * from flask_caching import Cache from flask_limiter import Limiter @@ -27,7 +28,7 @@ app.jinja_env.cache = {} app.jinja_env.auto_reload = True faulthandler.enable() -if environ.get("ENFORCE_PRODUCTION", False) and app.config["DEBUG"]: +if bool_from_string(environ.get("ENFORCE_PRODUCTION", "true")) and app.config["DEBUG"]: raise ValueError("Debug mode is not allowed! If this is a dev environment, please set ENFORCE_PRODUCTION to false") if environ.get("SITE_ID") is None: diff --git a/files/helpers/strings.py b/files/helpers/strings.py index 2fdbdf804..7e2d26fea 100644 --- a/files/helpers/strings.py +++ b/files/helpers/strings.py @@ -1,4 +1,11 @@ # clean strings for searching def sql_ilike_clean(my_str): - return my_str.replace(r'\\', '').replace('_', r'\_').replace('%', '').strip() \ No newline at end of file + return my_str.replace(r'\\', '').replace('_', r'\_').replace('%', '').strip() + +def bool_from_string(str_in: str) -> bool: + if str_in.lower() in ("yes", "true", "t", "1"): + return True + if str_in.lower() in ("no", "false", "f", "0"): + return False + raise ValueError()