Skip to content

Commit

Permalink
refactor: do not load .prod.env in production
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Sep 29, 2022
1 parent f2f2f76 commit f493a0d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions tenlists/webapp/ten_lists/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class BaseConfig(object):

TIMEZONE = "Africa/Lusaka"

env_path = os.path.join(PROJECT_ROOT, "env/.default.env")
load_dotenv(dotenv_path=env_path)
# This is rather redundant, as it is handled in create_app()
if os.environ.get("FLASK_CONFIGURATION") == "default":
env_path = os.path.join(PROJECT_ROOT, "env/.default.env")
load_dotenv(dotenv_path=env_path)

# Secret key for generating tokens
SECRET_KEY = os.getenv("TENLISTS_SECRET_KEY")
Expand All @@ -44,8 +46,10 @@ class DevelopmentConfig(BaseConfig):
# DEBUG can only be set to True in a development environment for security reasons
DEBUG = True

env_path = os.path.join(PROJECT_ROOT, "env/.dev.env")
load_dotenv(dotenv_path=env_path, override=True, verbose=True)
# This is rather redundant, as it is handled in create_app()
if os.environ.get("FLASK_CONFIGURATION") == "development":
env_path = os.path.join(PROJECT_ROOT, "env/.dev.env")
load_dotenv(dotenv_path=env_path, override=True, verbose=True)

# Secret key for generating tokens
SECRET_KEY = os.getenv("TENLISTS_SECRET_KEY_DEV")
Expand Down Expand Up @@ -75,8 +79,10 @@ class StagingConfig(BaseConfig):

DEBUG = False

env_path = os.path.join(PROJECT_ROOT, "env/.stage.env")
load_dotenv(dotenv_path=env_path, override=True)
# This is rather redundant, as it is handled in create_app()
if os.environ.get("FLASK_CONFIGURATION") == "staging":
env_path = os.path.join(PROJECT_ROOT, "env/.stage.env")
load_dotenv(dotenv_path=env_path, override=True)

# Secret key for generating tokens
SECRET_KEY = os.getenv("TENLISTS_SECRET_KEY")
Expand All @@ -102,8 +108,16 @@ class ProductionConfig(BaseConfig):
DEBUG = False
SESSION_COOKIE_SECURE = True

env_path = os.path.join(PROJECT_ROOT, "env/.prod.env")
load_dotenv(dotenv_path=env_path, override=True)
# =========================================================== #

# skip loading .prod.env file since we're running in docker container

# Also, this is rather redundant, as it is handled in create_app()
# if os.environ.get("FLASK_CONFIGURATION") == "production":
# env_path = os.path.join(PROJECT_ROOT, "env/.prod.env")
# load_dotenv(dotenv_path=env_path, override=True)

# =========================================================== #

# Secret key for generating tokens
SECRET_KEY = os.getenv("TENLISTS_SECRET_KEY")
Expand Down

0 comments on commit f493a0d

Please sign in to comment.