Skip to content

Commit

Permalink
added settings_prod.py for apps
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed May 13, 2024
1 parent 7cbf3f0 commit ba0ca2d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lab/ppn_backend/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@
SESSION_COOKIE_AGE = 60 * 60 * 12 # 12 hours
VUE_MANIFEST = BASE_DIR / "main/static/vue/manifest.json"
VUE_URL = "/static/vue/"


# used for loading secrets when deployed with docker
def secret(name):
path = Path('/run/secrets') / name
return path.read_text().strip()
73 changes: 73 additions & 0 deletions lab/ppn_backend/settings_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from os import getenv

from ppn_backend.settings_base import *

# secrets
SECRET_KEY = secret("SECRET_KEY")
FIELD_ENCRYPTION_KEY = secret("FIELD_ENCRYPTION_KEY")

DEBUG = False
ADMINS = [('Admin', getenv('ADMIN_EMAIL'))]

ALLOWED_HOSTS = [getenv("LAB_SERVER")]
CSRF_TRUSTED_ORIGINS = ["https://" + getenv("LAB_SERVER")]

STATIC_ROOT = "/static"

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"HOST": getenv("DB_HOST"),
"NAME": getenv("DB_NAME"),
"USER": getenv("DB_USER"),
"PASSWORD": secret("DB_PASSWORD"),
}
}

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '[{asctime}] {name} ({levelname}): {message}',
'style': '{',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO', # DEBUG is possible, but is VERY verbose.
},
},
}

MIDDLEWARE += [
"csp.middleware.CSPMiddleware",
]

FRONTEND_URI = "https://" + getenv('LAB_SERVER')
PARENT_URI = "https://" + getenv('PARENT_SERVER')

# try:
# from .saml_settings import enable_saml
# enable_saml(globals())
# except ImportError:
# print("Proceeding without SAML")


# Email
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = getenv('EMAIL_HOST')
EMAIL_PORT = 587
EMAIL_FROM = getenv('EMAIL_FROM')
EMAIL_HOST_USER = getenv('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = secret('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = True

VUE_MANIFEST = "/static/vue/manifest.json"
6 changes: 6 additions & 0 deletions parent/parent/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,9 @@

VUE_MANIFEST = BASE_DIR / "parent/static/vue/manifest.json"
VUE_URL = "/static/vue/"


# used for loading secrets when deployed with docker
def secret(name):
path = Path("/run/secrets") / name
return path.read_text().strip()
25 changes: 25 additions & 0 deletions parent/parent/settings_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from os import getenv

from parent.settings import *

DEBUG = False
ADMINS = [("Admin", getenv("ADMIN_EMAIL"))]

ALLOWED_HOSTS = [getenv("PARENT_SERVER")]
CSRF_TRUSTED_ORIGINS = ["https://" + getenv("PARENT_SERVER")]

STATIC_ROOT = "/static"

API_HOST = getenv("LAB_SERVER")


# Email
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = getenv("EMAIL_HOST")
EMAIL_PORT = 587
EMAIL_FROM = getenv("EMAIL_FROM")
EMAIL_HOST_USER = getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = secret("EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = True

VUE_MANIFEST = "/static/vue/manifest.json"

0 comments on commit ba0ca2d

Please sign in to comment.