-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbase.py
374 lines (321 loc) · 13.1 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import os
import dj_database_url
from django.utils.crypto import get_random_string
from .env import env
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
REPO_DIR = os.path.dirname(BASE_DIR)
CANONICAL_BASE = env.get_credential('CANONICAL_BASE', 'https://www.fec.gov')
WAGTAILADMIN_BASE_URL = CANONICAL_BASE
USAJOBS_WHOMAYAPPLY = env.get_credential('USAJOBS_WHOMAYAPPLY')
USAJOBS_AGENCY_CODE = env.get_credential('USAJOBS_AGENCY_CODE')
USAJOBS_API_KEY = env.get_credential('USAJOBS_API_KEY')
GOVDELIVERY_TOKEN = env.get_credential('GOVDELIVERY_TOKEN')
FEC_APP_URL = env.get_credential('FEC_APP_URL')
FEC_API_URL = env.get_credential('FEC_API_URL', 'http://localhost:5000')
FEC_API_KEY_PRIVATE = env.get_credential('FEC_WEB_API_KEY_PRIVATE')
FEC_API_VERSION = env.get_credential('FEC_API_VERSION', 'v1')
FEC_API_KEY_PUBLIC = env.get_credential('FEC_WEB_API_KEY_PUBLIC', '')
FEC_INTERNAL_API_KEY_PUBLIC = env.get_credential('FEC_INTERNAL_API_KEY_PUBLIC', '')
FEC_INTERNAL_IP = env.get_credential('FEC_INTERNAL_IP', '')
FEC_API_KEY_PUBLIC_CALENDAR = env.get_credential('FEC_WEB_API_KEY_PUBLIC_CALENDAR', FEC_API_KEY_PUBLIC)
FEC_CAL_DOWNLOAD_API_KEY = env.get_credential('FEC_CAL_DOWNLOAD_API_KEY')
FEC_DOWNLOAD_API_KEY = env.get_credential('FEC_DOWNLOAD_API_KEY', '')
FEC_RECAPTCHA_SECRET_KEY = env.get_credential('FEC_RECAPTCHA_SECRET_KEY')
FEC_GITHUB_TOKEN = env.get_credential('FEC_GITHUB_TOKEN')
# Config for the ServiceNow API for contacting RAD
FEC_SERVICE_NOW_API = env.get_credential('FEC_SERVICE_NOW_API')
FEC_SERVICE_NOW_USERNAME = env.get_credential('FEC_SERVICE_NOW_USERNAME')
FEC_SERVICE_NOW_PASSWORD = env.get_credential('FEC_SERVICE_NOW_PASSWORD')
# Search.gov API keys
SEARCHGOV_API_ACCESS_KEY = env.get_credential('SEARCHGOV_API_ACCESS_KEY')
SEARCHGOV_POLICY_GUIDANCE_KEY = env.get_credential('SEARCHGOV_POLICY_GUIDANCE_KEY')
WEBMANAGER_EMAIL = "[email protected]"
ENVIRONMENTS = {
'local': 'LOCAL',
'dev': 'DEVELOPMENT',
'stage': 'STAGING',
'prod': 'PRODUCTION',
'feature': 'FEATURE',
}
FEC_CMS_ENVIRONMENT = ENVIRONMENTS.get(env.get_credential('FEC_CMS_ENVIRONMENT'), ENVIRONMENTS['local'])
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'wagtail.search.backends.database',
'SEARCH_CONFIG': 'english',
}
}
FEATURES = {
'ierawfilters': bool(env.get_credential('FEC_FEATURE_IE_RAW_FILTERS', '')),
# Functionality
'website_status': bool(env.get_credential('FEC_FEATURE_WEBSITE_STATUS', '')),
# Feature flags (hiding or displaying components)
'adrs': bool(env.get_credential('FEC_FEATURE_ADRS', '')),
'afs': bool(env.get_credential('FEC_FEATURE_AFS', '')), # Admin fines search
'aggregatetotals': bool(env.get_credential('FEC_FEATURE_AGGR_TOTS', '')),
'barcharts': bool(env.get_credential('FEC_FEATURE_HOME_BARCHARTS', '')),
'contributionsbystate': bool(env.get_credential('FEC_FEATURE_CONTRIBUTIONS_BY_STATE', '')),
'debts': bool(env.get_credential('FEC_FEATURE_DEBTS', '')),
'h4_allocated_disbursements': bool(env.get_credential('FEC_FEATURE_H4_ALLOCATED_DISBURSEMENTS', True)),
'house_senate_overview': bool(env.get_credential('FEC_FEATURE_HOUSE_SENATE_OVERVIEW', '')),
'house_senate_overview_methodology': bool(env.get_credential('FEC_FEATURE_HOUSE_SENATE_OVERVIEW_METHODOLOGY', '')),
'house_senate_overview_summary': bool(env.get_credential('FEC_FEATURE_HOUSE_SENATE_OVERVIEW_SUMMARY', '')),
'house_senate_overview_totals': bool(env.get_credential('FEC_FEATURE_HOUSE_SENATE_OVERVIEW_TOTALS', '')),
'map': bool(env.get_credential('FEC_FEATURE_HOME_MAP', '')),
'nat_party_acct_receipts': bool(env.get_credential('FEC_FEATURE_NAT_PARTY_ACCT_RECEIPTS', '')),
'nat_party_acct_disbursements': bool(env.get_credential('FEC_FEATURE_NAT_PARTY_ACCT_DISBURSEMENTS', '')),
'nat_party_acct_rec_single': bool(env.get_credential('FEC_FEATURE_NAT_PARTY_ACCT_REC_SINGLE', '')),
'nat_party_acct_dis_single': bool(env.get_credential('FEC_FEATURE_NAT_PARTY_ACCT_DIS_SINGLE', '')),
'pac_party': bool(env.get_credential('FEC_FEATURE_PAC_PARTY', '')),
'pac_snapshot': bool(env.get_credential('FEC_FEATURE_PAC_SNAPSHOT', '')),
'presidential_map': bool(env.get_credential('FEC_FEATURE_PRESIDENTIAL_MAP', '')),
}
# Set feature flags to True for Feature
if FEC_CMS_ENVIRONMENT == ENVIRONMENTS['feature']:
FEATURES['house_senate_overview'] = True
FEATURES['house_senate_overview_methodology'] = True
FEATURES['house_senate_overview_summary'] = True
FEATURES['house_senate_overview_totals'] = True
# Set feature flags to True for local
if FEC_CMS_ENVIRONMENT == ENVIRONMENTS['local']:
FEATURES['adrs'] = True
FEATURES['afs'] = True
FEATURES['aggregatetotals'] = True
FEATURES['barcharts'] = True
FEATURES['contributionsbystate'] = True
FEATURES['debts'] = True
FEATURES['map'] = True
FEATURES['pac_party'] = True
FEATURES['pac_snapshot'] = True
FEATURES['presidential_map'] = True
FEATURES['h4_allocated_disbursements'] = True
FEATURES['house_senate_overview'] = True
FEATURES['house_senate_overview_methodology'] = True
FEATURES['house_senate_overview_summary'] = True
FEATURES['house_senate_overview_totals'] = True
FEATURES['nat_party_acct_receipts'] = True
FEATURES['nat_party_acct_disbursements'] = True
FEATURES['nat_party_acct_rec_single'] = True
FEATURES['nat_party_acct_dis_single'] = True
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'django_jinja',
'taggit',
'compressor',
'modelcluster',
'storages',
'wagtail',
'wagtail.admin',
'wagtail.search',
'wagtail.images',
'wagtail.documents',
'wagtail.snippets',
'wagtail.users',
'wagtail.sites',
'wagtail.embeds',
'wagtail.contrib.redirects',
'wagtail.contrib.forms',
'wagtail.locales',
'wagtail.contrib.search_promotions',
'wagtail.contrib.table_block',
'wagtail.contrib.styleguide',
'fec',
'search',
'home',
'data',
'legal',
'uaa_client',
'extend_admin',
)
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# custom response headers
'fec.middleware.AddSecureHeaders',
'uaa_client.middleware.UaaRefreshMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# 'wagtail.contrib.legacy.sitemiddleware.SiteMiddleware',
# :up: SiteMiddleware :up: was removed for Wagtail 2.11. Safe to lose it altogether?
)
SECURE_REFERRER_POLICY = 'strict-origin-when-cross-origin'
CSRF_TRUSTED_ORIGINS = ["https://*.fec.gov", "https://*.app.cloud.gov"]
if FEC_CMS_ENVIRONMENT == ENVIRONMENTS['local']:
CSRF_TRUSTED_ORIGINS.extend(["http://127.0.0.1:5000"])
ROOT_URLCONF = 'fec.urls'
from data import constants # noqa: E402
TEMPLATES = [
{
'BACKEND': 'django_jinja.backend.Jinja2',
'APP_DIRS': True,
'OPTIONS': {
'environment': 'data.jinja2.environment',
'match_extension': '.jinja',
'constants': {
'constants': constants,
'CANONICAL_BASE': CANONICAL_BASE,
'FEC_API_KEY_PRIVATE': FEC_API_KEY_PRIVATE,
'FEC_DOWNLOAD_API_KEY': FEC_DOWNLOAD_API_KEY,
'FEC_API_URL': FEC_API_URL,
'WEBMANAGER_EMAIL': WEBMANAGER_EMAIL,
'FEC_CMS_ENVIRONMENT': FEC_CMS_ENVIRONMENT,
'FEATURES': FEATURES,
},
'context_processors': [
'django.template.context_processors.request',
'fec.context.api_key',
]
}
},
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'fec.context.show_settings',
'fec.context.features',
'fec.context.api_key',
],
},
},
]
WSGI_APPLICATION = 'fec.wsgi.application'
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', get_random_string(50))
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
# Be sure to set the DATABASE_URL environment variable on your local
# development machine so that the local database can be connected to.
'default': dj_database_url.config()
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGES = (
('en', 'English'),
)
TIME_ZONE = 'America/New_York'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'dist', 'fec', 'static'),
os.path.join(PROJECT_DIR, 'static'),
# We will need just the assets of certain npm modules for Wagtail
# So we are including a folder of symlinks to modules for access
os.path.join(BASE_DIR, 'fec', 'wagtail_npm_dependencies'),
)
DIST_DIR = os.path.join(BASE_DIR, 'dist')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'fec.utils.PatchedSCSSCompiler'),
)
# Proxy settings
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Wagtail settings
WAGTAIL_SITE_NAME = "fec"
WAGTAILEMBEDS_RESPONSIVE_HTML = True
# Custom settings
from fec import constants # noqa: E402
CONSTANTS = constants
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 9,
}
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
if FEC_CMS_ENVIRONMENT != ENVIRONMENTS['local']:
AWS_QUERYSTRING_AUTH = False
AWS_ACCESS_KEY_ID = env.get_credential('access_key_id')
AWS_SECRET_ACCESS_KEY = env.get_credential('secret_access_key')
AWS_STORAGE_BUCKET_NAME = env.get_credential('bucket')
AWS_S3_REGION_NAME = env.get_credential('region')
AWS_S3_CUSTOM_DOMAIN = env.get_credential('CMS_AWS_CUSTOM_DOMAIN')
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
AWS_LOCATION = 'cms-content'
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3.S3Storage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}
UAA_CLIENT_ID = env.get_credential('CMS_LOGIN_CLIENT_ID', 'my-client-id')
UAA_CLIENT_SECRET = env.get_credential('CMS_LOGIN_CLIENT_SECRET', 'my-client-secret')
# fake uaa server deploys locally on port 8080. Will be needed to login for local use
# TODO: These will have to have an explicit reference until we can figure out how
# to silence Django warnings about the url being http (it expects https).
# UAA_AUTH_URL = env.get_credential('CMS_LOGIN_AUTH_URL', 'http://localhost:8080/oauth/authorize')
# UAA_TOKEN_URL = env.get_credential('CMS_LOGIN_TOKEN_URL','http://localhost:8080/oauth/token')
UAA_AUTH_URL = 'https://login.fr.cloud.gov/oauth/authorize'
UAA_TOKEN_URL = 'https://login.fr.cloud.gov/oauth/token'
WAGTAIL_FRONTEND_LOGIN_URL = 'uaa_client:login'
AUTHENTICATION_BACKENDS = \
['django.contrib.auth.backends.ModelBackend',
'uaa_client.authentication.UaaBackend']
DEFAULT_AUTHENTICATION_CLASSES = ['rest_framework_jwt.authentication.JSONWebTokenAuthentication']
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {
'format': '%(levelname)s:%(name)s: %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'INFO',
'formatter': 'console',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'INFO',
'propogate': False,
},
},
}
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'