mirror of
https://github.com/lemeow125/DRF_Template.git
synced 2024-11-17 04:09:25 +08:00
Clean up imports and .env variables
This commit is contained in:
parent
71eda8a496
commit
658753dea4
4 changed files with 51 additions and 58 deletions
26
.env.sample
26
.env.sample
|
@ -1,9 +1,11 @@
|
||||||
# Django
|
# Django
|
||||||
### Use https://djecrety.ir/ for generation!
|
# Use https://djecrety.ir/ for generation
|
||||||
SECRET_KEY = ''
|
SECRET_KEY = ''
|
||||||
|
|
||||||
# Production Switches
|
# Production Switches
|
||||||
BACKEND_DEBUG = 'True'
|
BACKEND_DEBUG = 'True'
|
||||||
|
USE_VAULT = 'False'
|
||||||
|
SERVE_MEDIA = 'False'
|
||||||
|
|
||||||
# Superuser Credentials
|
# Superuser Credentials
|
||||||
DJANGO_ADMIN_USERNAME = 'admin'
|
DJANGO_ADMIN_USERNAME = 'admin'
|
||||||
|
@ -23,7 +25,7 @@ EMAIL_USE_TLS = 'False'
|
||||||
EMAIL_ADDRESS = 'noreply-testing@drf-template.com'
|
EMAIL_ADDRESS = 'noreply-testing@drf-template.com'
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
### Have different credentials set on dev, staging, and prod!
|
# Have different credentials set on dev, staging, and prod
|
||||||
DB_DATABASE = 'drf-template'
|
DB_DATABASE = 'drf-template'
|
||||||
DB_USERNAME = 'root'
|
DB_USERNAME = 'root'
|
||||||
DB_PASSWORD = ''
|
DB_PASSWORD = ''
|
||||||
|
@ -32,7 +34,7 @@ DB_PORT = '5432'
|
||||||
DB_SSL_MODE = 'disable'
|
DB_SSL_MODE = 'disable'
|
||||||
|
|
||||||
# Redis
|
# Redis
|
||||||
### Used for DB cache and Celery broker
|
# Used for DB cache and Celery broker
|
||||||
REDIS_HOST = 'redis'
|
REDIS_HOST = 'redis'
|
||||||
REDIS_PORT = '6379'
|
REDIS_PORT = '6379'
|
||||||
|
|
||||||
|
@ -44,16 +46,24 @@ CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
|
||||||
STRIPE_SECRET_KEY = ''
|
STRIPE_SECRET_KEY = ''
|
||||||
STRIPE_SECRET_WEBHOOK = ''
|
STRIPE_SECRET_WEBHOOK = ''
|
||||||
|
|
||||||
BACKEND_DOMAIN = 'localhost:8000'
|
USE_VAULT = 'False'
|
||||||
DOMAIN = 'localhost:4200'
|
SERVE_MEDIA = 'False'
|
||||||
|
BACKEND_URL = 'localhost:8000'
|
||||||
|
FRONTEND_URL = 'localhost:4200'
|
||||||
USE_HTTPS = 'False'
|
USE_HTTPS = 'False'
|
||||||
DJANGO_PORT = '8000'
|
TIMEZONE = 'Asia/Manila'
|
||||||
|
|
||||||
|
# Cloud Storage
|
||||||
|
# No need to set these if you're not using S3
|
||||||
|
CLOUD_BUCKET = ''
|
||||||
|
MEDIA_CONTAINER = ''
|
||||||
|
STATIC_CONTAINER = ''
|
||||||
|
|
||||||
# Proxy (For Selenium)
|
# Proxy (For Selenium)
|
||||||
USE_PROXY = 'False'
|
USE_PROXY = 'False'
|
||||||
## IP-Whitelisted Proxy Address
|
# IP-Whitelisted Proxy Address
|
||||||
PROXY_IP_WHITELIST = 'proxy-here.com:12345'
|
PROXY_IP_WHITELIST = 'proxy-here.com:12345'
|
||||||
## Username/Password Proxy Address
|
# Username/Password Proxy Address
|
||||||
PROXY_USER_AUTH = 'username:password@proxy-here.com:12345'
|
PROXY_USER_AUTH = 'username:password@proxy-here.com:12345'
|
||||||
|
|
||||||
# CAPTCHA
|
# CAPTCHA
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from config.settings import DEBUG, CLOUD, MEDIA_ROOT
|
from config.settings import DEBUG, SERVE_MEDIA, MEDIA_ROOT
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('accounts/', include('accounts.urls')),
|
path('accounts/', include('accounts.urls')),
|
||||||
path('subscriptions/', include('subscriptions.urls')),
|
path('subscriptions/', include('subscriptions.urls')),
|
||||||
|
@ -11,7 +11,7 @@ urlpatterns = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# URLs for local development
|
# URLs for local development
|
||||||
if DEBUG and not CLOUD:
|
if DEBUG and SERVE_MEDIA:
|
||||||
urlpatterns += staticfiles_urlpatterns()
|
urlpatterns += staticfiles_urlpatterns()
|
||||||
urlpatterns += static(
|
urlpatterns += static(
|
||||||
'media/', document_root=MEDIA_ROOT)
|
'media/', document_root=MEDIA_ROOT)
|
||||||
|
|
|
@ -1,15 +1,3 @@
|
||||||
"""
|
|
||||||
Django settings for test backend project.
|
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 4.2.6.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
|
||||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
|
||||||
"""
|
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dotenv import load_dotenv, find_dotenv # Python dotenv
|
from dotenv import load_dotenv, find_dotenv # Python dotenv
|
||||||
|
@ -21,17 +9,19 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
# Root folder where docker-compose.yml is located
|
# Root folder where docker-compose.yml is located
|
||||||
ROOT_DIR = Path(__file__).resolve().parent.parent.parent
|
ROOT_DIR = Path(__file__).resolve().parent.parent.parent
|
||||||
|
|
||||||
# If you're hosting this on the cloud, have this set
|
# If you're hosting this with a secret provider, have this set to True
|
||||||
CLOUD = bool(os.getenv('CLOUD', False))
|
USE_VAULT = bool(os.getenv('USE_VAULT', False) == 'True')
|
||||||
|
# Have this set to True to serve media and static contents directly via Django
|
||||||
|
SERVE_MEDIA = bool(os.getenv('SERVE_MEDIA', False) == 'True')
|
||||||
|
|
||||||
load_dotenv(find_dotenv())
|
load_dotenv(find_dotenv())
|
||||||
|
|
||||||
|
|
||||||
def get_secret(secret_name):
|
def get_secret(secret_name):
|
||||||
if CLOUD:
|
if USE_VAULT:
|
||||||
try:
|
try:
|
||||||
pass
|
pass
|
||||||
# Add specific implementations here if deploying to Azure, GCP, or AWS to get secrets
|
# Add specific implementations here if deploying to Azure, GCP, or AWS to get secrets from vault
|
||||||
except:
|
except:
|
||||||
secret_value = ""
|
secret_value = ""
|
||||||
else:
|
else:
|
||||||
|
@ -44,25 +34,18 @@ def get_secret(secret_name):
|
||||||
return secret_value
|
return secret_value
|
||||||
|
|
||||||
|
|
||||||
# Frontend Domain
|
|
||||||
DOMAIN = get_secret('DOMAIN')
|
|
||||||
# Backend Domain
|
|
||||||
BACKEND_DOMAIN = get_secret('BACKEND_DOMAIN')
|
|
||||||
# URL Prefixes
|
# URL Prefixes
|
||||||
USE_HTTPS = (get_secret('USE_HTTPS') == 'True')
|
USE_HTTPS = (get_secret('USE_HTTPS') == 'True')
|
||||||
URL_PREFIX = 'https://' if CLOUD and USE_HTTPS else 'http://'
|
URL_PREFIX = 'https://' if USE_HTTPS else 'http://'
|
||||||
BACKEND_URL = f'{URL_PREFIX}{BACKEND_DOMAIN}'
|
BACKEND_URL = URL_PREFIX + get_secret('BACKEND_URL')
|
||||||
FRONTEND_URL = f'{URL_PREFIX}{DOMAIN}'
|
FRONTEND_URL = URL_PREFIX + get_secret('FRONTEND_URL')
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
BACKEND_URL,
|
BACKEND_URL,
|
||||||
FRONTEND_URL
|
FRONTEND_URL
|
||||||
|
# You can also set up https://*.name.xyz for wildcards here
|
||||||
]
|
]
|
||||||
if CLOUD:
|
|
||||||
# TODO: If you require additional URLs to be trusted in cloud service providers, add them here
|
|
||||||
CSRF_TRUSTED_ORIGINS += []
|
|
||||||
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = (get_secret('BACKEND_DEBUG') == 'True')
|
DEBUG = (get_secret('BACKEND_DEBUG') == 'True')
|
||||||
|
@ -142,17 +125,18 @@ MIDDLEWARE = [
|
||||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||||
|
|
||||||
ROOT_URLCONF = 'config.urls'
|
ROOT_URLCONF = 'config.urls'
|
||||||
if CLOUD:
|
if SERVE_MEDIA:
|
||||||
# Cloud Storage Settings
|
# Cloud Storage Settings
|
||||||
|
# This is assuming you use the same bucket for media and static containers
|
||||||
CLOUD_BUCKET = get_secret('CLOUD_BUCKET')
|
CLOUD_BUCKET = get_secret('CLOUD_BUCKET')
|
||||||
CLOUD_BUCKET_CONTAINER = get_secret('CLOUD_BUCKET_CONTAINER')
|
MEDIA_CONTAINER = get_secret('MEDIA_CONTAINER')
|
||||||
CLOUD_STATIC_CONTAINER = get_secret('CLOUD_STATIC_CONTAINER')
|
STATIC_CONTAINER = get_secret('STATIC_CONTAINER')
|
||||||
|
|
||||||
MEDIA_URL = f'https://{CLOUD_BUCKET}/{CLOUD_BUCKET_CONTAINER}/'
|
MEDIA_URL = f'https://{CLOUD_BUCKET}/{MEDIA_CONTAINER}/'
|
||||||
MEDIA_ROOT = f'https://{CLOUD_BUCKET}/'
|
MEDIA_ROOT = f'https://{CLOUD_BUCKET}/'
|
||||||
|
|
||||||
STATIC_URL = f'https://{CLOUD_BUCKET}/{CLOUD_STATIC_CONTAINER}/'
|
STATIC_URL = f'https://{CLOUD_BUCKET}/{STATIC_CONTAINER}/'
|
||||||
STATIC_ROOT = f'https://{CLOUD_BUCKET}/{CLOUD_STATIC_CONTAINER}/'
|
STATIC_ROOT = f'https://{CLOUD_BUCKET}/{STATIC_CONTAINER}/'
|
||||||
|
|
||||||
# Consult django-storages documentation when filling in these values. This will vary depending on your cloud service provider
|
# Consult django-storages documentation when filling in these values. This will vary depending on your cloud service provider
|
||||||
STORAGES = {
|
STORAGES = {
|
||||||
|
@ -235,7 +219,7 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
# Have this set to True if you're using a connection bouncer
|
# Set to True to avoid issues with pgbouncer when pooling connections
|
||||||
'DISABLE_SERVER_SIDE_CURSORS': True,
|
'DISABLE_SERVER_SIDE_CURSORS': True,
|
||||||
"NAME": get_secret("DB_DATABASE"),
|
"NAME": get_secret("DB_DATABASE"),
|
||||||
"USER": get_secret("DB_USERNAME"),
|
"USER": get_secret("DB_USERNAME"),
|
||||||
|
@ -247,6 +231,16 @@ DATABASES = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# Django Cache
|
||||||
|
CACHES = {
|
||||||
|
"default": {
|
||||||
|
"BACKEND": "django_redis.cache.RedisCache",
|
||||||
|
"LOCATION": f"redis://{get_secret('REDIS_HOST')}:{get_secret('REDIS_PORT')}/2",
|
||||||
|
"OPTIONS": {
|
||||||
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'accounts.CustomUser'
|
AUTH_USER_MODEL = 'accounts.CustomUser'
|
||||||
|
|
||||||
|
@ -314,7 +308,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'Asia/Manila'
|
TIME_ZONE = get_secret('TIMEZONE')
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
|
@ -330,7 +324,7 @@ SITE_NAME = 'DRF-Template'
|
||||||
|
|
||||||
# JWT Token Lifetimes
|
# JWT Token Lifetimes
|
||||||
SIMPLE_JWT = {
|
SIMPLE_JWT = {
|
||||||
"ACCESS_TOKEN_LIFETIME": timedelta(hours=6),
|
"ACCESS_TOKEN_LIFETIME": timedelta(hours=1),
|
||||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=3)
|
"REFRESH_TOKEN_LIFETIME": timedelta(days=3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,14 +367,3 @@ DATA_UPLOAD_MAX_NUMBER_FIELDS = 20480
|
||||||
GRAPH_MODELS = {
|
GRAPH_MODELS = {
|
||||||
'app_labels': ['accounts', 'user_groups', 'billing', 'emails', 'payments', 'subscriptions']
|
'app_labels': ['accounts', 'user_groups', 'billing', 'emails', 'payments', 'subscriptions']
|
||||||
}
|
}
|
||||||
|
|
||||||
# Django/DRF Cache
|
|
||||||
CACHES = {
|
|
||||||
"default": {
|
|
||||||
"BACKEND": "django_redis.cache.RedisCache",
|
|
||||||
"LOCATION": f"redis://{get_secret('REDIS_HOST')}:{get_secret('REDIS_PORT')}/2",
|
|
||||||
"OPTIONS": {
|
|
||||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from config.settings import STRIPE_SECRET_KEY, DOMAIN, STRIPE_SECRET_WEBHOOK, CLOUD, BACKEND_URL, FRONTEND_URL
|
from config.settings import STRIPE_SECRET_KEY, STRIPE_SECRET_WEBHOOK, FRONTEND_URL
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
Loading…
Reference in a new issue