vvp -- VNF Validation Platform
[oom.git] / kubernetes / vvp / charts / vvp-ci-uwsgi / resources / config / ci / __init__.py
1 # Copyright © 2018 Amdocs, AT&T, Bell Canada
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import os
16 from datetime import datetime
17
18 # With this file at web/settings/__init__.py, we need three applications of
19 # dirname() to find the project root.
20 PROJECT_PATH = os.path.realpath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
21 LOGS_PATH    = os.path.join(PROJECT_PATH, "logs")
22
23 ICE_ENVIRONMENT = os.environ['ICE_ENVIRONMENT']
24 PROGRAM_NAME_URL_PREFIX = os.environ['PROGRAM_NAME_URL_PREFIX']
25 SERVICE_PROVIDER = os.environ['SERVICE_PROVIDER']
26 PROGRAM_NAME = os.environ['PROGRAM_NAME']
27 SERVICE_PROVIDER_DOMAIN = os.environ['SERVICE_PROVIDER_DOMAIN']
28
29 # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
30 SECRET_KEY = os.environ["SECRET_KEY"]
31
32 # https://docs.djangoproject.com/en/1.10/ref/settings/#allowed-hosts
33 # Anything in the Host header that does not match our expected domain should
34 # raise SuspiciousOperation exception.
35 ALLOWED_HOSTS = ['*']
36
37 if ICE_ENVIRONMENT == 'production':
38     DEBUG = False
39
40     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
41     EMAIL_HOST = os.environ.get('ICE_EMAIL_HOST')
42     EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']
43     EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
44     EMAIL_PORT = os.environ['EMAIL_PORT']
45 else:
46     DEBUG = True
47     EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
48
49
50 # Note: Only SSL email backends are allowed
51 EMAIL_USE_SSL = True
52
53 REST_FRAMEWORK = {
54     'DEFAULT_AUTHENTICATION_CLASSES': (
55         'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
56     ),
57     'PAGE_SIZE': 10,
58     # Use Django's standard `django.contrib.auth` permissions,
59     # or allow read-only access for unauthenticated users.
60     'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
61 }
62 APPEND_SLASH = False
63
64 # Application definition
65
66 INSTALLED_APPS = [
67
68     'django.contrib.auth',
69     'django.contrib.contenttypes',  # required by d.c.admin
70     'django.contrib.sessions',      # required by d.c.admin
71     'django.contrib.messages',      # required by d.c.admin
72     'django.contrib.staticfiles',
73     'django.contrib.admin',         # django admin site
74     'rest_framework',
75     'iceci.apps.IceCiConfig',
76 ]
77
78 MIDDLEWARE_CLASSES = [
79     'django.middleware.security.SecurityMiddleware',
80     'django.contrib.sessions.middleware.SessionMiddleware',
81     'django.middleware.common.CommonMiddleware',
82     'django.middleware.csrf.CsrfViewMiddleware',
83     'django.contrib.auth.middleware.AuthenticationMiddleware',
84     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
85     'django.contrib.messages.middleware.MessageMiddleware',
86     'django.middleware.clickjacking.XFrameOptionsMiddleware',
87 ]
88
89 ROOT_URLCONF = 'web.urls'
90
91 TEMPLATES = [
92     {
93         'BACKEND': 'django.template.backends.django.DjangoTemplates',
94         'DIRS': [PROJECT_PATH + '/web/templates'],
95         'APP_DIRS': True,
96         'OPTIONS': {
97             'context_processors': [
98                 'django.template.context_processors.debug',
99                 'django.template.context_processors.request',
100                 'django.contrib.auth.context_processors.auth',          # required by d.c.admin
101                 'django.contrib.messages.context_processors.messages',  # required by d.c.admin
102             ],
103         },
104     },
105 ]
106
107 WSGI_APPLICATION = 'web.wsgi.application'
108
109 # Database
110 # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
111
112 DATABASES = {
113     'default': { # CI DB details.
114         'NAME': '/app/ice_ci_db.db' ,
115         'ENGINE': 'django.db.backends.sqlite3',
116         'TEST_NAME': '/app/ice_ci_db.db',
117     },
118 }
119 SINGLETONE_DB = {
120     'default': { # CI DB details.
121         'ENGINE': 'django.db.backends.postgresql',
122         'NAME': os.environ.get('CI_DB_NAME', 'ice_ci_db'),
123         'USER': os.environ.get('CI_DB_USER', 'iceci'),
124         'PASSWORD': os.environ.get('CI_DB_PASSWORD', 'Aa123456'),
125         'HOST': os.environ.get('CI_DB_HOST', 'localhost'),
126         'PORT': os.environ.get('CI_DB_PORT', '5433'),
127     },
128     'em_db': { # ICE DB details.
129         'ENGINE': 'django.db.backends.postgresql',
130         'NAME': os.environ.get('EM_DB_NAME', 'icedb'),
131         'USER': os.environ.get('EM_DB_USER', 'iceuser'),
132         'PASSWORD': os.environ.get('EM_DB_PASSWORD', 'Aa123456'),
133         'HOST': os.environ.get('EM_DB_HOST', 'localhost'),
134         'PORT': os.environ.get('EM_DB_PORT', '5433'),
135     },
136     'cms_db': { # ICE CMS details.
137         'ENGINE': 'django.db.backends.postgresql',
138         'NAME': os.environ.get('CMS_DB_NAME', 'icecmsdb'),
139         'USER': os.environ.get('CMS_DB_USER', 'icecmsuser'),
140         'PASSWORD': os.environ.get('CMS_DB_PASSWORD', 'Aa123456'),
141         'HOST': os.environ.get('CMS_DB_HOST', 'localhost'),
142         'PORT': os.environ.get('CMS_DB_PORT', '5433'),
143     }
144 }
145
146 # Password validation
147 # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
148
149 AUTH_PASSWORD_VALIDATORS = [
150     {
151         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
152     },
153     {
154         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
155     },
156     {
157         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
158     },
159     {
160         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
161     },
162 ]
163
164
165 # Internationalization
166 # https://docs.djangoproject.com/en/1.9/topics/i18n/
167
168 LANGUAGE_CODE = 'en-us'
169
170 TIME_ZONE = 'UTC'
171
172 USE_I18N = True
173
174 USE_L10N = True
175
176 USE_TZ = False
177
178
179 # Static files (CSS, JavaScript, Images)
180 # https://docs.djangoproject.com/en/1.9/howto/static-files/
181 STATIC_ROOT = os.environ['STATIC_ROOT']
182 STATIC_URL = '/static/'
183
184 LOGGING = {
185     'version': 1,
186     'disable_existing_loggers': False,
187     'formatters': {  # All possible attributes are: https://docs.python.org/3/library/logging.html#logrecord-attributes
188         'verbose': {
189             'format': '%(asctime)s %(levelname)s %(module)s %(filename)s:%(lineno)d %(process)d %(thread)d %(message)s'
190         },
191         'simple': {
192             'format': '%(asctime)s %(levelname)s %(filename)s:%(lineno)d  %(message)s'
193         },
194     },
195     'handlers': {
196         'console': {
197             'class': 'logging.StreamHandler',
198             'formatter': 'simple'
199         },
200         'file1': {
201             'level': 'INFO',  # handler will ignore DEBUG (only process INFO, WARN, ERROR, CRITICAL, FATAL)
202             'class': 'logging.FileHandler',
203             'filename': os.environ.get('ICE_ICE_LOGGER_PATH', LOGS_PATH) + 'vvp-info.log',
204             'formatter': 'verbose'
205         },
206         'file2': {
207             'level': 'DEBUG',
208             'class': 'logging.FileHandler',
209             'filename': os.environ.get('ICE_ICE_LOGGER_PATH', LOGS_PATH) + 'vvp-debug.log',
210             'formatter': 'verbose'
211         },
212         'file3': {
213             'level': 'ERROR',
214             'class': 'logging.FileHandler',
215             'filename': os.environ.get('ICE_ICE_LOGGER_PATH', LOGS_PATH) + 'vvp-requests.log',
216             'formatter': 'verbose'
217         },
218         'file4': {
219             'level': 'ERROR',
220             'class': 'logging.FileHandler',
221             'filename': os.environ.get('ICE_ICE_LOGGER_PATH', LOGS_PATH) + 'vvp-db.log',
222             'formatter': 'verbose'
223         }
224     },
225     'loggers': {
226         'vvp-ci.logger': {
227             'handlers': ['file1', 'file2', 'file3', 'file4','console'],
228             'level': os.getenv('ICE_ICE_LOGGER_LEVEL', 'DEBUG'),
229         },
230         'django': {
231             'handlers': ['console'],
232             'level': os.getenv('ICE_DJANGO_LOGGER_LEVEL', 'DEBUG'),
233         },
234         'django.request': {
235             'handlers': ['file3'],
236             'level': os.getenv('ICE_ICE_REQUESTS_LOGGER_LEVEL', 'ERROR'),
237         },
238         'django.db.backends': {
239             'handlers': ['file4'],
240             'level': os.getenv('ICE_ICE_DB_LOGGER_LEVEL', 'ERROR'),
241         }
242     }
243 }
244
245
246 #############################
247 # ICE-CI Related Configuration
248 #############################
249 ICE_CONTACT_FROM_ADDRESS = os.getenv('ICE_CONTACT_FROM_ADDRESS')
250 ICE_CONTACT_EMAILS = list(os.getenv('ICE_CONTACT_EMAILS','user@example.com').split(','))
251 ICE_CI_ENVIRONMENT_NAME = os.getenv('ICE_CI_ENVIRONMENT_NAME', 'Dev') # Dev / Docker / Staging
252 ICE_EM_URL = "{domain}/{prefix}".format(domain=os.environ['ICE_EM_DOMAIN_NAME'], prefix=PROGRAM_NAME_URL_PREFIX)
253 ICE_PORTAL_URL = os.environ['ICE_DOMAIN']
254 EM_REST_URL = ICE_EM_URL + '/v1/engmgr/'
255
256 #Number of test results presented in admin page. Illegal values: '0' or 'Null'
257 NUMBER_OF_TEST_RESULTS = int(os.getenv('NUMBER_OF_TEST_RESULTS', '30'))
258 ICE_BUILD_REPORT_NUM = os.getenv('ICE_BUILD_REPORT_NUM',"{:%Y-%m-%d-%H-%M-%S}".format(datetime.now()))
259 IS_JUMP_STATE=os.getenv('IS_JUMP_STATE', "True")
260 DATABASE_TYPE = 'sqlite'
261
262 # FIXME: Does this authentication scheme actually gain us anything? What's the
263 # threat model
264 WEBHOOK_TOKEN = os.environ['SECRET_WEBHOOK_TOKEN']
265
266 # The authentication token and URL needed for us to issue requests to the GitLab API.
267 GITLAB_TOKEN = os.environ['SECRET_GITLAB_AUTH_TOKEN']
268 GITLAB_URL = "http://vvp-gitlab/"
269
270 JENKINS_URL = "http://vvp-jenkins:8080/"
271 JENKINS_USERNAME = "admin"
272 JENKINS_PASSWORD = os.environ['SECRET_JENKINS_PASSWORD']
273
274 AWS_S3_HOST = os.environ['S3_HOST']
275 AWS_S3_PORT = int(os.environ['S3_PORT'])
276 AWS_S3_CUSTOM_DOMAIN = os.environ['S3_HOST']
277 AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
278 AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']