-
Notifications
You must be signed in to change notification settings - Fork 88
/
settings.py
427 lines (339 loc) · 13.4 KB
/
settings.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/aboutcode-org/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
import sys
import tempfile
from pathlib import Path
import environ
PROJECT_DIR = environ.Path(__file__) - 1
ROOT_DIR = PROJECT_DIR - 1
# Environment
ENV_FILE = "/etc/scancodeio/.env"
if not Path(ENV_FILE).exists():
ENV_FILE = ROOT_DIR(".env")
env = environ.Env()
environ.Env.read_env(ENV_FILE)
# Security
SECRET_KEY = env.str("SECRET_KEY")
ALLOWED_HOSTS = env.list(
"ALLOWED_HOSTS",
default=[".localhost", "127.0.0.1", "[::1]", "host.docker.internal", "172.17.0.1"],
)
CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[])
# SECURITY WARNING: don't run with debug turned on in production
DEBUG = env.bool("SCANCODEIO_DEBUG", default=False)
SCANCODEIO_REQUIRE_AUTHENTICATION = env.bool(
"SCANCODEIO_REQUIRE_AUTHENTICATION", default=False
)
SCANCODEIO_ENABLE_ADMIN_SITE = env.bool("SCANCODEIO_ENABLE_ADMIN_SITE", default=False)
SECURE_CONTENT_TYPE_NOSNIFF = env.bool("SECURE_CONTENT_TYPE_NOSNIFF", default=True)
X_FRAME_OPTIONS = env.str("X_FRAME_OPTIONS", default="DENY")
SESSION_COOKIE_SECURE = env.bool("SESSION_COOKIE_SECURE", default=True)
CSRF_COOKIE_SECURE = env.bool("CSRF_COOKIE_SECURE", default=True)
# ``security.W004`` SECURE_HSTS_SECONDS and ``security.W008`` SECURE_SSL_REDIRECT
# are handled by the web server.
SILENCED_SYSTEM_CHECKS = ["security.W004", "security.W008"]
# ScanCode.io
SCANCODEIO_WORKSPACE_LOCATION = env.str("SCANCODEIO_WORKSPACE_LOCATION", default="var")
SCANCODEIO_CONFIG_DIR = env.str("SCANCODEIO_CONFIG_DIR", default=".scancode")
SCANCODEIO_CONFIG_FILE = env.str(
"SCANCODEIO_CONFIG_FILE", default="scancode-config.yml"
)
SCANCODEIO_LOG_LEVEL = env.str("SCANCODEIO_LOG_LEVEL", "INFO")
# Set the number of parallel processes to use for ScanCode related scan execution.
# If the SCANCODEIO_PROCESSES argument is not set, defaults to an optimal number of CPUs
# available on the machine.
SCANCODEIO_PROCESSES = env.int("SCANCODEIO_PROCESSES", default=None)
SCANCODEIO_POLICIES_FILE = env.str("SCANCODEIO_POLICIES_FILE", default="policies.yml")
# This setting defines the additional locations ScanCode.io will search for pipelines.
# This should be set to a list of strings that contain full paths to your additional
# pipelines directories.
SCANCODEIO_PIPELINES_DIRS = env.list("SCANCODEIO_PIPELINES_DIRS", default=[])
# Maximum time allowed for a pipeline to complete.
SCANCODEIO_TASK_TIMEOUT = env.str("SCANCODEIO_TASK_TIMEOUT", default="24h")
# Default to 2 minutes.
SCANCODEIO_SCAN_FILE_TIMEOUT = env.int("SCANCODEIO_SCAN_FILE_TIMEOUT", default=120)
# List views pagination, controls the number of items displayed per page.
# Syntax in .env: SCANCODEIO_PAGINATE_BY=project=10,project_error=10
SCANCODEIO_PAGINATE_BY = env.dict(
"SCANCODEIO_PAGINATE_BY",
default={
"project": 20,
"error": 50,
"resource": 100,
"package": 100,
"dependency": 100,
"relation": 100,
},
)
# Default limit for "most common" entries in QuerySets.
SCANCODEIO_MOST_COMMON_LIMIT = env.int("SCANCODEIO_MOST_COMMON_LIMIT", default=7)
# Fetch authentication credentials
# SCANCODEIO_FETCH_BASIC_AUTH="host=user,password;"
SCANCODEIO_FETCH_BASIC_AUTH = env.dict(
"SCANCODEIO_FETCH_BASIC_AUTH",
cast={"value": tuple},
default={},
)
# SCANCODEIO_FETCH_DIGEST_AUTH="host=user,password;"
SCANCODEIO_FETCH_DIGEST_AUTH = env.dict(
"SCANCODEIO_FETCH_DIGEST_AUTH",
cast={"value": tuple},
default={},
)
# SCANCODEIO_FETCH_HEADERS="host=Header1=value,Header2=value;"
SCANCODEIO_FETCH_HEADERS = {}
FETCH_HEADERS_STR = env.str("SCANCODEIO_FETCH_HEADERS", default="")
for entry in FETCH_HEADERS_STR.split(";"):
if entry.strip():
host, headers = entry.split("=", 1)
SCANCODEIO_FETCH_HEADERS[host] = env.parse_value(headers, cast=dict)
# SCANCODEIO_NETRC_LOCATION="~/.netrc"
SCANCODEIO_NETRC_LOCATION = env.str("SCANCODEIO_NETRC_LOCATION", default="")
if SCANCODEIO_NETRC_LOCATION:
# Propagate the location to the environ for `requests.utils.get_netrc_auth`
env.ENVIRON["NETRC"] = SCANCODEIO_NETRC_LOCATION
# SCANCODEIO_SKOPEO_CREDENTIALS="host1=user:password,host2=user:password"
SCANCODEIO_SKOPEO_CREDENTIALS = env.dict("SCANCODEIO_SKOPEO_CREDENTIALS", default={})
# SCANCODEIO_SKOPEO_AUTHFILE_LOCATION="/path/to/auth.json"
SCANCODEIO_SKOPEO_AUTHFILE_LOCATION = env.str(
"SCANCODEIO_SKOPEO_AUTHFILE_LOCATION", default=""
)
# Application definition
INSTALLED_APPS = [
# Local apps
# Must come before Third-party apps for proper templates override
"scanpipe",
# Django built-in
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.admin",
"django.contrib.humanize",
# Third-party apps
"crispy_forms",
"crispy_bootstrap3", # required for the djangorestframework browsable API
"django_filters",
"rest_framework",
"rest_framework.authtoken",
"django_rq",
"django_probes",
"fontawesomefree",
"taggit",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "scancodeio.urls"
WSGI_APPLICATION = "scancodeio.wsgi.application"
SECURE_PROXY_SSL_HEADER = env.tuple(
"SECURE_PROXY_SSL_HEADER", default=("HTTP_X_FORWARDED_PROTO", "https")
)
# Database
DATABASES = {
"default": {
"ENGINE": env.str("SCANCODEIO_DB_ENGINE", "django.db.backends.postgresql"),
"HOST": env.str("SCANCODEIO_DB_HOST", "localhost"),
"NAME": env.str("SCANCODEIO_DB_NAME", "scancodeio"),
"USER": env.str("SCANCODEIO_DB_USER", "scancodeio"),
"PASSWORD": env.str("SCANCODEIO_DB_PASSWORD", "scancodeio"),
"PORT": env.str("SCANCODEIO_DB_PORT", "5432"),
"ATOMIC_REQUESTS": True,
}
}
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Forms and filters
FILTERS_EMPTY_CHOICE_LABEL = env.str("FILTERS_EMPTY_CHOICE_LABEL", default="All")
# Templates
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"debug": DEBUG,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
"scancodeio.context_processors.versions",
],
},
},
]
# Login
LOGIN_REDIRECT_URL = "project_list"
# Passwords
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": (
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
),
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {
"min_length": env.int("SCANCODEIO_PASSWORD_MIN_LENGTH", default=12),
},
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# Testing
# True if running tests through `./manage test`
IS_TESTS = "test" in sys.argv
if IS_TESTS:
# Do not pollute the workspace while running the tests.
SCANCODEIO_WORKSPACE_LOCATION = tempfile.mkdtemp()
SCANCODEIO_REQUIRE_AUTHENTICATION = True
SCANCODEIO_SCAN_FILE_TIMEOUT = 120
# The default password hasher is rather slow by design.
# Using a faster hashing algorithm in the testing context to speed up the run.
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
# Debug toolbar
DEBUG_TOOLBAR = env.bool("SCANCODEIO_DEBUG_TOOLBAR", default=False)
if DEBUG and DEBUG_TOOLBAR:
INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
INTERNAL_IPS = ["127.0.0.1"]
# Logging
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "{levelname} {message}",
"style": "{",
},
},
"handlers": {
"null": {
"class": "logging.NullHandler",
},
"console": {
"class": "logging.StreamHandler",
"formatter": "simple",
},
},
"loggers": {
"scanpipe": {
"handlers": ["null"] if IS_TESTS else ["console"],
"level": SCANCODEIO_LOG_LEVEL,
"propagate": False,
},
"django": {
"handlers": ["null"] if IS_TESTS else ["console"],
"propagate": False,
},
# Set SCANCODEIO_LOG_LEVEL=DEBUG to display all SQL queries in the console.
"django.db.backends": {
"level": SCANCODEIO_LOG_LEVEL,
},
},
}
# Instead of sending out real emails the console backend just writes the emails
# that would be sent to the standard output.
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Internationalization
LANGUAGE_CODE = "en-us"
TIME_ZONE = env.str("TIME_ZONE", default="UTC")
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = "/static/"
STATIC_ROOT = env.str("STATIC_ROOT", default="/var/scancodeio/static/")
STATICFILES_DIRS = [
PROJECT_DIR("static"),
]
# Third-party apps
CRISPY_TEMPLATE_PACK = "bootstrap3"
# Job Queue
RQ_QUEUES = {
"default": {
"HOST": env.str("SCANCODEIO_REDIS_HOST", default="localhost"),
"PORT": env.str("SCANCODEIO_REDIS_PORT", default="6379"),
"PASSWORD": env.str("SCANCODEIO_REDIS_PASSWORD", default=""),
"DEFAULT_TIMEOUT": env.int("SCANCODEIO_REDIS_DEFAULT_TIMEOUT", default=360),
},
}
SCANCODEIO_ASYNC = env.bool("SCANCODEIO_ASYNC", default=False)
if not SCANCODEIO_ASYNC:
for queue_config in RQ_QUEUES.values():
queue_config["ASYNC"] = False
# ClamAV virus scan
CLAMD_USE_TCP = env.bool("CLAMD_USE_TCP", default=True)
CLAMD_TCP_ADDR = env.str("CLAMD_TCP_ADDR", default="clamav")
# Django restframework
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_RENDERER_CLASSES": (
"rest_framework.renderers.JSONRenderer",
"rest_framework.renderers.BrowsableAPIRenderer",
"rest_framework.renderers.AdminRenderer",
),
"DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.SearchFilter",
),
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": env.int("SCANCODEIO_REST_API_PAGE_SIZE", default=50),
"UPLOADED_FILES_USE_URL": False,
}
if not SCANCODEIO_REQUIRE_AUTHENTICATION:
REST_FRAMEWORK["DEFAULT_PERMISSION_CLASSES"] = (
"rest_framework.permissions.AllowAny",
)
# VulnerableCode integration
VULNERABLECODE_URL = env.str("VULNERABLECODE_URL", default="")
VULNERABLECODE_USER = env.str("VULNERABLECODE_USER", default="")
VULNERABLECODE_PASSWORD = env.str("VULNERABLECODE_PASSWORD", default="")
VULNERABLECODE_API_KEY = env.str("VULNERABLECODE_API_KEY", default="")
# PurlDB integration
PURLDB_URL = env.str("PURLDB_URL", default="")
PURLDB_USER = env.str("PURLDB_USER", default="")
PURLDB_PASSWORD = env.str("PURLDB_PASSWORD", default="")
PURLDB_API_KEY = env.str("PURLDB_API_KEY", default="")
# MatchCode.io integration
MATCHCODEIO_URL = env.str("MATCHCODEIO_URL", default="")
MATCHCODEIO_USER = env.str("MATCHCODEIO_USER", default="")
MATCHCODEIO_PASSWORD = env.str("MATCHCODEIO_PASSWORD", default="")
MATCHCODEIO_API_KEY = env.str("MATCHCODEIO_API_KEY", default="")
# FederatedCode integration
FEDERATEDCODE_GIT_ACCOUNT_URL = env.str("FEDERATEDCODE_GIT_ACCOUNT_URL", default="")
FEDERATEDCODE_GIT_SERVICE_TOKEN = env.str("FEDERATEDCODE_GIT_SERVICE_TOKEN", default="")
FEDERATEDCODE_GIT_SERVICE_NAME = env.str("FEDERATEDCODE_GIT_SERVICE_NAME", default="")
FEDERATEDCODE_GIT_SERVICE_EMAIL = env.str("FEDERATEDCODE_GIT_SERVICE_EMAIL", default="")