1
"""
2
Django settings for cyborgbackup project.
3

4
Generated by 'django-admin startproject' using Django 1.11.15.
5

6
For more information on this file, see
7
https://docs.djangoproject.com/en/1.11/topics/settings/
8

9
For the full list of settings and their values, see
10
https://docs.djangoproject.com/en/1.11/ref/settings/
11
"""
12

13 3
import os
14 3
import urllib.parse
15 3
from datetime import timedelta
16 3
from celery.schedules import crontab
17 3
from kombu import Queue, Exchange
18 3
from kombu.common import Broadcast
19 3
from corsheaders.defaults import default_headers
20

21
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
22 3
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
23

24 3
JOBOUTPUT_ROOT = os.path.join(BASE_DIR, 'job_output')
25

26 3
SCRIPTS_DIR = os.path.join(BASE_DIR, 'cyborgbackup', 'scripts')
27 3
PROVIDER_DIR = os.path.join(BASE_DIR, 'cyborgbackup', 'provider')
28

29
# Quick-start development settings - unsuitable for production
30
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
31

32
# SECURITY WARNING: keep the secret key used in production secret!
33 3
try:
34 3
    SECRET_KEY
35 3
except NameError:
36 3
    SECRET_FILE = os.path.join(BASE_DIR, 'secret.txt')
37 3
    try:
38 3
        SECRET_KEY = open(SECRET_FILE).read().strip()
39 0
    except IOError:
40 0
        try:
41 0
            import random
42 0
            choices = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
43 0
            SECRET_KEY = ''.join([random.SystemRandom().choice(choices) for i in range(50)])
44 0
            secret = open(SECRET_FILE, 'w')
45 0
            secret.write(SECRET_KEY)
46 0
            secret.close()
47 0
        except IOError:
