|
1 | 1 | import os
|
2 |
| -from urllib.parse import urlparse |
3 | 2 |
|
4 |
| -import django_prometheus |
5 | 3 | import sentry_sdk
|
6 | 4 | from corsheaders.defaults import default_headers
|
7 | 5 | from sentry_sdk.integrations.celery import CeleryIntegration
|
8 | 6 | from sentry_sdk.integrations.django import DjangoIntegration
|
9 | 7 | from sentry_sdk.integrations.httpx import HttpxIntegration
|
10 | 8 | from sentry_sdk.integrations.redis import RedisIntegration
|
11 | 9 | from sentry_sdk.scrubber import DEFAULT_DENYLIST, EventScrubber
|
| 10 | +from shared.django_apps.db_settings import * |
12 | 11 |
|
13 | 12 | from utils.config import SettingsModule, get_config, get_settings_module
|
14 | 13 |
|
15 | 14 | SECRET_KEY = get_config("django", "secret_key", default="*")
|
16 | 15 |
|
17 |
| -AUTH_USER_MODEL = "codecov_auth.User" |
18 |
| - |
19 | 16 | # Application definition
|
20 | 17 |
|
21 | 18 | INSTALLED_APPS = [
|
|
97 | 94 | # Database
|
98 | 95 | # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
99 | 96 |
|
100 |
| -db_url = get_config("services", "database_url") |
101 |
| -if db_url: |
102 |
| - db_conf = urlparse(db_url) |
103 |
| - DATABASE_USER = db_conf.username |
104 |
| - DATABASE_NAME = db_conf.path.replace("/", "") |
105 |
| - DATABASE_PASSWORD = db_conf.password |
106 |
| - DATABASE_HOST = db_conf.hostname |
107 |
| - DATABASE_PORT = db_conf.port |
108 |
| -else: |
109 |
| - DATABASE_USER = get_config("services", "database", "username", default="postgres") |
110 |
| - DATABASE_NAME = get_config("services", "database", "name", default="postgres") |
111 |
| - DATABASE_PASSWORD = get_config( |
112 |
| - "services", "database", "password", default="postgres" |
113 |
| - ) |
114 |
| - DATABASE_HOST = get_config("services", "database", "host", default="postgres") |
115 |
| - DATABASE_PORT = get_config("services", "database", "port", default=5432) |
116 |
| - |
117 |
| -DATABASE_READ_REPLICA_ENABLED = get_config( |
118 |
| - "setup", "database", "read_replica_enabled", default=False |
119 |
| -) |
120 |
| - |
121 |
| -db_read_url = get_config("services", "database_read_url") |
122 |
| -if db_read_url: |
123 |
| - db_conf = urlparse(db_read_url) |
124 |
| - DATABASE_READ_USER = db_conf.username |
125 |
| - DATABASE_READ_NAME = db_conf.path.replace("/", "") |
126 |
| - DATABASE_READ_PASSWORD = db_conf.password |
127 |
| - DATABASE_READ_HOST = db_conf.hostname |
128 |
| - DATABASE_READ_PORT = db_conf.port |
129 |
| -else: |
130 |
| - DATABASE_READ_USER = get_config( |
131 |
| - "services", "database_read", "username", default="postgres" |
132 |
| - ) |
133 |
| - DATABASE_READ_NAME = get_config( |
134 |
| - "services", "database_read", "name", default="postgres" |
135 |
| - ) |
136 |
| - DATABASE_READ_PASSWORD = get_config( |
137 |
| - "services", "database_read", "password", default="postgres" |
138 |
| - ) |
139 |
| - DATABASE_READ_HOST = get_config( |
140 |
| - "services", "database_read", "host", default="postgres" |
141 |
| - ) |
142 |
| - DATABASE_READ_PORT = get_config("services", "database_read", "port", default=5432) |
143 |
| - |
144 | 97 | GRAPHQL_QUERY_COST_THRESHOLD = get_config(
|
145 | 98 | "setup", "graphql", "query_cost_threshold", default=10000
|
146 | 99 | )
|
147 | 100 |
|
148 |
| -TIMESERIES_ENABLED = get_config("setup", "timeseries", "enabled", default=False) |
149 |
| -TIMESERIES_REAL_TIME_AGGREGATES = get_config( |
150 |
| - "setup", "timeseries", "real_time_aggregates", default=False |
151 |
| -) |
152 |
| - |
153 |
| -timeseries_database_url = get_config("services", "timeseries_database_url") |
154 |
| -if timeseries_database_url: |
155 |
| - timeseries_database_conf = urlparse(timeseries_database_url) |
156 |
| - TIMESERIES_DATABASE_USER = timeseries_database_conf.username |
157 |
| - TIMESERIES_DATABASE_NAME = timeseries_database_conf.path.replace("/", "") |
158 |
| - TIMESERIES_DATABASE_PASSWORD = timeseries_database_conf.password |
159 |
| - TIMESERIES_DATABASE_HOST = timeseries_database_conf.hostname |
160 |
| - TIMESERIES_DATABASE_PORT = timeseries_database_conf.port |
161 |
| -else: |
162 |
| - TIMESERIES_DATABASE_USER = get_config( |
163 |
| - "services", "timeseries_database", "username", default="postgres" |
164 |
| - ) |
165 |
| - TIMESERIES_DATABASE_NAME = get_config( |
166 |
| - "services", "timeseries_database", "name", default="postgres" |
167 |
| - ) |
168 |
| - TIMESERIES_DATABASE_PASSWORD = get_config( |
169 |
| - "services", "timeseries_database", "password", default="postgres" |
170 |
| - ) |
171 |
| - TIMESERIES_DATABASE_HOST = get_config( |
172 |
| - "services", "timeseries_database", "host", default="timescale" |
173 |
| - ) |
174 |
| - TIMESERIES_DATABASE_PORT = get_config( |
175 |
| - "services", "timeseries_database", "port", default=5432 |
176 |
| - ) |
177 |
| - |
178 |
| -TIMESERIES_DATABASE_READ_REPLICA_ENABLED = get_config( |
179 |
| - "setup", "timeseries", "read_replica_enabled", default=False |
180 |
| -) |
181 |
| - |
182 |
| -timeseries_database_read_url = get_config("services", "timeseries_database_read_url") |
183 |
| -if timeseries_database_read_url: |
184 |
| - timeseries_database_conf = urlparse(timeseries_database_read_url) |
185 |
| - TIMESERIES_DATABASE_READ_USER = timeseries_database_conf.username |
186 |
| - TIMESERIES_DATABASE_READ_NAME = timeseries_database_conf.path.replace("/", "") |
187 |
| - TIMESERIES_DATABASE_READ_PASSWORD = timeseries_database_conf.password |
188 |
| - TIMESERIES_DATABASE_READ_HOST = timeseries_database_conf.hostname |
189 |
| - TIMESERIES_DATABASE_READ_PORT = timeseries_database_conf.port |
190 |
| -else: |
191 |
| - TIMESERIES_DATABASE_READ_USER = get_config( |
192 |
| - "services", "timeseries_database_read", "username", default="postgres" |
193 |
| - ) |
194 |
| - TIMESERIES_DATABASE_READ_NAME = get_config( |
195 |
| - "services", "timeseries_database_read", "name", default="postgres" |
196 |
| - ) |
197 |
| - TIMESERIES_DATABASE_READ_PASSWORD = get_config( |
198 |
| - "services", "timeseries_database_read", "password", default="postgres" |
199 |
| - ) |
200 |
| - TIMESERIES_DATABASE_READ_HOST = get_config( |
201 |
| - "services", "timeseries_database_read", "host", default="timescale" |
202 |
| - ) |
203 |
| - TIMESERIES_DATABASE_READ_PORT = get_config( |
204 |
| - "services", "timeseries_database_read", "port", default=5432 |
205 |
| - ) |
206 |
| - |
207 |
| -# this is the time in seconds django decides to keep the connection open after the request |
208 |
| -# the default is 0 seconds, meaning django closes the connection after every request |
209 |
| -# https://docs.djangoproject.com/en/3.1/ref/settings/#conn-max-age |
210 |
| -CONN_MAX_AGE = int(get_config("services", "database", "conn_max_age", default=0)) |
211 |
| - |
212 |
| -DATABASES = { |
213 |
| - "default": { |
214 |
| - "ENGINE": "psqlextra.backend", |
215 |
| - "NAME": DATABASE_NAME, |
216 |
| - "USER": DATABASE_USER, |
217 |
| - "PASSWORD": DATABASE_PASSWORD, |
218 |
| - "HOST": DATABASE_HOST, |
219 |
| - "PORT": DATABASE_PORT, |
220 |
| - "CONN_MAX_AGE": CONN_MAX_AGE, |
221 |
| - } |
222 |
| -} |
223 |
| - |
224 |
| -if DATABASE_READ_REPLICA_ENABLED: |
225 |
| - DATABASES["default_read"] = { |
226 |
| - "ENGINE": "psqlextra.backend", |
227 |
| - "NAME": DATABASE_READ_NAME, |
228 |
| - "USER": DATABASE_READ_USER, |
229 |
| - "PASSWORD": DATABASE_READ_PASSWORD, |
230 |
| - "HOST": DATABASE_READ_HOST, |
231 |
| - "PORT": DATABASE_READ_PORT, |
232 |
| - "CONN_MAX_AGE": CONN_MAX_AGE, |
233 |
| - } |
234 |
| - |
235 |
| -if TIMESERIES_ENABLED: |
236 |
| - DATABASES["timeseries"] = { |
237 |
| - "ENGINE": "django_prometheus.db.backends.postgresql", |
238 |
| - "NAME": TIMESERIES_DATABASE_NAME, |
239 |
| - "USER": TIMESERIES_DATABASE_USER, |
240 |
| - "PASSWORD": TIMESERIES_DATABASE_PASSWORD, |
241 |
| - "HOST": TIMESERIES_DATABASE_HOST, |
242 |
| - "PORT": TIMESERIES_DATABASE_PORT, |
243 |
| - "CONN_MAX_AGE": CONN_MAX_AGE, |
244 |
| - } |
245 |
| - |
246 |
| - if TIMESERIES_DATABASE_READ_REPLICA_ENABLED: |
247 |
| - DATABASES["timeseries_read"] = { |
248 |
| - "ENGINE": "django_prometheus.db.backends.postgresql", |
249 |
| - "NAME": TIMESERIES_DATABASE_READ_NAME, |
250 |
| - "USER": TIMESERIES_DATABASE_READ_USER, |
251 |
| - "PASSWORD": TIMESERIES_DATABASE_READ_PASSWORD, |
252 |
| - "HOST": TIMESERIES_DATABASE_READ_HOST, |
253 |
| - "PORT": TIMESERIES_DATABASE_READ_PORT, |
254 |
| - "CONN_MAX_AGE": CONN_MAX_AGE, |
255 |
| - } |
256 |
| - |
257 |
| -# See https://django-postgres-extra.readthedocs.io/en/master/settings.html |
258 |
| -POSTGRES_EXTRA_DB_BACKEND_BASE: "django_prometheus.db.backends.postgresql" # type: ignore |
259 |
| - |
260 |
| -# Allows to use the pgpartition command |
261 |
| -PSQLEXTRA_PARTITIONING_MANAGER = ( |
262 |
| - "shared.django_apps.user_measurements.partitioning.manager" |
263 |
| -) |
264 |
| - |
265 | 101 | DATABASE_ROUTERS = ["codecov.db.DatabaseRouter"]
|
266 | 102 |
|
267 | 103 | # Password validation
|
|
502 | 338 | CORS_ALLOWED_ORIGIN_REGEXES = get_config(
|
503 | 339 | "setup", "api_cors_allowed_origin_regexes", default=[]
|
504 | 340 | )
|
505 |
| -CORS_ALLOWED_ORIGINS = [] |
| 341 | +CORS_ALLOWED_ORIGINS: list[str] = [] |
506 | 342 |
|
507 | 343 | GRAPHQL_PLAYGROUND = True
|
508 | 344 |
|
|
0 commit comments