|
1 | | -""" |
2 | | -Django settings for app project. |
| 1 | +from pathlib import Path |
3 | 2 |
|
4 | | -Generated by 'django-admin startproject' using Django 1.11. |
| 3 | +import environ |
5 | 4 |
|
6 | | -For more information on this file, see |
7 | | -https://docs.djangoproject.com/en/1.11/topics/settings/ |
| 5 | +PROJECT_DIR = Path(__file__).resolve().parent |
| 6 | +ROOT_DIR = PROJECT_DIR.parent |
8 | 7 |
|
9 | | -For the full list of settings and their values, see |
10 | | -https://docs.djangoproject.com/en/1.11/ref/settings/ |
11 | | -""" |
| 8 | +# Environment |
12 | 9 |
|
13 | | -import os |
| 10 | +env_file = str(ROOT_DIR.joinpath(".env")) |
| 11 | +if Path(env_file).exists(): |
| 12 | + environ.Env.read_env(env_file) |
14 | 13 |
|
| 14 | +env = environ.Env(TRAVIS=(bool, False)) |
15 | 15 |
|
16 | | -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) |
17 | | -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 16 | +SECRET_KEY = env.str("SECRET_KEY") |
18 | 17 |
|
19 | | -# Quick-start development settings - unsuitable for production |
20 | | -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ |
21 | | - |
22 | | -# SECURITY WARNING: keep the secret key used in production secret! |
23 | | -DEBUG = False |
24 | | -SECRET_KEY = os.environ.get( |
25 | | - "SECRET_KEY", default="this-is-a-dummy-key-and-its-overridden-for-prod-servers" |
26 | | -) |
27 | | - |
28 | | -# SECURITY WARNING: don't run with debug turned on in production! |
29 | | - |
30 | | -DEBUG_PROPAGATE_EXCEPTIONS = True |
31 | | - |
32 | | -ALLOWED_HOSTS = os.environ.get("VC_ALLOWED_HOSTS", "*").split(":") |
| 18 | +ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]"]) |
33 | 19 |
|
34 | 20 | # Application definition |
35 | 21 |
|
|
62 | 48 | TEMPLATES = [ |
63 | 49 | { |
64 | 50 | "BACKEND": "django.template.backends.django.DjangoTemplates", |
65 | | - "DIRS": [os.path.join(BASE_DIR, "templates")], |
| 51 | + "DIRS": [str(PROJECT_DIR.joinpath("templates"))], |
66 | 52 | "APP_DIRS": True, |
67 | 53 | "OPTIONS": { |
68 | 54 | "debug": False, |
|
81 | 67 |
|
82 | 68 |
|
83 | 69 | # Database |
84 | | -# https://docs.djangoproject.com/en/1.11/ref/settings/#databases |
85 | 70 |
|
86 | 71 | DATABASES = { |
87 | 72 | "default": { |
88 | | - "ENGINE": "django.db.backends.postgresql", |
89 | | - "NAME": os.environ.get("VC_DB_NAME", "vulnerablecode"), |
90 | | - "USER": os.environ.get("VC_DB_USER", "vulnerablecode"), |
91 | | - "PASSWORD": os.environ.get("VC_DB_PASSWORD", "vulnerablecode"), |
92 | | - "HOST": os.environ.get("VC_DB_HOST", "localhost"), |
93 | | - "PORT": os.environ.get("VC_DB_PORT", "5432"), |
| 73 | + "ENGINE": env.str("VULNERABLECODE_DB_ENGINE", "django.db.backends.postgresql"), |
| 74 | + "NAME": env.str("VULNERABLECODE_DB_NAME", "vulnerablecode"), |
| 75 | + "USER": env.str("VULNERABLECODE_DB_USER", "vulnerablecode"), |
| 76 | + "PASSWORD": env.str("VULNERABLECODE_DB_PASSWORD", "vulnerablecode"), |
| 77 | + "HOST": env.str("VULNERABLECODE_DB_HOST", "localhost"), |
| 78 | + "PORT": env.str("VULNERABLECODE_DB_PORT", "5432"), |
94 | 79 | } |
95 | 80 | } |
96 | 81 |
|
97 | | -if "TRAVIS" in os.environ: |
| 82 | +if env("TRAVIS"): |
98 | 83 | DATABASES["default"]["USER"] = "postgres" |
99 | 84 | DATABASES["default"]["PASSWORD"] = "" |
100 | 85 |
|
|
122 | 107 |
|
123 | 108 |
|
124 | 109 | # Internationalization |
125 | | -# https://docs.djangoproject.com/en/1.11/topics/i18n/ |
126 | 110 |
|
127 | 111 | LANGUAGE_CODE = "en-us" |
128 | 112 |
|
|
136 | 120 |
|
137 | 121 |
|
138 | 122 | # Static files (CSS, JavaScript, Images) |
139 | | -# https://docs.djangoproject.com/en/1.11/howto/static-files/ |
140 | 123 |
|
141 | | -STATIC_ROOT = os.path.join(BASE_DIR, "static") |
142 | 124 | STATIC_URL = "/static/" |
143 | 125 |
|
| 126 | +STATIC_ROOT = "/var/vulnerablecode/static" |
| 127 | + |
| 128 | +STATICFILES_DIRS = [ |
| 129 | + str(PROJECT_DIR.joinpath("static")), |
| 130 | +] |
| 131 | + |
144 | 132 | # REST API |
145 | 133 | REST_FRAMEWORK = { |
146 | 134 | "DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",), |
|
0 commit comments