From 07435921a6e56362f010673b150dd097c48559f3 Mon Sep 17 00:00:00 2001 From: Bernd Meyer Date: Fri, 3 Oct 2014 08:04:09 -0700 Subject: [PATCH] Added database credentials and security check for db password. Added database credentials (user name: 'django', password: 'blank') and security check for db password. The security check will raise an error if the database password is 'blank' in production. --- .../{{cookiecutter.repo_name}}/config/__init__.py | 13 +++++++++++++ .../{{cookiecutter.repo_name}}/config/common.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/__init__.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/__init__.py index feb8c8e1..2fa0127a 100644 --- a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/__init__.py +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/__init__.py @@ -1,5 +1,18 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +import os +from django.conf import settings +from django.core.checks import register, Error from .local import Local # noqa from .production import Production # noqa + + +@register(settings) +def dj_database_url_check(app_configs=None, **kwargs): + errors = [] + password = settings.DATABASES['default'].get('PASSWORD') + config = os.environ['DJANGO_CONFIGURATION'].lower() + if password == 'blank' and config == 'production': + errors.append(Error('Change the database password for production.')) + return errors diff --git a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/common.py b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/common.py index caa4d199..46c3e2a8 100644 --- a/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/common.py +++ b/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/config/common.py @@ -112,7 +112,7 @@ class Common(Configuration): # DATABASE CONFIGURATION # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases - DATABASES = values.DatabaseURLValue('postgres://localhost/{{cookiecutter.repo_name}}') + DATABASES = values.DatabaseURLValue('postgres://localhost/django:blank{{cookiecutter.repo_name}}') # END DATABASE CONFIGURATION # CACHING