From ff13a24560335f00b071e5f0fb9e2bc5f327be0e Mon Sep 17 00:00:00 2001 From: BDlhj Date: Mon, 25 Nov 2024 00:43:54 +0900 Subject: [PATCH] refactor: Replace dotenv with django-environ and enhance security --- backoffice/settings/base.py | 10 ++++++---- backoffice/settings/local.py | 2 ++ backoffice/settings/prod.py | 2 -- poetry.lock | 18 +++++++++++++++++- pyproject.toml | 1 + 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/backoffice/settings/base.py b/backoffice/settings/base.py index 4b44b5c..e59abfb 100644 --- a/backoffice/settings/base.py +++ b/backoffice/settings/base.py @@ -13,21 +13,23 @@ import os from pathlib import Path -from dotenv import load_dotenv +import environ -load_dotenv() +env = environ.Env(DEBUG=(bool, False)) # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent.parent +environ.Env.read_env(os.path.join(BASE_DIR, ".env")) + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.getenv("SECRET_KEY") +SECRET_KEY = env("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = [] diff --git a/backoffice/settings/local.py b/backoffice/settings/local.py index b5d67c8..68ade3e 100644 --- a/backoffice/settings/local.py +++ b/backoffice/settings/local.py @@ -1,5 +1,7 @@ from .base import * # noqa: F401, F403 +DEBUG = True + INTERNAL_IPS = [ "127.0.0.1", "localhost", diff --git a/backoffice/settings/prod.py b/backoffice/settings/prod.py index 40cfecf..4d931af 100644 --- a/backoffice/settings/prod.py +++ b/backoffice/settings/prod.py @@ -1,7 +1,5 @@ from .base import * # noqa: F401, F403 -DEBUG = False - ALLOWED_HOSTS = ["*"] # TODO: 추후 도메인 설정 후 변경 # TODO: 추후 도메인 설정 후 CSRF_TRUSTED_ORIGINS, CORS_ALLOWED_ORIGINS에 추가 diff --git a/poetry.lock b/poetry.lock index 88c5dca..a0627a4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -149,6 +149,22 @@ files = [ django = ">=4.2.9" sqlparse = ">=0.2" +[[package]] +name = "django-environ" +version = "0.11.2" +description = "A package that allows you to utilize 12factor inspired environment variables to configure your Django application." +optional = false +python-versions = ">=3.6,<4" +files = [ + {file = "django-environ-0.11.2.tar.gz", hash = "sha256:f32a87aa0899894c27d4e1776fa6b477e8164ed7f6b3e410a62a6d72caaf64be"}, + {file = "django_environ-0.11.2-py2.py3-none-any.whl", hash = "sha256:0ff95ab4344bfeff693836aa978e6840abef2e2f1145adff7735892711590c05"}, +] + +[package.extras] +develop = ["coverage[toml] (>=5.0a4)", "furo (>=2021.8.17b43,<2021.9.dev0)", "pytest (>=4.6.11)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] +docs = ["furo (>=2021.8.17b43,<2021.9.dev0)", "sphinx (>=3.5.0)", "sphinx-notfound-page"] +testing = ["coverage[toml] (>=5.0a4)", "pytest (>=4.6.11)"] + [[package]] name = "django-extensions" version = "3.2.3" @@ -382,4 +398,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.13" -content-hash = "a84fb51aa59057f705a9cc1809355ee944c8ab3f6222de2473b12d33b0e967a3" +content-hash = "84919ed43c0ea286ed1ebc4eb2fa27adad1aae3a01599a7c12b8b7d9e9d058ef" diff --git a/pyproject.toml b/pyproject.toml index c87e3cc..cfb581c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ django = "^5.1.3" python-dotenv = "^1.0.1" django-cors-headers = "^4.6.0" django-extensions = "^3.2.3" +django-environ = "^0.11.2" [tool.poetry.group.dev.dependencies]