|
9 | 9 |
|
10 | 10 | # --- SECURITY SETTINGS --- # |
11 | 11 | # Load the server config file. |
12 | | -server_config = configparser.ConfigParser() |
13 | | -server_config.read(BASE_DIR + "/server.conf") |
14 | | - |
15 | | -# Quick-start development settings - unsuitable for production |
16 | | -# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ |
17 | | - |
18 | | -# Is this a production server? |
19 | | -PRODUCTION = server_config["PRODUCTION"]["production"] |
| 12 | +secrets = configparser.ConfigParser() |
| 13 | +secrets.read(BASE_DIR + "/.secrets") |
| 14 | +PRODUCTION = secrets["SERVER"]["PRODUCTION"] |
| 15 | +DEBUG = PRODUCTION |
20 | 16 |
|
21 | 17 | # Set the anonymous user's key. |
22 | | -ANON_KEY = server_config["KEYS"]["anon"] |
| 18 | +ANON_KEY = secrets["DJANGO_KEYS"]["ANON_KEY"] |
23 | 19 |
|
24 | 20 | # SECURITY WARNING: keep the secret key used in production secret! |
25 | | -SECRET_KEY = "$vz@#@^q(od&$rf&*6^z!m5nh6qw2*cq*j6fha#^h9(r7$xqy4" |
| 21 | +SECRET_KEY = secrets["DJANGO_KEYS"]["SECRET_KEY"] |
26 | 22 |
|
27 | 23 | # SECURITY WARNING: don't run with debug turned on in production! |
28 | | -DEBUG = PRODUCTION |
29 | 24 |
|
| 25 | +# The publicly accessible hostname. |
| 26 | +HOSTNAME = secrets["SERVER"]["HOSTNAME"] |
30 | 27 | # The human-readable hostname. |
31 | | -HUMAN_READABLE_HOSTNAME = server_config["HRHOSTNAME"]["hrnames"] |
32 | | - |
33 | | -if server_config["GROUP_PREFIX"]["allow_all_creation"] == "True": |
34 | | - GROUP = True |
35 | | - PREFIX = True |
36 | | -elif server_config["GROUP_PREFIX"]["allow_group_creation"] == "True": |
37 | | - GROUP = True |
38 | | -elif server_config["GROUP_PREFIX"]["allow_prefix_creation"] == "True": |
39 | | - PREFIX = True |
40 | | - |
| 28 | +HUMAN_READABLE_HOSTNAME = secrets["SERVER"]["HUMAN_READABLE_HOSTNAME"] |
41 | 29 | # The publicly accessible hostname. |
42 | | -if server_config["PRODUCTION"]["production"] == "True": |
43 | | - PUBLIC_HOSTNAME = server_config["PUBLICHOSTNAME"]["prod_name"] |
44 | | -elif server_config["PRODUCTION"]["production"] == "False": |
45 | | - PUBLIC_HOSTNAME = server_config["PUBLICHOSTNAME"]["name"] |
| 30 | +PUBLIC_HOSTNAME = secrets["SERVER"]["PUBLIC_HOSTNAME"] |
| 31 | +# import pdb; pdb.set_trace() |
46 | 32 |
|
47 | | -# Source: https://dzone.com/articles/how-to-fix-django-cors-error |
48 | 33 |
|
49 | | -# Check for open (public) access to the API. |
50 | | -if server_config["REQUESTS_FROM"]["public"].strip() == "false": |
51 | | - |
52 | | - # Process the requester groups. |
53 | | - |
54 | | - # configparser automatically strips white space off the |
55 | | - # ends of arguments. |
56 | | - requesters = [ |
57 | | - server_config["REQUESTS_FROM"][i].strip() |
58 | | - for i in server_config["REQUESTS_FROM"] |
59 | | - ] |
60 | | - requesters.remove("false") |
61 | | - requesters = [i.split(",") for i in requesters] |
62 | | - |
63 | | - # Flatten the list. |
64 | | - # Source: https://stackabuse.com/python-how-to-flatten-list-of-lists/ |
65 | | - flattened = [item.strip() for sublist in requesters for item in sublist] |
66 | | - |
67 | | - if server_config["PRODUCTION"]["production"] == "True": |
68 | | - ALLOWED_HOSTS = [ |
69 | | - i.strip() for i in server_config["HOSTNAMES"]["prod_names"].split(",") |
70 | | - ] |
71 | | - elif server_config["PRODUCTION"]["production"] == "False": |
72 | | - ALLOWED_HOSTS = [ |
73 | | - i.strip() for i in server_config["HOSTNAMES"]["names"].split(",") |
74 | | - ] |
75 | | - |
76 | | - CORS_ORIGIN_ALLOW_ALL = False |
77 | | - CORS_ORIGIN_WHITELIST = tuple(flattened) |
78 | | - |
79 | | -elif server_config["REQUESTS_FROM"]["public"].strip() == "true": |
80 | | - if server_config["PRODUCTION"]["production"] == "True": |
81 | | - ALLOWED_HOSTS = [server_config["HOSTNAMES"]["prod_names"].split(",")[0], "*"] |
82 | | - CORS_ORIGIN_ALLOW_ALL = True |
83 | | - elif server_config["PRODUCTION"]["production"] == "False": |
84 | | - ALLOWED_HOSTS = [server_config["HOSTNAMES"]["names"].split(",")[0], "*"] |
85 | | - CORS_ORIGIN_ALLOW_ALL = True |
| 34 | +CORS_ORIGIN_ALLOW_ALL = True |
| 35 | +CORS_ORIGIN_WHITELIST = ["*"] |
86 | 36 |
|
87 | 37 | # Use the REST framework |
88 | 38 | REST_FRAMEWORK = { |
|
94 | 44 | ], |
95 | 45 | "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"], |
96 | 46 | "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema", |
97 | | - |
98 | | - |
99 | 47 | } |
100 | 48 |
|
101 | 49 | JWT_AUTH = { |
|
197 | 145 | DATABASES = { |
198 | 146 | "default": { |
199 | 147 | "ENGINE": "django.db.backends.sqlite3", |
200 | | - "NAME": server_config["DATABASES"]["path"], |
| 148 | + "NAME": secrets["SERVER"]["DATABASE"], |
201 | 149 | } |
202 | 150 | } |
203 | 151 |
|
|
219 | 167 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ |
220 | 168 |
|
221 | 169 | STATIC_URL = "/api/static/" |
222 | | -# STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] |
223 | | -STATIC_ROOT = "/var/www/bcoeditor/bco_api/bco_api/static/" |
| 170 | +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] |
| 171 | +# STATIC_ROOT = "/var/www/bcoeditor/bco_api/bco_api/static/" |
224 | 172 |
|
225 | 173 | # ----- CUSTOM VARIABLES AND METHODS ----- # |
226 | 174 | # Load request and validation templates (definitions). |
|
229 | 177 | # First, the request definitions. |
230 | 178 |
|
231 | 179 | # Make the object naming accessible as a dictionary. |
232 | | -OBJECT_NAMING = {} |
233 | | - |
234 | | -if server_config["PRODUCTION"]["production"] == "True": |
235 | | - |
236 | | - for i in server_config["OBJECT_NAMING"]: |
237 | | - if i.split("_")[0] == "prod": |
238 | | - |
239 | | - # Strip out the production flag. |
240 | | - STRIPPED = "_".join(i.split("_")[1:]) |
241 | | - |
242 | | - OBJECT_NAMING[STRIPPED] = server_config["OBJECT_NAMING"][i] |
243 | | - |
244 | | -elif server_config["PRODUCTION"]["production"] == "False": |
245 | | - |
246 | | - for i in server_config["OBJECT_NAMING"]: |
247 | | - if i.split("_")[0] != "prod": |
248 | | - OBJECT_NAMING[i] = server_config["OBJECT_NAMING"][i] |
249 | 180 |
|
250 | 181 | # emailing notifications |
251 | | -EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" |
| 182 | +EMAIL_BACKEND = secrets["SERVER"]["EMAIL_BACKEND"] |
252 | 183 | EMAIL_HOST = "localhost" |
253 | 184 | EMAIL_PORT = 25 |
254 | 185 | DEFAULT_AUTO_FIELD = "django.db.models.AutoField" |
0 commit comments