Add library for dashboard API
[pharos.git] / tools / pharos-dashboard / src / pharos_dashboard / settings.py
1 import os
2 from datetime import timedelta
3
4 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
5 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
6
7 # SECURITY WARNING: don't run with debug turned on in production!
8 DEBUG = False
9
10 # Application definition
11
12 INSTALLED_APPS = [
13     'dashboard',
14     'booking',
15     'account',
16     'jenkins',
17     'notification',
18     'django.contrib.admin',
19     'django.contrib.auth',
20     'django.contrib.contenttypes',
21     'django.contrib.sessions',
22     'django.contrib.messages',
23     'django.contrib.staticfiles',
24     'django.contrib.humanize',
25     'bootstrap3',
26     'crispy_forms',
27     'rest_framework',
28     'rest_framework.authtoken',
29 ]
30
31 MIDDLEWARE = [
32     'django.middleware.security.SecurityMiddleware',
33     'django.contrib.sessions.middleware.SessionMiddleware',
34     'django.middleware.common.CommonMiddleware',
35     'django.middleware.csrf.CsrfViewMiddleware',
36     'django.contrib.auth.middleware.AuthenticationMiddleware',
37     'django.contrib.messages.middleware.MessageMiddleware',
38     'django.middleware.clickjacking.XFrameOptionsMiddleware',
39     'account.middleware.TimezoneMiddleware',
40 ]
41
42 ROOT_URLCONF = 'pharos_dashboard.urls'
43
44 TEMPLATES = [
45     {
46         'BACKEND': 'django.template.backends.django.DjangoTemplates',
47         'DIRS': [os.path.join(BASE_DIR, 'templates')]
48         ,
49         'APP_DIRS': True,
50         'OPTIONS': {
51             'context_processors': [
52                 'django.template.context_processors.debug',
53                 'django.template.context_processors.request',
54                 'django.contrib.auth.context_processors.auth',
55                 'django.contrib.messages.context_processors.messages',
56             ],
57         },
58     },
59 ]
60
61 WSGI_APPLICATION = 'pharos_dashboard.wsgi.application'
62
63 # Password validation
64 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
65
66 AUTH_PASSWORD_VALIDATORS = [
67     {
68         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
69     },
70     {
71         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
72     },
73     {
74         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
75     },
76     {
77         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
78     },
79 ]
80
81 # Internationalization
82 # https://docs.djangoproject.com/en/1.10/topics/i18n/
83
84 LANGUAGE_CODE = 'en-us'
85
86 TIME_ZONE = 'UTC'
87
88 USE_I18N = True
89
90 USE_L10N = True
91
92 USE_TZ = True
93
94 # Static files (CSS, JavaScript, Images)
95 # https://docs.djangoproject.com/en/1.10/howto/static-files/
96 MEDIA_URL = '/media/'
97 STATIC_URL = '/static/'
98
99 # Static files (CSS, JavaScript, Images)
100 # https://docs.djangoproject.com/en/1.10/howto/static-files/
101 STATICFILES_DIRS = [
102     os.path.join(BASE_DIR, "static"),
103 ]
104
105 LOGIN_REDIRECT_URL = '/'
106
107 # SECURITY WARNING: keep the secret key used in production secret!
108 SECRET_KEY = os.environ['SECRET_KEY']
109
110 BOOTSTRAP3 = {
111     'set_placeholder': False,
112 }
113
114 ALLOWED_HOSTS = ['*']
115
116 # Database
117 # https://docs.djangoproject.com/en/1.10/ref/settings/#databases
118 DATABASES = {
119     'default': {
120         'ENGINE': 'django.db.backends.postgresql',
121         'NAME': os.environ['DB_NAME'],
122         'USER': os.environ['DB_USER'],
123         'PASSWORD': os.environ['DB_PASS'],
124         'HOST': os.environ['DB_SERVICE'],
125         'PORT': os.environ['DB_PORT']
126     }
127 }
128
129
130 # Rest API Settings
131 REST_FRAMEWORK = {
132     'DEFAULT_PERMISSION_CLASSES': [
133         'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
134     ],
135     'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',),
136     'DEFAULT_AUTHENTICATION_CLASSES': (
137         'rest_framework.authentication.SessionAuthentication',
138         'rest_framework.authentication.TokenAuthentication',
139     )
140 }
141
142 MEDIA_ROOT = '/media'
143 STATIC_ROOT = '/static'
144
145 # Jira Settings
146 CREATE_JIRA_TICKET = False
147
148 JIRA_URL = os.environ['JIRA_URL']
149
150 JIRA_USER_NAME = os.environ['JIRA_USER_NAME']
151 JIRA_USER_PASSWORD = os.environ['JIRA_USER_PASSWORD']
152
153 OAUTH_CONSUMER_KEY = os.environ['OAUTH_CONSUMER_KEY']
154 OAUTH_CONSUMER_SECRET = os.environ['OAUTH_CONSUMER_SECRET']
155
156 OAUTH_REQUEST_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/request-token'
157 OAUTH_ACCESS_TOKEN_URL = JIRA_URL + '/plugins/servlet/oauth/access-token'
158 OAUTH_AUTHORIZE_URL = JIRA_URL + '/plugins/servlet/oauth/authorize'
159
160 OAUTH_CALLBACK_URL = JIRA_URL + '/accounts/authenticated'
161
162 # Celery Settings
163 CELERY_TIMEZONE = 'UTC'
164
165 RABBITMQ_URL = 'rabbitmq'
166 BROKER_URL = 'amqp://guest:guest@rabbitmq:5672//'
167
168 CELERYBEAT_SCHEDULE = {
169     'sync-jenkins': {
170         'task': 'jenkins.tasks.sync_jenkins',
171         'schedule': timedelta(minutes=5)
172     },
173     'send-booking-notifications': {
174         'task': 'notification.tasks.send_booking_notifications',
175         'schedule': timedelta(minutes=5)
176     },
177     'clean-database': {
178         'task': 'dashboard.tasks.database_cleanup',
179         'schedule': timedelta(hours=24)
180     },
181 }