We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove opbeat
Opbeat is no longer a thing, so we should remove it and replace it with something else? Maybe double down on Sentry and integrate that more tightly

https://github.com/uclapi/uclapi/blob/81b90305f9316b020664b32c2436e27ab957e8a7/backend/uclapi/requirements.txt#L33

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `backend/uclapi/uclapi/celery.py`
Content:
```
1 from __future__ import absolute_import, unicode_literals
2 
3 import celery
4 import os
5 import raven
6 
7 from django.conf import settings
8 from raven.contrib.celery import register_signal as raven_register_signal, \
9     register_logger_signal as raven_register_logger_signal
10 
11 from common.helpers import read_dotenv
12 
13 read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))
14 
15 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uclapi.settings')
16 
17 
18 class Celery(celery.Celery):
19     def on_configure(self):
20         if os.environ.get("SENTRY_DSN") is not None:
21             client = raven.Client(os.environ.get("SENTRY_DSN"))
22             raven_register_logger_signal(client)
23             raven_register_signal(client)
24 
25 
26 app = Celery('uclapi')
27 
28 app.config_from_object('django.conf.settings', namespace='CELERY')
29 
30 
31 from opbeat.contrib.django.models import \
32     register_handlers as opbeat_register_handlers, \
33     logger as opbeat_logger  # noqa: E402#
34 
35 from opbeat.contrib.celery import \
36     register_signal as opbeat_register_signal  # noqa: E402
37 
38 
39 try:
40     opbeat_register_signal(app)
41 except Exception as e:
42     opbeat_logger.exception('Failed installing celery hook: %s' % e)
43 
44 if 'opbeat.contrib.django' in settings.INSTALLED_APPS:
45     opbeat_register_handlers()
46 
47 app.autodiscover_tasks()
48 
49 
50 @app.task(bind=True)
51 def task(self):
52     print('Request: {0!r}'.format(self.request))
53
```

Path: `backend/uclapi/uclapi/settings.py`
Content:
```
1 """
2 Django settings for uclapi project.
3 
4 Generated by 'django-admin startproject' using Django 1.10.4.
5 
6 For more information on this file, see
7 https://docs.djangoproject.com/en/1.10/topics/settings/
8 
9 For the full list of settings and their values, see
10 https://docs.djangoproject.com/en/1.10/ref/settings/
11 """
12 
13 import os
14 import requests
15 from distutils.util import strtobool
16 
17 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
18 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19 
20 
21 # Quick-start development settings - unsuitable for production
22 # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
23 
24 # SECURITY WARNING: keep the secret key used in production secret!
25 SECRET_KEY = os.environ.get("SECRET_KEY")
26 
27 # SECURITY WARNING: don't run with debug turned on in production!
28 # This value should be set by the UCLAPI_PRODUCTION environment
29 # variable anyway. If in production, debug should be false.
30 DEBUG = not strtobool(os.environ.get("UCLAPI_PRODUCTION"))
31 
32 ALLOWED_HOSTS = ["localhost"]
33 
34 # If a domain is specified then make this an allowed host
35 if os.environ.get("UCLAPI_DOMAIN"):
36     ALLOWED_HOSTS.append(os.environ.get("UCLAPI_DOMAIN"))
37 
38 # If we are running under the AWS Elastic Load Balancer then enable internal
39 # requests so that the ELB and Health Checks work
40 if strtobool(os.environ.get("UCLAPI_RUNNING_ON_AWS_ELB")):
41     EC2_PRIVATE_IP = None
42     try:
43         EC2_PRIVATE_IP = requests.get(
44             "http://169.254.169.254/latest/meta-data/local-ipv4",
45             timeout=0.01
46         ).text
47     except requests.exceptions.RequestException:
48         pass
49 
50     if EC2_PRIVATE_IP:
51         ALLOWED_HOSTS.append(EC2_PRIVATE_IP)
52 
53 # Application definition
54 
55 INSTALLED_APPS = [
56     'django.contrib.admin',
57     'django.contrib.auth',
58     'django.contrib.contenttypes',
59     'django.contrib.sessions',
60     'django.contrib.messages',
61     'django.contrib.staticfiles',
62     'rest_framework',
63     'dashboard',
64     'marketplace',
65     'roombookings',
66     'oauth',
67     'timetable',
68     'common',
69     'opbeat.contrib.django',
70     'raven.contrib.django.raven_compat',
71     'corsheaders',
72     'workspaces'
73 ]
74 
75 MIDDLEWARE = [
76     'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',
77     'django.middleware.security.SecurityMiddleware',
78     'django.contrib.sessions.middleware.SessionMiddleware',
79     'corsheaders.middleware.CorsMiddleware',
80     'django.middleware.common.CommonMiddleware',
81     'django.middleware.csrf.CsrfViewMiddleware',
82     'django.contrib.auth.middleware.AuthenticationMiddleware',
83     'django.contrib.messages.middleware.MessageMiddleware',
84     'django.middleware.clickjacking.XFrameOptionsMiddleware',
85 ]
86 
87 if DEBUG:
88     MIDDLEWARE.append(
89         'dashboard.middleware.fake_shibboleth_middleware'
90         '.FakeShibbolethMiddleWare'
91     )
92 
93 ROOT_URLCONF = 'uclapi.urls'
94 
95 TEMPLATES = [
96     {
97         'BACKEND': 'django.template.backends.django.DjangoTemplates',
98         'DIRS': [],
99         'APP_DIRS': True,
100         'OPTIONS': {
101             'context_processors': [
102                 'django.template.context_processors.debug',
103                 'django.template.context_processors.request',
104                 'django.contrib.auth.context_processors.auth',
105                 'django.contrib.messages.context_processors.messages',
106             ],
107         },
108     },
109 ]
110 
111 WSGI_APPLICATION = 'uclapi.wsgi.application'
112 
113 
114 # Database
115 # https://docs.djangoproject.com/en/1.10/ref/settings/#databases
116 
117 DATABASES = {
118     'default': {
119         'ENGINE': 'django.db.backends.postgresql',
120         'NAME': os.environ.get("DB_UCLAPI_NAME"),
121         'USER': os.environ.get("DB_UCLAPI_USERNAME"),
122         'PASSWORD': os.environ.get("DB_UCLAPI_PASSWORD"),
123         'HOST': os.environ.get("DB_UCLAPI_HOST"),
124         'PORT': os.environ.get("DB_UCLAPI_PORT")
125     },
126     'roombookings': {
127         'ENGINE': 'django.db.backends.oracle',
128         'NAME': os.environ.get("DB_ROOMS_NAME"),
129         'USER': os.environ.get("DB_ROOMS_USERNAME"),
130         'PASSWORD': os.environ.get("DB_ROOMS_PASSWORD"),
131         'HOST': '',
132         'PORT': ''
133     },
134     'gencache': {
135         'ENGINE': 'django.db.backends.postgresql',
136         'NAME': os.environ.get("DB_CACHE_NAME"),
137         'USER': os.environ.get("DB_CACHE_USERNAME"),
138         'PASSWORD': os.environ.get("DB_CACHE_PASSWORD"),
139         'HOST': os.environ.get("DB_CACHE_HOST"),
140         'PORT': os.environ.get("DB_CACHE_PORT")
141     }
142 }
143 
144 DATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']
145 
146 # analytics
147 OPBEAT = {
148     'ORGANIZATION_ID': os.environ.get("OPBEAT_ORG_ID"),
149     'APP_ID': os.environ.get("OPBEAT_APP_ID"),
150     'SECRET_TOKEN': os.environ.get("OPBEAT_SECRET_TOKEN")
151 }
152 
153 RAVEN_CONFIG = {
154     'dsn': os.environ.get("SENTRY_DSN"),
155 }
156 
157 
158 # Password validation
159 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
160 
161 AUTH_PASSWORD_VALIDATORS = [
162     {
163         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa
164     },
165     {
166         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa
167     },
168     {
169         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa
170     },
171     {
172         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa
173     },
174 ]
175 
176 
177 # Internationalization
178 # https://docs.djangoproject.com/en/1.10/topics/i18n/
179 
180 LANGUAGE_CODE = 'en-us'
181 
182 TIME_ZONE = 'UTC'
183 
184 USE_I18N = True
185 
186 USE_L10N = True
187 
188 USE_TZ = False
189 
190 # Static files (CSS, JavaScript, Images)
191 # https://docs.djangoproject.com/en/1.10/howto/static-files/
192 
193 STATIC_URL = '/static/'
194 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
195 
196 # Cross Origin settings
197 CORS_ORIGIN_ALLOW_ALL = True
198 CORS_URLS_REGEX = r'^/roombookings/.*$'
199 
200 # Fair use policy
201 fair_use_policy_path = os.path.join(
202     BASE_DIR,
203     'uclapi/UCLAPIAcceptableUsePolicy.txt'
204 )
205 with open(fair_use_policy_path, 'r', encoding='utf-8') as fp:
206     FAIR_USE_POLICY = list(fp)
207 
208 REDIS_UCLAPI_HOST = os.environ["REDIS_UCLAPI_HOST"]
209 
210 # Celery Settings
211 CELERY_BROKER_URL = 'redis://' + REDIS_UCLAPI_HOST
212 CELERY_ACCEPT_CONTENT = ['json']
213 CELERY_TASK_SERIALIZER = 'json'
214 CELERY_RESULT_SERIALIZER = 'json'
215 
216 
217 ROOMBOOKINGS_SETID = 'LIVE-17-18'
218 
219 # S3 file storage settings
220 # There are three scenarios to consider:
221 # 1) Local development
222 #    In local dev,  AWS_S3_STATICS = False
223 #                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False
224 #    These allow you to use local statics using /static/ in the
225 #    same way as you would normally.
226 # 2) Production
227 #    In prod,       AWS_S3_STATICS = True
228 #                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False
229 #    This means that S3 statics will be used, but no creds are
230 #    needed on the boxes because web servers should never do
231 #    uploads to the remote S3 bucket.
232 # 3) Deployment
233 #    In deployment, AWS_S3_STATICS = True
234 #                   AWS_S3_STATICS_CREDENTIALS_ENABLED = True
235 #    This will be done either from CI/CD or from the computer
236 #    of a person who has permission to upload new statics to
237 #    S3.
238 
239 if strtobool(os.environ.get("AWS_S3_STATICS", "False")):
240     DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
241     STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
242     AWS_STORAGE_BUCKET_NAME = os.environ["AWS_S3_BUCKET_NAME"]
243     AWS_LOCATION = os.environ["AWS_S3_BUCKET_PATH"]
244     AWS_S3_REGION_NAME = os.environ["AWS_S3_REGION"]
245 
246     # This is a hack to not require AWS Access Credentials
247     # when the system is running in the Cloud. This avoids us from
248     # needing to store AWS credentials.
249     # https://github.com/jschneier/django-storages/issues/254#issuecomment-329813295  # noqa
250     AWS_S3_CUSTOM_DOMAIN = "{}.s3.amazonaws.com".format(
251         AWS_STORAGE_BUCKET_NAME
252     )
253 
254     # If credentials are enabled, collectstatic can do uploads
255     if strtobool(os.environ["AWS_S3_STATICS_CREDENTIALS_ENABLED"]):
256         AWS_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"]
257         AWS_SECRET_ACCESS_KEY = os.environ["AWS_ACCESS_SECRET"]
258         AWS_S3_OBJECT_PARAMETERS = {
259             'CacheControl': 'max-age=86400',
260         }
261         AWS_S3_ENCRYPTION = False
262     else:
263         AWS_QUERYSTRING_AUTH = False
264
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/backend/uclapi/uclapi/celery.py b/backend/uclapi/uclapi/celery.py
--- a/backend/uclapi/uclapi/celery.py
+++ b/backend/uclapi/uclapi/celery.py
@@ -27,23 +27,6 @@
 
 app.config_from_object('django.conf.settings', namespace='CELERY')
 
-
-from opbeat.contrib.django.models import \
-    register_handlers as opbeat_register_handlers, \
-    logger as opbeat_logger  # noqa: E402#
-
-from opbeat.contrib.celery import \
-    register_signal as opbeat_register_signal  # noqa: E402
-
-
-try:
-    opbeat_register_signal(app)
-except Exception as e:
-    opbeat_logger.exception('Failed installing celery hook: %s' % e)
-
-if 'opbeat.contrib.django' in settings.INSTALLED_APPS:
-    opbeat_register_handlers()
-
 app.autodiscover_tasks()
 
 
diff --git a/backend/uclapi/uclapi/settings.py b/backend/uclapi/uclapi/settings.py
--- a/backend/uclapi/uclapi/settings.py
+++ b/backend/uclapi/uclapi/settings.py
@@ -66,14 +66,12 @@
     'oauth',
     'timetable',
     'common',
-    'opbeat.contrib.django',
     'raven.contrib.django.raven_compat',
     'corsheaders',
     'workspaces'
 ]
 
 MIDDLEWARE = [
-    'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'corsheaders.middleware.CorsMiddleware',
@@ -143,13 +141,6 @@
 
 DATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']
 
-# analytics
-OPBEAT = {
-    'ORGANIZATION_ID': os.environ.get("OPBEAT_ORG_ID"),
-    'APP_ID': os.environ.get("OPBEAT_APP_ID"),
-    'SECRET_TOKEN': os.environ.get("OPBEAT_SECRET_TOKEN")
-}
-
 RAVEN_CONFIG = {
     'dsn': os.environ.get("SENTRY_DSN"),
 }

{"golden_diff": "diff --git a/backend/uclapi/uclapi/celery.py b/backend/uclapi/uclapi/celery.py\n--- a/backend/uclapi/uclapi/celery.py\n+++ b/backend/uclapi/uclapi/celery.py\n@@ -27,23 +27,6 @@\n \n app.config_from_object('django.conf.settings', namespace='CELERY')\n \n-\n-from opbeat.contrib.django.models import \\\n-    register_handlers as opbeat_register_handlers, \\\n-    logger as opbeat_logger  # noqa: E402#\n-\n-from opbeat.contrib.celery import \\\n-    register_signal as opbeat_register_signal  # noqa: E402\n-\n-\n-try:\n-    opbeat_register_signal(app)\n-except Exception as e:\n-    opbeat_logger.exception('Failed installing celery hook: %s' % e)\n-\n-if 'opbeat.contrib.django' in settings.INSTALLED_APPS:\n-    opbeat_register_handlers()\n-\n app.autodiscover_tasks()\n \n \ndiff --git a/backend/uclapi/uclapi/settings.py b/backend/uclapi/uclapi/settings.py\n--- a/backend/uclapi/uclapi/settings.py\n+++ b/backend/uclapi/uclapi/settings.py\n@@ -66,14 +66,12 @@\n     'oauth',\n     'timetable',\n     'common',\n-    'opbeat.contrib.django',\n     'raven.contrib.django.raven_compat',\n     'corsheaders',\n     'workspaces'\n ]\n \n MIDDLEWARE = [\n-    'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',\n     'django.middleware.security.SecurityMiddleware',\n     'django.contrib.sessions.middleware.SessionMiddleware',\n     'corsheaders.middleware.CorsMiddleware',\n@@ -143,13 +141,6 @@\n \n DATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']\n \n-# analytics\n-OPBEAT = {\n-    'ORGANIZATION_ID': os.environ.get(\"OPBEAT_ORG_ID\"),\n-    'APP_ID': os.environ.get(\"OPBEAT_APP_ID\"),\n-    'SECRET_TOKEN': os.environ.get(\"OPBEAT_SECRET_TOKEN\")\n-}\n-\n RAVEN_CONFIG = {\n     'dsn': os.environ.get(\"SENTRY_DSN\"),\n }\n", "issue": "Remove opbeat\nOpbeat is no longer a thing, so we should remove it and replace it with something else? Maybe double down on Sentry and integrate that more tightly\r\n\r\nhttps://github.com/uclapi/uclapi/blob/81b90305f9316b020664b32c2436e27ab957e8a7/backend/uclapi/requirements.txt#L33\n", "before_files": [{"content": "from __future__ import absolute_import, unicode_literals\n\nimport celery\nimport os\nimport raven\n\nfrom django.conf import settings\nfrom raven.contrib.celery import register_signal as raven_register_signal, \\\n    register_logger_signal as raven_register_logger_signal\n\nfrom common.helpers import read_dotenv\n\nread_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uclapi.settings')\n\n\nclass Celery(celery.Celery):\n    def on_configure(self):\n        if os.environ.get(\"SENTRY_DSN\") is not None:\n            client = raven.Client(os.environ.get(\"SENTRY_DSN\"))\n            raven_register_logger_signal(client)\n            raven_register_signal(client)\n\n\napp = Celery('uclapi')\n\napp.config_from_object('django.conf.settings', namespace='CELERY')\n\n\nfrom opbeat.contrib.django.models import \\\n    register_handlers as opbeat_register_handlers, \\\n    logger as opbeat_logger  # noqa: E402#\n\nfrom opbeat.contrib.celery import \\\n    register_signal as opbeat_register_signal  # noqa: E402\n\n\ntry:\n    opbeat_register_signal(app)\nexcept Exception as e:\n    opbeat_logger.exception('Failed installing celery hook: %s' % e)\n\nif 'opbeat.contrib.django' in settings.INSTALLED_APPS:\n    opbeat_register_handlers()\n\napp.autodiscover_tasks()\n\n\n@app.task(bind=True)\ndef task(self):\n    print('Request: {0!r}'.format(self.request))\n", "path": "backend/uclapi/uclapi/celery.py"}, {"content": "\"\"\"\nDjango settings for uclapi project.\n\nGenerated by 'django-admin startproject' using Django 1.10.4.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/1.10/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/1.10/ref/settings/\n\"\"\"\n\nimport os\nimport requests\nfrom distutils.util import strtobool\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = os.environ.get(\"SECRET_KEY\")\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# This value should be set by the UCLAPI_PRODUCTION environment\n# variable anyway. If in production, debug should be false.\nDEBUG = not strtobool(os.environ.get(\"UCLAPI_PRODUCTION\"))\n\nALLOWED_HOSTS = [\"localhost\"]\n\n# If a domain is specified then make this an allowed host\nif os.environ.get(\"UCLAPI_DOMAIN\"):\n    ALLOWED_HOSTS.append(os.environ.get(\"UCLAPI_DOMAIN\"))\n\n# If we are running under the AWS Elastic Load Balancer then enable internal\n# requests so that the ELB and Health Checks work\nif strtobool(os.environ.get(\"UCLAPI_RUNNING_ON_AWS_ELB\")):\n    EC2_PRIVATE_IP = None\n    try:\n        EC2_PRIVATE_IP = requests.get(\n            \"http://169.254.169.254/latest/meta-data/local-ipv4\",\n            timeout=0.01\n        ).text\n    except requests.exceptions.RequestException:\n        pass\n\n    if EC2_PRIVATE_IP:\n        ALLOWED_HOSTS.append(EC2_PRIVATE_IP)\n\n# Application definition\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'rest_framework',\n    'dashboard',\n    'marketplace',\n    'roombookings',\n    'oauth',\n    'timetable',\n    'common',\n    'opbeat.contrib.django',\n    'raven.contrib.django.raven_compat',\n    'corsheaders',\n    'workspaces'\n]\n\nMIDDLEWARE = [\n    'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nif DEBUG:\n    MIDDLEWARE.append(\n        'dashboard.middleware.fake_shibboleth_middleware'\n        '.FakeShibbolethMiddleWare'\n    )\n\nROOT_URLCONF = 'uclapi.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'uclapi.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/1.10/ref/settings/#databases\n\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': os.environ.get(\"DB_UCLAPI_NAME\"),\n        'USER': os.environ.get(\"DB_UCLAPI_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_UCLAPI_PASSWORD\"),\n        'HOST': os.environ.get(\"DB_UCLAPI_HOST\"),\n        'PORT': os.environ.get(\"DB_UCLAPI_PORT\")\n    },\n    'roombookings': {\n        'ENGINE': 'django.db.backends.oracle',\n        'NAME': os.environ.get(\"DB_ROOMS_NAME\"),\n        'USER': os.environ.get(\"DB_ROOMS_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_ROOMS_PASSWORD\"),\n        'HOST': '',\n        'PORT': ''\n    },\n    'gencache': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': os.environ.get(\"DB_CACHE_NAME\"),\n        'USER': os.environ.get(\"DB_CACHE_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_CACHE_PASSWORD\"),\n        'HOST': os.environ.get(\"DB_CACHE_HOST\"),\n        'PORT': os.environ.get(\"DB_CACHE_PORT\")\n    }\n}\n\nDATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']\n\n# analytics\nOPBEAT = {\n    'ORGANIZATION_ID': os.environ.get(\"OPBEAT_ORG_ID\"),\n    'APP_ID': os.environ.get(\"OPBEAT_APP_ID\"),\n    'SECRET_TOKEN': os.environ.get(\"OPBEAT_SECRET_TOKEN\")\n}\n\nRAVEN_CONFIG = {\n    'dsn': os.environ.get(\"SENTRY_DSN\"),\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa\n    },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/1.10/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'UTC'\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = False\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/1.10/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static')\n\n# Cross Origin settings\nCORS_ORIGIN_ALLOW_ALL = True\nCORS_URLS_REGEX = r'^/roombookings/.*$'\n\n# Fair use policy\nfair_use_policy_path = os.path.join(\n    BASE_DIR,\n    'uclapi/UCLAPIAcceptableUsePolicy.txt'\n)\nwith open(fair_use_policy_path, 'r', encoding='utf-8') as fp:\n    FAIR_USE_POLICY = list(fp)\n\nREDIS_UCLAPI_HOST = os.environ[\"REDIS_UCLAPI_HOST\"]\n\n# Celery Settings\nCELERY_BROKER_URL = 'redis://' + REDIS_UCLAPI_HOST\nCELERY_ACCEPT_CONTENT = ['json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\n\n\nROOMBOOKINGS_SETID = 'LIVE-17-18'\n\n# S3 file storage settings\n# There are three scenarios to consider:\n# 1) Local development\n#    In local dev,  AWS_S3_STATICS = False\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False\n#    These allow you to use local statics using /static/ in the\n#    same way as you would normally.\n# 2) Production\n#    In prod,       AWS_S3_STATICS = True\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False\n#    This means that S3 statics will be used, but no creds are\n#    needed on the boxes because web servers should never do\n#    uploads to the remote S3 bucket.\n# 3) Deployment\n#    In deployment, AWS_S3_STATICS = True\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = True\n#    This will be done either from CI/CD or from the computer\n#    of a person who has permission to upload new statics to\n#    S3.\n\nif strtobool(os.environ.get(\"AWS_S3_STATICS\", \"False\")):\n    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'\n    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'\n    AWS_STORAGE_BUCKET_NAME = os.environ[\"AWS_S3_BUCKET_NAME\"]\n    AWS_LOCATION = os.environ[\"AWS_S3_BUCKET_PATH\"]\n    AWS_S3_REGION_NAME = os.environ[\"AWS_S3_REGION\"]\n\n    # This is a hack to not require AWS Access Credentials\n    # when the system is running in the Cloud. This avoids us from\n    # needing to store AWS credentials.\n    # https://github.com/jschneier/django-storages/issues/254#issuecomment-329813295  # noqa\n    AWS_S3_CUSTOM_DOMAIN = \"{}.s3.amazonaws.com\".format(\n        AWS_STORAGE_BUCKET_NAME\n    )\n\n    # If credentials are enabled, collectstatic can do uploads\n    if strtobool(os.environ[\"AWS_S3_STATICS_CREDENTIALS_ENABLED\"]):\n        AWS_ACCESS_KEY_ID = os.environ[\"AWS_ACCESS_KEY_ID\"]\n        AWS_SECRET_ACCESS_KEY = os.environ[\"AWS_ACCESS_SECRET\"]\n        AWS_S3_OBJECT_PARAMETERS = {\n            'CacheControl': 'max-age=86400',\n        }\n        AWS_S3_ENCRYPTION = False\n    else:\n        AWS_QUERYSTRING_AUTH = False\n", "path": "backend/uclapi/uclapi/settings.py"}], "after_files": [{"content": "from __future__ import absolute_import, unicode_literals\n\nimport celery\nimport os\nimport raven\n\nfrom django.conf import settings\nfrom raven.contrib.celery import register_signal as raven_register_signal, \\\n    register_logger_signal as raven_register_logger_signal\n\nfrom common.helpers import read_dotenv\n\nread_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'uclapi.settings')\n\n\nclass Celery(celery.Celery):\n    def on_configure(self):\n        if os.environ.get(\"SENTRY_DSN\") is not None:\n            client = raven.Client(os.environ.get(\"SENTRY_DSN\"))\n            raven_register_logger_signal(client)\n            raven_register_signal(client)\n\n\napp = Celery('uclapi')\n\napp.config_from_object('django.conf.settings', namespace='CELERY')\n\napp.autodiscover_tasks()\n\n\n@app.task(bind=True)\ndef task(self):\n    print('Request: {0!r}'.format(self.request))\n", "path": "backend/uclapi/uclapi/celery.py"}, {"content": "\"\"\"\nDjango settings for uclapi project.\n\nGenerated by 'django-admin startproject' using Django 1.10.4.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/1.10/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/1.10/ref/settings/\n\"\"\"\n\nimport os\nimport requests\nfrom distutils.util import strtobool\n\n# Build paths inside the project like this: os.path.join(BASE_DIR, ...)\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = os.environ.get(\"SECRET_KEY\")\n\n# SECURITY WARNING: don't run with debug turned on in production!\n# This value should be set by the UCLAPI_PRODUCTION environment\n# variable anyway. If in production, debug should be false.\nDEBUG = not strtobool(os.environ.get(\"UCLAPI_PRODUCTION\"))\n\nALLOWED_HOSTS = [\"localhost\"]\n\n# If a domain is specified then make this an allowed host\nif os.environ.get(\"UCLAPI_DOMAIN\"):\n    ALLOWED_HOSTS.append(os.environ.get(\"UCLAPI_DOMAIN\"))\n\n# If we are running under the AWS Elastic Load Balancer then enable internal\n# requests so that the ELB and Health Checks work\nif strtobool(os.environ.get(\"UCLAPI_RUNNING_ON_AWS_ELB\")):\n    EC2_PRIVATE_IP = None\n    try:\n        EC2_PRIVATE_IP = requests.get(\n            \"http://169.254.169.254/latest/meta-data/local-ipv4\",\n            timeout=0.01\n        ).text\n    except requests.exceptions.RequestException:\n        pass\n\n    if EC2_PRIVATE_IP:\n        ALLOWED_HOSTS.append(EC2_PRIVATE_IP)\n\n# Application definition\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'rest_framework',\n    'dashboard',\n    'marketplace',\n    'roombookings',\n    'oauth',\n    'timetable',\n    'common',\n    'raven.contrib.django.raven_compat',\n    'corsheaders',\n    'workspaces'\n]\n\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'corsheaders.middleware.CorsMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nif DEBUG:\n    MIDDLEWARE.append(\n        'dashboard.middleware.fake_shibboleth_middleware'\n        '.FakeShibbolethMiddleWare'\n    )\n\nROOT_URLCONF = 'uclapi.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'uclapi.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/1.10/ref/settings/#databases\n\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': os.environ.get(\"DB_UCLAPI_NAME\"),\n        'USER': os.environ.get(\"DB_UCLAPI_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_UCLAPI_PASSWORD\"),\n        'HOST': os.environ.get(\"DB_UCLAPI_HOST\"),\n        'PORT': os.environ.get(\"DB_UCLAPI_PORT\")\n    },\n    'roombookings': {\n        'ENGINE': 'django.db.backends.oracle',\n        'NAME': os.environ.get(\"DB_ROOMS_NAME\"),\n        'USER': os.environ.get(\"DB_ROOMS_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_ROOMS_PASSWORD\"),\n        'HOST': '',\n        'PORT': ''\n    },\n    'gencache': {\n        'ENGINE': 'django.db.backends.postgresql',\n        'NAME': os.environ.get(\"DB_CACHE_NAME\"),\n        'USER': os.environ.get(\"DB_CACHE_USERNAME\"),\n        'PASSWORD': os.environ.get(\"DB_CACHE_PASSWORD\"),\n        'HOST': os.environ.get(\"DB_CACHE_HOST\"),\n        'PORT': os.environ.get(\"DB_CACHE_PORT\")\n    }\n}\n\nDATABASE_ROUTERS = ['uclapi.dbrouters.ModelRouter']\n\nRAVEN_CONFIG = {\n    'dsn': os.environ.get(\"SENTRY_DSN\"),\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',  # noqa\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',  # noqa\n    },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/1.10/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'UTC'\n\nUSE_I18N = True\n\nUSE_L10N = True\n\nUSE_TZ = False\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/1.10/howto/static-files/\n\nSTATIC_URL = '/static/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static')\n\n# Cross Origin settings\nCORS_ORIGIN_ALLOW_ALL = True\nCORS_URLS_REGEX = r'^/roombookings/.*$'\n\n# Fair use policy\nfair_use_policy_path = os.path.join(\n    BASE_DIR,\n    'uclapi/UCLAPIAcceptableUsePolicy.txt'\n)\nwith open(fair_use_policy_path, 'r', encoding='utf-8') as fp:\n    FAIR_USE_POLICY = list(fp)\n\nREDIS_UCLAPI_HOST = os.environ[\"REDIS_UCLAPI_HOST\"]\n\n# Celery Settings\nCELERY_BROKER_URL = 'redis://' + REDIS_UCLAPI_HOST\nCELERY_ACCEPT_CONTENT = ['json']\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_RESULT_SERIALIZER = 'json'\n\n\nROOMBOOKINGS_SETID = 'LIVE-17-18'\n\n# S3 file storage settings\n# There are three scenarios to consider:\n# 1) Local development\n#    In local dev,  AWS_S3_STATICS = False\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False\n#    These allow you to use local statics using /static/ in the\n#    same way as you would normally.\n# 2) Production\n#    In prod,       AWS_S3_STATICS = True\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = False\n#    This means that S3 statics will be used, but no creds are\n#    needed on the boxes because web servers should never do\n#    uploads to the remote S3 bucket.\n# 3) Deployment\n#    In deployment, AWS_S3_STATICS = True\n#                   AWS_S3_STATICS_CREDENTIALS_ENABLED = True\n#    This will be done either from CI/CD or from the computer\n#    of a person who has permission to upload new statics to\n#    S3.\n\nif strtobool(os.environ.get(\"AWS_S3_STATICS\", \"False\")):\n    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'\n    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'\n    AWS_STORAGE_BUCKET_NAME = os.environ[\"AWS_S3_BUCKET_NAME\"]\n    AWS_LOCATION = os.environ[\"AWS_S3_BUCKET_PATH\"]\n    AWS_S3_REGION_NAME = os.environ[\"AWS_S3_REGION\"]\n\n    # This is a hack to not require AWS Access Credentials\n    # when the system is running in the Cloud. This avoids us from\n    # needing to store AWS credentials.\n    # https://github.com/jschneier/django-storages/issues/254#issuecomment-329813295  # noqa\n    AWS_S3_CUSTOM_DOMAIN = \"{}.s3.amazonaws.com\".format(\n        AWS_STORAGE_BUCKET_NAME\n    )\n\n    # If credentials are enabled, collectstatic can do uploads\n    if strtobool(os.environ[\"AWS_S3_STATICS_CREDENTIALS_ENABLED\"]):\n        AWS_ACCESS_KEY_ID = os.environ[\"AWS_ACCESS_KEY_ID\"]\n        AWS_SECRET_ACCESS_KEY = os.environ[\"AWS_ACCESS_SECRET\"]\n        AWS_S3_OBJECT_PARAMETERS = {\n            'CacheControl': 'max-age=86400',\n        }\n        AWS_S3_ENCRYPTION = False\n    else:\n        AWS_QUERYSTRING_AUTH = False\n", "path": "backend/uclapi/uclapi/settings.py"}]}