Beef up the Production check a little and do true comparison correctly.

This commit is contained in:
Ben Rog-Wilhelm 2022-11-21 09:38:00 -06:00 committed by Ben Rog-Wilhelm
parent 2067875c6a
commit 18437003cf
4 changed files with 12 additions and 3 deletions

View file

@ -12,6 +12,7 @@ services:
environment:
- DATABASE_URL=postgresql://postgres@postgres:5432
- REDIS_URL=redis://redis
- ENFORCE_PRODUCTION=False
links:
- "redis"
- "postgres"

2
env
View file

@ -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

View file

@ -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:

View file

@ -1,4 +1,11 @@
# clean strings for searching
def sql_ilike_clean(my_str):
return my_str.replace(r'\\', '').replace('_', r'\_').replace('%', '').strip()
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()