/
server.py
374 lines (316 loc) · 11.4 KB
/
server.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
"""
sentry.conf.server
~~~~~~~~~~~~~~~~~~
These settings act as the default (base) settings for the Sentry-provided web-server
:copyright: (c) 2010-2013 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from django.conf.global_settings import * # NOQA
import hashlib
import os
import os.path
import socket
import sys
import urlparse
DEBUG = False
TEMPLATE_DEBUG = True
ADMINS = ()
INTERNAL_IPS = ('127.0.0.1',)
MANAGERS = ADMINS
APPEND_SLASH = True
PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, os.path.normpath(os.path.join(PROJECT_ROOT, os.pardir)))
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'sentry.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
if 'DATABASE_URL' in os.environ:
url = urlparse.urlparse(os.environ['DATABASE_URL'])
# Ensure default database exists.
DATABASES['default'] = DATABASES.get('default', {})
# Update with environment configuration.
DATABASES['default'].update({
'NAME': url.path[1:],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
})
if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'UTC'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
USE_TZ = True
# Make this unique, and don't share it with anybody.
SECRET_KEY = hashlib.md5(socket.gethostname() + ')*)&8a36)6%74e@-ne5(-!8a(vv#tkv)(eyg&@0=zd^pl!7=y@').hexdigest()
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'sentry.middleware.SentryMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'sentry.conf.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_ROOT, 'templates'),
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.csrf',
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect'
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'crispy_forms',
'djcelery',
'gunicorn',
'kombu.transport.django',
'raven.contrib.django.raven_compat',
'sentry',
'sentry.plugins.sentry_interface_types',
'sentry.plugins.sentry_mail',
'sentry.plugins.sentry_servers',
'sentry.plugins.sentry_urls',
'sentry.plugins.sentry_useragents',
'social_auth',
'south',
'static_compiler',
'django_social_auth_trello',
)
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/_static/'
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
"static_compiler.finders.StaticCompilerFinder",
)
LOCALE_PATHS = (
os.path.join(PROJECT_ROOT, 'locale'),
)
# Auth configuration
try:
from django.core.urlresolvers import reverse_lazy
except ImportError:
LOGIN_REDIRECT_URL = '/login-redirect/'
LOGIN_URL = '/login/'
else:
LOGIN_REDIRECT_URL = reverse_lazy('sentry-login-redirect')
LOGIN_URL = reverse_lazy('sentry-login')
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.google.GoogleOAuthBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.yahoo.YahooBackend',
'social_auth.backends.browserid.BrowserIDBackend',
'social_auth.backends.contrib.linkedin.LinkedinBackend',
'social_auth.backends.contrib.livejournal.LiveJournalBackend',
'social_auth.backends.contrib.orkut.OrkutBackend',
'social_auth.backends.contrib.foursquare.FoursquareBackend',
'social_auth.backends.contrib.github.GithubBackend',
'social_auth.backends.contrib.dropbox.DropboxBackend',
'social_auth.backends.contrib.flickr.FlickrBackend',
'social_auth.backends.contrib.instagram.InstagramBackend',
'social_auth.backends.contrib.vkontakte.VKontakteBackend',
'social_auth.backends.contrib.skyrock.SkyrockBackend',
'social_auth.backends.contrib.yahoo.YahooOAuthBackend',
'social_auth.backends.OpenIDBackend',
'social_auth.backends.contrib.bitbucket.BitbucketBackend',
'social_auth.backends.contrib.mixcloud.MixcloudBackend',
'social_auth.backends.contrib.live.LiveBackend',
'django_social_auth_trello.backend.TrelloBackend',
'sentry.utils.auth.EmailAuthBackend',
)
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET = ''
FACEBOOK_APP_ID = ''
FACEBOOK_API_SECRET = ''
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
GOOGLE_OAUTH2_CLIENT_ID = ''
GOOGLE_OAUTH2_CLIENT_SECRET = ''
GITHUB_APP_ID = ''
GITHUB_API_SECRET = ''
TRELLO_API_KEY = ''
TRELLO_API_SECRET = ''
SOCIAL_AUTH_CREATE_USERS = True
import random
SOCIAL_AUTH_DEFAULT_USERNAME = lambda: random.choice(['Darth Vader', 'Obi-Wan Kenobi', 'R2-D2', 'C-3PO', 'Yoda'])
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email']
# Queue configuration
from kombu import Queue
BROKER_URL = "django://"
CELERY_IGNORE_RESULT = True
CELERY_SEND_EVENTS = False
CELERY_RESULT_BACKEND = None
CELERY_TASK_RESULT_EXPIRES = 1
CELERY_DISABLE_RATE_LIMITS = True
CELERY_DEFAULT_QUEUE = "default"
CELERY_DEFAULT_EXCHANGE = "default"
CELERY_DEFAULT_EXCHANGE_TYPE = "direct"
CELERY_DEFAULT_ROUTING_KEY = "default"
CELERY_CREATE_MISSING_QUEUES = True
CELERY_QUEUES = (
Queue('default', routing_key='default'),
Queue('celery', routing_key='celery'),
Queue('alerts', routing_key='alerts'),
Queue('cleanup', routing_key='cleanup'),
Queue('sourcemaps', routing_key='sourcemaps'),
Queue('search', routing_key='search'),
Queue('counters', routing_key='counters'),
Queue('events', routing_key='events'),
Queue('triggers', routing_key='triggers'),
)
# Sentry and Raven configuration
SENTRY_PUBLIC = False
SENTRY_PROJECT = 1
SENTRY_CACHE_BACKEND = 'default'
EMAIL_SUBJECT_PREFIX = '[Sentry] '
# Disable South in tests as it is sending incorrect create signals
SOUTH_TESTS_MIGRATE = False
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'console': {
'level': 'WARNING',
'class': 'logging.StreamHandler'
},
'sentry': {
'class': 'raven.contrib.django.handlers.SentryHandler',
}
},
'loggers': {
'()': {
'handlers': ['console', 'sentry'],
},
'root': {
'handlers': ['console', 'sentry'],
},
'sentry': {
'level': 'ERROR',
'handlers': ['console', 'sentry'],
'propagate': False,
},
'sentry.errors': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'django.request': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
}
}
NPM_ROOT = os.path.abspath(os.path.join(PROJECT_ROOT, os.pardir, os.pardir, 'node_modules'))
# We only define static bundles if NPM has been setup
if os.path.exists(NPM_ROOT):
STATIC_BUNDLES = {
"packages": {
"sentry/scripts/global.min.js": {
"src": [
"sentry/scripts/core.js",
"sentry/scripts/models.js",
"sentry/scripts/templates.js",
"sentry/scripts/utils.js",
"sentry/scripts/collections.js",
"sentry/scripts/charts.js",
"sentry/scripts/views.js",
"sentry/scripts/app.js",
],
},
"sentry/scripts/legacy.min.js": {
"src": [
"sentry/scripts/sentry.core.js",
"sentry/scripts/sentry.charts.js",
"sentry/scripts/sentry.stream.js",
],
},
"sentry/scripts/lib.min.js": {
"src": [
"sentry/scripts/lib/jquery.js",
"sentry/scripts/lib/jquery-migrate.js",
"sentry/scripts/lib/jquery.animate-colors.js",
"sentry/scripts/lib/jquery.clippy.min.js",
"sentry/scripts/lib/jquery.cookie.js",
"sentry/scripts/lib/jquery.flot.min.js",
"sentry/scripts/lib/simple-slider.js",
"sentry/scripts/lib/json2.js",
"sentry/scripts/lib/underscore.js",
"sentry/scripts/lib/backbone.js",
"sentry/scripts/lib/select2/select2.js",
"sentry/scripts/lib/bootstrap.js",
],
},
"sentry/styles/global.min.css": {
"src": {
"sentry/less/sentry.less": "sentry/styles/sentry.css",
},
},
"sentry/styles/wall.min.css": {
"src": {
"sentry/less/wall.less": "sentry/styles/wall.css",
},
},
},
"postcompilers": {
"*.js": ["node_modules/uglify-js/bin/uglifyjs {input} --source-map-root={relroot}/ --source-map-url={name}.map{ext} --source-map={relpath}/{name}.map{ext} -o {output}"],
},
"preprocessors": {
"*.less": ["node_modules/less/bin/lessc {input} {output}"],
},
}
# Configure celery
import djcelery
djcelery.setup_loader()