-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathbase.py
255 lines (208 loc) · 7.6 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
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/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/nexB/scancode.io for support and download.
import sys
from pathlib import Path
import environ
PROJECT_DIR = Path(__file__).resolve().parent.parent
ROOT_DIR = PROJECT_DIR.parent
# Environment
env_file = "/etc/scancodeio/.env"
if not Path(env_file).exists():
env_file = str(ROOT_DIR.joinpath(".env"))
environ.Env.read_env(env_file)
env = environ.Env()
SECRET_KEY = env.str("SECRET_KEY")
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]"])
# ScanCode.io
SCANCODEIO_WORKSPACE_LOCATION = env.str("SCANCODEIO_WORKSPACE_LOCATION", default="var")
SCANCODE_DEFAULT_OPTIONS = env.list("SCANCODE_DEFAULT_OPTIONS", default=[])
# Set the number of parallel processes to use for ScanCode related scan execution.
# If the SCANCODE_PROCESSES argument is not set, defaults to the number of CPUs minus 1.
SCANCODEIO_PROCESSES = env.int("SCANCODEIO_PROCESSES", default=None)
SCANCODEIO_POLICIES_FILE = env.str("SCANCODEIO_POLICIES_FILE", default="policies.yml")
# Application definition
INSTALLED_APPS = (
# Local apps
# Must come before Third-party apps for proper templates override
"scanner",
"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",
"django_filters",
"rest_framework",
"rest_framework.authtoken",
)
MIDDLEWARE = (
"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"
# 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": "5432",
"ATOMIC_REQUESTS": True,
}
}
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# Templates
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"debug": False,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
"scancodeio.context_processors.versions",
],
},
},
]
# Passwords
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
"OPTIONS": {
"min_length": 14,
},
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# True if running tests through `./manage test`
IS_TESTS = "test" in sys.argv
# Cache
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "default",
},
"scan_results": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "scan",
"TIMEOUT": 86_400, # 1 day
"OPTIONS": {
# Maximum entries allowed in the cache before old values are deleted
"MAX_ENTRIES": 1_000_000,
},
},
}
# Logging
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"null": {
"class": "logging.NullHandler",
},
"console": {
"class": "logging.StreamHandler",
},
},
"loggers": {
"scanner.tasks": {
"handlers": ["null"] if IS_TESTS else ["console"],
"level": env.str("DJANGO_LOG_LEVEL", "INFO"),
},
"scanpipe.pipelines": {
"handlers": ["null"] if IS_TESTS else ["console"],
"level": env.str("DJANGO_LOG_LEVEL", "INFO"),
},
"scanpipe.pipes": {
"handlers": ["null"] if IS_TESTS else ["console"],
"level": env.str("DJANGO_LOG_LEVEL", "INFO"),
},
},
}
# 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_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = "/static/"
STATIC_ROOT = "/var/scancodeio/static/"
STATICFILES_DIRS = [
str(PROJECT_DIR.joinpath("static")),
]
# Third-party apps
CRISPY_TEMPLATE_PACK = "bootstrap3"
# Celery
CELERY_BROKER_URL = env.str("CELERY_BROKER_URL", default="redis://")
CELERY_RESULT_BACKEND = env.str("CELERY_RESULT_BACKEND", default="redis://")
CELERY_TRACK_STARTED = env.bool("CELERY_TRACK_STARTED", default=True)
CELERY_IGNORE_RESULT = env.bool("CELERY_IGNORE_RESULT", default=False)
CELERY_TASK_DEFAULT_QUEUE = env.str("CELERY_RESULT_BACKEND", default="default")
# When True, tasks will be executed immediately in the local thread instead of being
# sent to the queue for execution by a worker.
CELERY_TASK_ALWAYS_EAGER = env.bool("CELERY_TASK_ALWAYS_EAGER", default=True)
# 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": 10,
"UPLOADED_FILES_USE_URL": False,
}