48 0
            Exception('Please create a %s file with random characters \
49
            to generate your secret key!' % SECRET_FILE)
50

51
# SECURITY WARNING: don't run with debug turned on in production!
52 3
DEBUG = True
53 3
SQL_DEBUG = False
54

55 3
ALLOWED_HOSTS = ['web', 'localhost', '127.0.0.1', '::1', '*']
56

57
# Application definition
58

59 3
INSTALLED_APPS = [
60
    'django.contrib.admin',
61
    'django.contrib.auth',
62
    'django.contrib.contenttypes',
63
    'django.contrib.sessions',
64
    'django.contrib.messages',
65
    'django.contrib.staticfiles',
66
    'django_celery_results',
67
    'corsheaders',
68
    'rest_framework',
69
    'rest_framework.authtoken',
70
    'rest_framework_swagger',
71
    'channels',
72
    'django_elasticsearch_dsl',
73
    'django_elasticsearch_dsl_drf',
74
    'django_rest_passwordreset',
75
    'debug_toolbar',
76
    'elastic_panel',
77
    'cyborgbackup.elasticsearch',
78
    'cyborgbackup.ui',
79
    'cyborgbackup.api',
80
    'cyborgbackup.main'
81
]
82

83 3
DEBUG_TOOLBAR_CONFIG = {
84
    'INTERCEPT_REDIRECTS': False,
85
}
86

87 3
DEBUG_TOOLBAR_PANELS = (
88
    # Defaults
89
    'debug_toolbar.panels.versions.VersionsPanel',
90
    'debug_toolbar.panels.timer.TimerPanel',
91
    'debug_toolbar.panels.settings.SettingsPanel',
92
    'debug_toolbar.panels.headers.HeadersPanel',
93
    'debug_toolbar.panels.request.RequestPanel',
94
    'debug_toolbar.panels.sql.SQLPanel',
95
    'debug_toolbar.panels.staticfiles.StaticFilesPanel',
96
    'debug_toolbar.panels.templates.TemplatesPanel',
97
    'debug_toolbar.panels.cache.CachePanel',
98
    'debug_toolbar.panels.signals.SignalsPanel',
99
    'debug_toolbar.panels.logging.LoggingPanel',
100
    'debug_toolbar.panels.redirects.RedirectsPanel',
101
    # Additional
102
    'elastic_panel.panel.ElasticDebugPanel',
103
)
104

105 3
BROKER_URL = "amqp://{}:{}@{}/{}".format(os.environ.get("RABBITMQ_DEFAULT_USER", "cyborgbackup"),
106
                                         os.environ.get("RABBITMQ_DEFAULT_PASS", "cyborgbackup"),
107
                                         os.environ.get("RABBITMQ_HOST", "rabbitmq"),
108
                                         urllib.parse.quote(
109
                                             os.environ.get(
110
                                                 "RABBITMQ_DEFAULT_VHOST",
111
                                                 "cyborgbackup"),
112
                                             safe=''
113
                                         ))
114

115 3
CHANNEL_LAYERS = {
116
    'default': {'BACKEND': 'asgi_amqp.AMQPChannelLayer',
117
                'ROUTING': 'cyborgbackup.main.routing.channel_routing',
118
                'CONFIG': {'url': BROKER_URL}}
119
}
120

121 3
MIDDLEWARE = [
122
    'django.middleware.security.SecurityMiddleware',
123
    'django.contrib.sessions.middleware.SessionMiddleware',
124
    'corsheaders.middleware.CorsMiddleware',
125
    'django.middleware.common.CommonMiddleware',
126
    'django.middleware.csrf.CsrfViewMiddleware',
127
    'django.contrib.auth.middleware.AuthenticationMiddleware',
128
    'django.contrib.messages.middleware.MessageMiddleware',
129
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
130
    'crum.CurrentRequestUserMiddleware',
131
    'debug_toolbar.middleware.DebugToolbarMiddleware',
132
]
133

134 3
ROOT_URLCONF = 'cyborgbackup.urls'
135

136 3
CORS_ORIGIN_ALLOW_ALL = True
137 3
CORS_ALLOW_HEADERS = list(default_headers) + [
138
    'access-control-allow-methods',
139
    'access-control-allow-origin',
140
    'cookies'
141
]
142

143

144 3
TEMPLATES = [
145
    {
146
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
147
        'DIRS': [os.path.join(BASE_DIR, 'cyborgbackup/templates'), ],
148
        'APP_DIRS': True,
149
        'OPTIONS': {
150
            'context_processors': [
151
                'django.template.context_processors.debug',
152
                'django.template.context_processors.request',
153
                'django.contrib.auth.context_processors.auth',
154
                'django.contrib.messages.context_processors.messages',
155
            ],
156
        },
157
    },
158
]
159

160 3
WSGI_APPLICATION = 'cyborgbackup.wsgi.application'
161

162 3
ASGI_APPLICATION = 'cyborgbackup.routing.application'
163

164 3
ASGI_AMQP = {
165
    'INIT_FUNC': 'cyborgbackup.prepare_env',
166
    'MODEL': 'cyborgbackup.main.models.channels.ChannelGroup',
167
}
168

169

170
# Database
171
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
172

173 3
DATABASES = {
174
    'default': {
175
        'ENGINE': 'django.db.backends.postgresql',
176
        'NAME': os.environ.get('POSTGRES_NAME', 'cyborgbackup'),
177
        'USER': os.environ.get('POSTGRES_USER', 'postgres'),
178
        'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
179
        'HOST': os.environ.get('POSTGRES_HOST', 'localhost'),
180
        'PORT': os.environ.get('POSTGRES_PORT', 5432),
181
    }
182
}
183

184 3
REST_FRAMEWORK = {
185
    'DEFAULT_PAGINATION_CLASS': 'cyborgbackup.api.pagination.Pagination',
186
    'PAGE_SIZE': 100,
187
    'DEFAULT_AUTHENTICATION_CLASSES': (
188
        'cyborgbackup.api.authentication.SessionAuthentication',
189
        'cyborgbackup.api.authentication.LoggedBasicAuthentication',
190
        'rest_framework.authentication.TokenAuthentication',
191
        'rest_framework_simplejwt.authentication.JWTAuthentication'
192
    ),
193
    'DEFAULT_PERMISSION_CLASSES': (
194
        'cyborgbackup.api.permissions.ModelAccessPermission',
195
        'cyborgbackup.api.permissions.AllowOptionsAuthentication',
196
    ),
197
    'DEFAULT_FILTER_BACKENDS': (
198
        'cyborgbackup.api.filters.TypeFilterBackend',
199
        'cyborgbackup.api.filters.FieldLookupBackend',
200
        'rest_framework.filters.SearchFilter',
201
        'cyborgbackup.api.filters.OrderByBackend',
202
    ),
203
    'DEFAULT_PARSER_CLASSES': (
204
        'cyborgbackup.api.parsers.JSONParser',
205
    ),
206
    'DEFAULT_RENDERER_CLASSES': (
207
        'rest_framework.renderers.JSONRenderer',
208
        'cyborgbackup.api.renderers.BrowsableAPIRenderer',
209
    ),
210
    'DEFAULT_METADATA_CLASS': 'cyborgbackup.api.metadata.Metadata',
211
    'EXCEPTION_HANDLER': 'cyborgbackup.api.views.api_exception_handler',
212
    'VIEW_NAME_FUNCTION': 'cyborgbackup.api.generics.get_view_name',
213
    'VIEW_DESCRIPTION_FUNCTION': 'cyborgbackup.api.generics.get_view_description',
214
    'NON_FIELD_ERRORS_KEY': '__all__',
215
    'DEFAULT_VERSION': 'v1',
216
    # 'URL_FORMAT_OVERRIDE': None,
217
}
218

219
# Absolute filesystem path to the directory to store logs
220 3
LOGGING = {
221
    'version': 1,
222
    'disable_existing_loggers': False,
223
    'filters': {
224
        'require_debug_false': {
225
            '()': 'django.utils.log.RequireDebugFalse',
226
        },
227
        'require_debug_true': {
228
            '()': 'django.utils.log.RequireDebugTrue',
229
        },
230
    },
231
    'formatters': {
232
        'simple': {
233
            'format': '%(asctime)s %(levelname)-8s %(name)s %(message)s',
234
        },
235
    },
236
    'handlers': {
237
        'console': {
238
            '()': 'logging.StreamHandler',
239
            'level': 'DEBUG',
240
            'formatter': 'simple',
241
        },
242
    },
243
    'loggers': {
244
        'django': {
245
            'handlers': ['console'],
246
            'level': 'INFO',
247
        },
248
        'django.request': {
249
            'handlers': ['console'],
250
            'level': 'WARNING',
251
        },
252
        'rest_framework.request': {
253
            'handlers': ['console'],
254
            'level': 'WARNING',
255
            'propagate': False,
256
        },
257
        'py.warnings': {
258
            'handlers': ['console'],
259
            'level': 'DEBUG',
260
        },
261
        'cyborgbackup': {
262
            'handlers': ['console'],
263
            'level': 'DEBUG',
264
        },
265
        'elasticsearch': {
266
            'handlers': ['console'],
267
            'level': 'DEBUG',
268
        },
269
    },
270
}
271
# LOGGING['handlers']['console']['()'] = 'cyborgbackup.main.utils.handlers.ColorHandler'
272 3
LOGGING['handlers']['console'] = {
273
    '()': 'logging.StreamHandler',
274
    'level': 'DEBUG',
275
    'formatter': 'simple',
276
}
277

278

279 3
AUTH_USER_MODEL = 'main.User'
280

281
# Password validation
282
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
283

284 3
AUTH_PASSWORD_VALIDATORS = [
285
    {
286
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
287
    },
288
    {
289
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
290
    },
291
    {
292
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
293
    },
294
    {
295
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
296
    },
297
]
298

299 3
SIMPLE_JWT = {
300
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
301
    'REFRESH_TOKEN_LIFETIME': timedelta(days=14),
302
    'ROTATE_REFRESH_TOKENS': True,
303
    'BLACKLIST_AFTER_ROTATION': False,
304
    'ALGORITHM': 'HS256',
305
    'SIGNING_KEY': SECRET_KEY,
306
    'VERIFYING_KEY': None,
307
    'AUTH_HEADER_TYPES': ('Bearer',),
308
    'USER_ID_FIELD': 'id',
309
    'USER_ID_CLAIM': 'user_id',
310
    'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
311
    'TOKEN_TYPE_CLAIM': 'token_type',
312
}
313

314

315
# Internationalization
316
# https://docs.djangoproject.com/en/1.11/topics/i18n/
317

318 3
LANGUAGE_CODE = 'en-us'
319

320 3
TIME_ZONE = 'UTC'
321

322 3
USE_I18N = True
323

324 3
USE_L10N = True
325

326 3
USE_TZ = True
327

328

329
# Static files (CSS, JavaScript, Images)
330
# https://docs.djangoproject.com/en/1.11/howto/static-files/
331

332 3
STATICFILES_DIRS = (
333
    os.path.join(BASE_DIR, 'cyborgbackup', 'static'),
334
    os.path.join(BASE_DIR, 'cyborgbackup', 'ui', 'static'),
335
)
336

337 3
STATIC_URL = '/static/'
338

339 3
NAMED_URL_GRAPH = {}
340

341 3
PERSISTENT_CALLBACK_MESSAGES = True
342 3
USE_CALLBACK_QUEUE = True
343 3
CALLBACK_QUEUE = "callback_tasks"
344

345 3
IGNORE_CELERY_INSPECTOR = True
346 3
CELERY_RDBSIG = 1
347 3
CELERY_ALWAYS_EAGER = True
348 3
CELERY_BROKER_URL = BROKER_URL
349 3
CELERY_BROKER_POOL_LIMIT = None
350 3
CELERY_EVENT_QUEUE_TTL = 5
351 3
CELERY_ACCEPT_CONTENT = ['json']
352 3
CELERY_TRACK_STARTED = True
353 3
CELERYD_TASK_TIME_LIMIT = 86400
354 3
CELERYD_TASK_SOFT_TIME_LIMIT = None
355 3
CELERYD_POOL_RESTARTS = True
356 3
CELERY_RESULT_BACKEND = 'django-db'
357 3
CELERY_IMPORTS = ('cyborgbackup.main.utils.tasks', 'cyborgbackup.main.tasks')
358 3
CELERY_QUEUES = (
359
    Queue('cyborgbackup', Exchange('cyborgbackup'), routing_key='cyborgbackup'),
360
    Broadcast('cyborgbackup_broadcast_all')
361
)
362 3
CELERY_ACCEPT_CONTENT = ['application/json']
363 3
CELERY_TASK_SERIALIZER = 'json'
364 3
CELERY_RESULT_SERIALIZER = 'json'
365

366 3
CELERY_ROUTES = {}
367 3
CELERY_BEAT_SCHEDULER = 'celery.beat.PersistentScheduler'
368 3
CELERY_BEAT_SCHEDULE_FILENAME = os.path.join(
369
    BASE_DIR,
370
    'var',
371
    'run',
372
    'celerybeat-schedule')
373 3
CELERY_BEAT_MAX_LOOP_INTERVAL = 60
374 3
CELERY_BEAT_SCHEDULE = {
375
    'cyborgbackup_notify_daily': {
376
        'task': 'cyborgbackup.main.tasks.cyborgbackup_notifier',
377
        'schedule': crontab(minute='55', hour='23'),
378
        'args': ('daily',)
379
    },
380
    'cyborgbackup_notify_weekly': {
381
        'task': 'cyborgbackup.main.tasks.cyborgbackup_notifier',
382
        'schedule': crontab(hour=0, minute=0, day_of_week=6),
383
        'args': ('weekly',)
384
    },
385
    'cyborgbackup_notify_monthly': {
386
        'task': 'cyborgbackup.main.tasks.cyborgbackup_notifier',
387
        'schedule': crontab(hour=0, minute=0, day_of_month=1),
388
        'args': ('monthly',)
389
    },
390
    'cyborgbackup_scheduler': {
391
        'task': 'cyborgbackup.main.tasks.cyborgbackup_periodic_scheduler',
392
        'schedule': timedelta(seconds=30),
393
        'options': {'expires': 20}
394
    },
395
    'cyborgbackup_compute_Size': {
396
        'task': 'cyborgbackup.main.tasks.compute_borg_size',
397
        'schedule': timedelta(seconds=10),
398
        'options': {'expires': 20}
399
    },
400
    'cyborgbackup_prune_catalog': {
401
        'task': 'cyborgbackup.main.tasks.prune_catalog',
402
        'schedule': crontab(minute='30'),
403
        'options': {'expires': 20}
404
    },
405
    'task_manager': {
406
        'task': 'cyborgbackup.main.utils.tasks.run_task_manager',
407
        'schedule': timedelta(seconds=20),
408
        'options': {'expires': 20}
409
    },
410
}
411

412 3
ACTIVITY_STREAM_ENABLED = False
413 3
ELASTICSEARCH_DSL = {
414
    'default': {
415
        'hosts': '{}'.format(os.environ.get("ELASTICSEARCH_HOST", "localhost:9200"))
416
    },
417
}

Read our documentation on viewing source code .

Loading