1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

feat(settings): database (PostgreSQL) and SMTP are configurable from the environment

This commit is contained in:
catborise 2026-10-07 15:50:07 +03:00
parent 9f5e8fe1c4
commit 85706c5df6
5 changed files with 99 additions and 13 deletions

View file

@ -134,12 +134,26 @@ WSGI_APPLICATION = "webvirtcloud.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": Path.joinpath(BASE_DIR, "db.sqlite3"),
# sqlite by default; PostgreSQL when WEBVIRTCLOUD_DB_HOST is set (a host name,
# an IP, or a unix socket directory).
if db_host := os.getenv("WEBVIRTCLOUD_DB_HOST"):
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": db_host,
"PORT": os.getenv("WEBVIRTCLOUD_DB_PORT", "5432"),
"NAME": os.getenv("WEBVIRTCLOUD_DB_NAME", "webvirtcloud"),
"USER": os.getenv("WEBVIRTCLOUD_DB_USER", "webvirtcloud"),
"PASSWORD": os.getenv("WEBVIRTCLOUD_DB_PASSWORD", ""),
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": Path.joinpath(BASE_DIR, "db.sqlite3"),
}
}
}
AUTHENTICATION_BACKENDS = [
# first: refuses logins that are locked out
@ -355,15 +369,15 @@ SPECTACULAR_SETTINGS = {
"REDOC_DIST": "SIDECAR",
}
# EMAIL Config
# EMAIL Config (SMTP; override through the environment)
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = os.getenv("EMAIL_HOST", "smtp.gmail.com")
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", "1") == "1"
EMAIL_PORT = int(os.getenv("EMAIL_PORT", "587"))
## sender's email-id
EMAIL_HOST_USER = ''
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
## password associated with above email-id
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
# LDAP Config
#