Browse Source

Take configuration from environment variables.

pull/7/head
Pēteris Caune 10 years ago
parent
commit
75b0e36b12
1 changed files with 7 additions and 15 deletions
  1. +7
    -15
      hc/settings.py

+ 7
- 15
hc/settings.py View File

@ -10,25 +10,17 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/ https://docs.djangoproject.com/en/1.8/ref/settings/
""" """
import json
import os import os
import os.environ as env
import warnings import warnings
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
p = os.path.expanduser("~/.hc.json")
if os.path.exists(p):
env = json.loads(open(p).read())
else:
warnings.warn("~/.hc.json does not exist, using defaults")
env = {}
SECRET_KEY = env.get("secret_key", "---")
SECRET_KEY = env.get("HC_SECRET_KEY", "---")
if SECRET_KEY is "---": if SECRET_KEY is "---":
warnings.warn("SECRET_KEY is not set, this is insecure")
warnings.warn("HC_SECRET_KEY environment variable is not set!")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
@ -92,7 +84,7 @@ DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'hc', 'NAME': 'hc',
'USER': env.get("pg_user", "postgres"),
'USER': env.get("PG_USER", "postgres"),
'TEST': {'CHARSET': 'UTF8'} 'TEST': {'CHARSET': 'UTF8'}
} }
} }
@ -112,14 +104,14 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
SITE_ROOT = env.get("site_root", "http://localhost:8000")
SITE_ROOT = env.get("HC_SITE_ROOT", "http://localhost:8000")
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
STATIC_ROOT = os.path.join(BASE_DIR, 'static-collected') STATIC_ROOT = os.path.join(BASE_DIR, 'static-collected')
# AWS # AWS
EMAIL_BACKEND = 'django_ses_backend.SESBackend' EMAIL_BACKEND = 'django_ses_backend.SESBackend'
AWS_SES_ACCESS_KEY_ID = env.get("aws_ses_access_key")
AWS_SES_SECRET_ACCESS_KEY = env.get("aws_ses_secret_key")
AWS_SES_ACCESS_KEY_ID = env.get("AWS_SES_ACCESS_KEY_ID")
AWS_SES_SECRET_ACCESS_KEY = env.get("AWS_SES_SECRET_ACCESS_KEY")
AWS_SES_REGION_NAME = 'eu-west-1' AWS_SES_REGION_NAME = 'eu-west-1'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-1.amazonaws.com' AWS_SES_REGION_ENDPOINT = 'email.eu-west-1.amazonaws.com'

Loading…
Cancel
Save