Commit 40ef4652 by Őry Máté

django: keep secrets in envvars

parent 4599b2b9
...@@ -2,10 +2,22 @@ ...@@ -2,10 +2,22 @@
# Django base settings for cloud project. # Django base settings for cloud project.
from os.path import join, abspath, dirname from os.path import join, abspath, dirname
import os
import subprocess import subprocess
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
def get_env_variable(var_name, default=None):
""" Get the environment variable or return exception/default """
try:
return os.environ[var_name]
except KeyError:
if default is None:
error_msg = "Set the %s environment variable" % var_name
raise ImproperlyConfigured(error_msg)
else:
return default
DEBUG = False DEBUG = False
TEMPLATE_DEBUG = False TEMPLATE_DEBUG = False
STAT_DEBUG = False STAT_DEBUG = False
...@@ -18,16 +30,12 @@ MANAGERS = ADMINS ...@@ -18,16 +30,12 @@ MANAGERS = ADMINS
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'ENGINE': 'django.db.backends.mysql',
# 'mysql', 'sqlite3' or 'oracle'. 'NAME': get_env_variable('DJANGO_DB_NAME', 'webadmin'),
'NAME': 'webadmin', # Or path to database file if 'USER': get_env_variable('DJANGO_DB_USER', 'webadmin'),
# using sqlite3. 'PASSWORD': get_env_variable('DJANGO_DB_PASSWORD'),
'USER': 'webadmin', # Not used with sqlite3. 'HOST': get_env_variable('DJANGO_DB_HOST', ''),
'PASSWORD': 'asjklddfjklqjf', # Not used with sqlite3. 'PORT': get_env_variable('DJANGO_DB_PORT', ''),
'HOST': '', # Set to empty string for localhost.
# Not used with sqlite3.
'PORT': '', # Set to empty string for default.
# Not used with sqlite3.
} }
} }
...@@ -91,7 +99,7 @@ STATICFILES_FINDERS = ( ...@@ -91,7 +99,7 @@ STATICFILES_FINDERS = (
) )
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
SECRET_KEY = 'sx%4b1oa2)mn%##6+e1+25g@r8ht(cqk(nko^fr66w&26f22ba' SECRET_KEY = get_env_variable('DJANGO_SECRET_KEY')
# List of callables that know how to import templates from various sources. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
...@@ -204,7 +212,7 @@ CELERY_CACHE_BACKEND = "default" ...@@ -204,7 +212,7 @@ CELERY_CACHE_BACKEND = "default"
CELERY_RESULT_BACKEND = "amqp" CELERY_RESULT_BACKEND = "amqp"
CELERY_TASK_RESULT_EXPIRES = 3600 CELERY_TASK_RESULT_EXPIRES = 3600
BROKER_URL = 'amqp://nyuszi:teszt@localhost:5672/django' BROKER_URL = get_env_variable('DJANGO_BROKER_URL', 'amqp://nyuszi:teszt@localhost:5672/django')
CELERY_ROUTES = { CELERY_ROUTES = {
'firewall.tasks.ReloadTask': {'queue': 'local'}, 'firewall.tasks.ReloadTask': {'queue': 'local'},
'firewall.tasks.reload_dns_task': {'queue': 'dns'}, 'firewall.tasks.reload_dns_task': {'queue': 'dns'},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment