Lab as a Service 2.0
[laas.git] / src / pharos_dashboard / settings.py
1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import os
10 from datetime import timedelta
11
12 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
13 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
14
15 # SECURITY WARNING: don't run with debug turned on in production!
16 # NOTE: os.environ only returns strings, so making a comparison to
17 # 'True' here will convert it to the correct Boolean value.
18 DEBUG = os.environ['DEBUG'] == 'True'
19 TESTING = os.environ['TEST'] == 'True'
20
21 # Application definition
22
23 INSTALLED_APPS = [
24     'dashboard',
25     'resource_inventory',
26     'booking',
27     'account',
28     'notifier',
29     'workflow',
30     'api',
31     'django.contrib.admin',
32     'django.contrib.auth',
33     'django.contrib.contenttypes',
34     'django.contrib.sessions',
35     'django.contrib.messages',
36     'django.contrib.staticfiles',
37     'django.contrib.humanize',
38     'bootstrap3',
39     'crispy_forms',
40     'rest_framework',
41     'rest_framework.authtoken',
42 ]
43
44 MIDDLEWARE = [
45     'django.middleware.security.SecurityMiddleware',
46     'django.contrib.sessions.middleware.SessionMiddleware',
47     'django.middleware.common.CommonMiddleware',
48     'django.middleware.csrf.CsrfViewMiddleware',
49     'django.contrib.auth.middleware.AuthenticationMiddleware',
50     'django.contrib.messages.middleware.MessageMiddleware',
51     'django.middleware.clickjacking.XFrameOptionsMiddleware',
52     'account.middleware.TimezoneMiddleware',
53 ]
54
55 ROOT_URLCONF = 'pharos_dashboard.urls'
56
57 TEMPLATES = [
58     {
59         'BACKEND': 'django.template.backends.django.DjangoTemplates',
60         'DIRS': [os.path.join(BASE_DIR, 'templates')]
61         ,
62         'APP_DIRS': True,
63         'OPTIONS': {
64             'context_processors': [
65                 'dashboard.context_processors.debug',
66                 'django.template.context_processors.debug',
67                 'django.template.context_processors.request',
68                 'django.contrib.auth.context_processors.auth',
69                 'django.contrib.messages.context_processors.messages',
70             ],
71         },
72     },
73 ]
74
75 TEMPLATE_CONTEXT_PROCESSORS = [
76     'dashboard.context_processors.debug',
77 ]
78
79 WSGI_APPLICATION = 'pharos_dashboard.wsgi.application'
80
81 # Password validation
82 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
83
84 AUTH_PASSWORD_VALIDATORS = [
85     {
86         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
87     },
88     {
89         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
90     },
91     {
92         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
93     },
94     {
95         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
96     },
97 ]
98
99 # Internationalization
100 # https://docs.djangoproject.com/en/1.10/topics/i18n/
101
102 LANGUAGE_CODE = 'en-us'
103
104 TIME_ZONE = 'UTC'
105
106 USE_I18N = True
107
108 USE_L10N = True
109
110 USE_TZ = True
111
112 # Static files (CSS, JavaScript, Images)
113 # https://docs.djangoproject.com/en/1.10/howto/static-files/
114 MEDIA_URL = '/media/'
115 STATIC_URL = '/static/'
116
117 # Static files (CSS, JavaScript, Images)
118 # https://docs.djangoproject.com/en/1.10/howto/static-files/
119 STATICFILES_DIRS = [
120     os.path.join(BASE_DIR, "static"),
121 ]
122
123 LOGIN_REDIRECT_URL = '/'
124
125 # SECURITY WARNING: keep the secret key used in production secret!
126 SECRET_KEY = os.environ['SECRET_KEY']
127
128 BOOTSTRAP3 = {
129     'set_placeholder': False,
130 }
131
132 ALLOWED_HOSTS = ['*']
133
134 # Database
135 # https://docs.djangoproject.com/en/1.10/ref/settings/#databases
136 DATABASES = {
137     'default': {
138         'ENGINE': 'django.db.backends.postgresql',
139         'NAME': os.environ['DB_NAME'],
140         'USER': os.environ['DB_USER'],
141         'PASSWORD': os.environ['DB_PASS'],
142         'HOST': os.environ['DB_SERVICE'],
143         'PORT': os.environ['DB_PORT']
144     }
145 }
146
147 # Rest API Settings
148 REST_FRAMEWORK = {
149     'DEFAULT_PERMISSION_CLASSES': [
150         'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
151     ],
152     'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.FilterSet',),
153     'DEFAULT_AUTHENTICATION_CLASSES': (
154         'rest_framework.authentication.SessionAuthentication',
155         'rest_framework.authentication.TokenAuthentication',
156     )
157 }
158
159 MEDIA_ROOT = '/media'
160 STATIC_ROOT = '/static'
161
162 # Jira Settings
163 CREATE_JIRA_TICKET = False
164
165 JIRA_URL = os.environ['JIRA_URL']
166
167 JIRA_USER_NAME = os.environ['JIRA_USER_NAME']
168 JIRA_USER_PASSWORD = os.environ['JIRA_USER_PASSWORD']
169
170 OAUTH_CONSUMER_KEY = os.environ['OAUTH_CONSUMER_KEY']
171 OAUTH_CONSUMER_SECRET = os.environ['OAUTH_CONSUMER_SECRET']
172
173 OAUTH_REQUEST_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/request-token'
174 OAUTH_ACCESS_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/access-token'
175 OAUTH_AUTHORIZE_URL = JIRA_URL + '/plugins/servlet/oauth/authorize'
176
177 OAUTH_CALLBACK_URL = os.environ['DASHBOARD_URL'] + '/accounts/authenticated'
178
179 # Celery Settings
180 CELERY_TIMEZONE = 'UTC'
181
182 RABBITMQ_URL = 'rabbitmq'
183 RABBITMQ_DEFAULT_USER = os.environ['RABBITMQ_DEFAULT_USER']
184 RABBITMQ_DEFAULT_PASS = os.environ['RABBITMQ_DEFAULT_PASS']
185
186 BROKER_URL = 'amqp://' + RABBITMQ_DEFAULT_USER + ':' + RABBITMQ_DEFAULT_PASS + '@rabbitmq:5672//'
187
188 CELERYBEAT_SCHEDULE = {
189     'booking_poll': {
190         'task': 'dashboard.tasks.booking_poll',
191         'schedule': timedelta(minutes=1)
192     },
193     'free_hosts': {
194         'task': 'dashboard.tasks.free_hosts',
195         'schedule': timedelta(minutes=1)
196     },
197     'conjure_notifiers': {
198     'task': 'dashboard.tasks.conjure_aggregate_notifiers',
199     'schedule': timedelta(seconds=30)
200     },
201 }
202
203 # Notifier Settings
204 EMAIL_HOST = os.environ['EMAIL_HOST']
205 EMAIL_PORT = os.environ['EMAIL_PORT']
206 EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
207 EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
208 EMAIL_USE_TLS=True
209 DEFAULT_EMAIL_FROM = os.environ.get('DEFAULT_EMAIL_FROM', 'webmaster@localhost')
210 SESSION_ENGINE="django.contrib.sessions.backends.signed_cookies"