diff --git a/retail_order_api/.env.template b/retail_order_api/.env.template new file mode 100644 index 0000000..4715066 --- /dev/null +++ b/retail_order_api/.env.template @@ -0,0 +1,32 @@ +# Django +SECRET_KEY=your_secret_key +DEBUG=True + +# PostgreSQL +ALLOWED_HOSTS=localhost,127.0.0.1 +DB_ENGINE=django.db.backends.postgresql +DB_NAME=your_db_name +DB_USER=your_db_user +DB_PASSWORD=your_db_password +DB_HOST=your_db_host +DB_PORT=your_db_port + +# SMTP +EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend +EMAIL_HOST=your_email_host +EMAIL_HOST_USER=your_email_host_user +EMAIL_HOST_PASSWORD=your_email_host_password +EMAIL_PORT=your_email_port +EMAIL_USE_TLS=True + +# Google Auth +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=your_google_oauth2_key +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=your_google_oauth2_secret + +# GitHub Auth +SOCIAL_AUTH_GITHUB_KEY=your_github_key +SOCIAL_AUTH_GITHUB_SECRET=your_github_secret + +# Celery +CELERY_BROKER_URL=your_celery_broker_url +CELERY_RESULT_BACKEND=your_celery_result_backend diff --git a/retail_order_api/.env_example b/retail_order_api/.env_example deleted file mode 100644 index 7457cbf..0000000 --- a/retail_order_api/.env_example +++ /dev/null @@ -1,32 +0,0 @@ -# Django -SECRET_KEY= -DEBUG= - -# PostgreSQL -ALLOWED_HOSTS= -DB_ENGINE= -DB_NAME= -DB_HOST= -DB_PORT= -DB_USER= -DB_PASSWORD= - -# SMTP -EMAIL_BACKEND= -EMAIL_HOST= -EMAIL_HOST_USER= -EMAIL_HOST_PASSWORD= -EMAIL_PORT= -EMAIL_USE_TLS= - -# Google Auth -SOCIAL_AUTH_GOOGLE_OAUTH2_KEY= -SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET= - -# GitHub Auth -SOCIAL_AUTH_GITHUB_KEY= -SOCIAL_AUTH_GITHUB_SECRET= - -# Celery -CELERY_BROKER_URL= -CELERY_RESULT_BACKEND= diff --git a/retail_order_api/requirements.txt b/retail_order_api/requirements.txt index 2bf0ef6..da4cd7e 100644 Binary files a/retail_order_api/requirements.txt and b/retail_order_api/requirements.txt differ diff --git a/retail_order_api/retail_order_api/settings.py b/retail_order_api/retail_order_api/settings.py index db98560..69253ce 100644 --- a/retail_order_api/retail_order_api/settings.py +++ b/retail_order_api/retail_order_api/settings.py @@ -2,14 +2,16 @@ from datetime import timedelta from pathlib import Path -from dotenv import load_dotenv - -load_dotenv() +import environ BASE_DIR = Path(__file__).resolve().parent.parent -SECRET_KEY = os.getenv("SECRET_KEY") -DEBUG = os.getenv("DEBUG").lower() == "true" -ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS").split(",") + +env = environ.Env() +environ.Env.read_env(os.path.join(BASE_DIR, ".env")) + +SECRET_KEY = env.str("SECRET_KEY", "") +DEBUG = env.bool("DEBUG", True) +ALLOWED_HOSTS = env.list("ALLOWED_HOSTS") INSTALLED_APPS = [ "baton", @@ -44,7 +46,7 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(BASE_DIR, "templates")], + "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -65,12 +67,12 @@ DATABASES = { "default": { - "ENGINE": os.getenv("DB_ENGINE"), - "NAME": os.getenv("DB_NAME"), - "HOST": os.getenv("DB_HOST"), - "PORT": os.getenv("DB_PORT"), - "USER": os.getenv("DB_USER"), - "PASSWORD": os.getenv("DB_PASSWORD"), + "ENGINE": env.str("DB_ENGINE", "django.db.backends.sqlite3"), + "NAME": env.str("DB_NAME", os.path.join(BASE_DIR, "db.sqlite3")), + "USER": env.str("DB_USER", "user"), + "PASSWORD": env.str("DB_PASSWORD", "password"), + "HOST": env.str("DB_HOST", "localhost"), + "PORT": env.str("DB_PORT", "5432"), } } @@ -129,12 +131,12 @@ # SMTP -EMAIL_BACKEND = os.getenv("EMAIL_BACKEND") -EMAIL_HOST = os.getenv("EMAIL_HOST") -EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER") -EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") -EMAIL_PORT = os.getenv("EMAIL_PORT") -EMAIL_USE_TLS = os.getenv("DEBUG").lower() == "true" +EMAIL_BACKEND = env.str("EMAIL_BACKEND", "") +EMAIL_HOST = env.str("EMAIL_HOST", "") +EMAIL_HOST_USER = env.str("EMAIL_HOST_USER", "") +EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD", "") +EMAIL_PORT = env.str("EMAIL_PORT", "") +EMAIL_USE_TLS = env.str("EMAIL_USE_TLS", "") # Djoser @@ -174,12 +176,12 @@ # Google OAuth2 SOCIAL_AUTH_USER_MODEL = "backend.CustomUser" -SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.getenv("SOCIAL_AUTH_GOOGLE_OAUTH2_KEY") -SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.getenv("SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET") +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = env.str("SOCIAL_AUTH_GOOGLE_OAUTH2_KEY", "") +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = env.str("SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET", "") # Github OAuth2 -SOCIAL_AUTH_GITHUB_KEY = os.getenv("SOCIAL_AUTH_GITHUB_KEY") -SOCIAL_AUTH_GITHUB_SECRET = os.getenv("SOCIAL_AUTH_GITHUB_SECRET") +SOCIAL_AUTH_GITHUB_KEY = env.str("SOCIAL_AUTH_GITHUB_KEY", "") +SOCIAL_AUTH_GITHUB_SECRET = env.str("SOCIAL_AUTH_GITHUB_SECRET", "") SOCIAL_AUTH_GITHUB_SCOPE = ["read:user", "user:email"] AUTHENTICATION_BACKENDS = ( @@ -205,8 +207,8 @@ } # Celery -CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND") -CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL") +CELERY_RESULT_BACKEND = env.str("CELERY_RESULT_BACKEND", "redis://localhost:6379") +CELERY_BROKER_URL = env.str("CELERY_BROKER_URL", "redis://localhost:6379") # django-baton