Browse Source

secrets file mechanism added to have a way to store passwd out of git

master
Benni Baermann 4 years ago
parent
commit
1be2d1faee
2 changed files with 20 additions and 1 deletions
  1. +4
    -1
      .gitignore
  2. +16
    -0
      foerderbarometer/settings.py

+ 4
- 1
.gitignore View File

@ -1,4 +1,8 @@
# ---> Python # ---> Python
# secret passwords and so
/secrets.json
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
@ -128,4 +132,3 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/

+ 16
- 0
foerderbarometer/settings.py View File

@ -10,14 +10,29 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/ https://docs.djangoproject.com/en/3.1/ref/settings/
""" """
import json
import os
from pathlib import Path from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
# mails in development go to stdout # mails in development go to stdout
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
# get secrets
with open(os.path.join(BASE_DIR, 'secrets.json')) as secrets_file:
secrets = json.load(secrets_file)
def get_secret(setting, secrets=secrets):
"""Get secret setting or fail with ImproperlyConfigured"""
try:
return secrets[setting]
except KeyError:
raise ImproperlyConfigured("Set the {} setting".format(setting))
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
@ -85,6 +100,7 @@ DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3',
'PASSWORD': get_secret('DATABASE_PASSWORD')
} }
} }

Loading…
Cancel
Save