forked from atlas-bi/Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
382 lines (305 loc) · 10.6 KB
/
config.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
375
376
377
378
379
380
381
382
"""Default Configuration."""
import os
from pathlib import Path
from urllib.parse import urlparse
import redis
import saml2
import saml2.saml
from apscheduler.jobstores.redis import RedisJobStore
class Config:
"""All prod configuration set here. For dev there are overrides below."""
# pylint: disable=too-few-public-methods
# ruff: noqa: RUF012
ALLOWED_HOSTS = ["*", "localhost"]
ORG_NAME = "Riverside Healthcare"
DEBUG = False
TESTING = False
DEMO = False
# flask cookie encryption
SECRET_KEY = b"zL-yN8sVPaheeWmLJz8CxHXSLt8ZMI9jrAPXn167a8I="
# password encryption key (multiple of 4 bytes) https://fernetkeygen.com
PASS_KEY = b"zL-yN8sVPaheeWmLJz8CxHXSLt8ZMI9jrAPXn167a8I="
# redis sessions
redis_host = os.environ.get("REDISHOST", "localhost")
redis_port = int(os.environ.get("REDISPORT", 6379))
redis_password = os.environ.get("REDISPASSWORD")
redis_user = os.environ.get("REDISUSER")
SESSION_TYPE = "redis"
SESSION_REDIS = redis.Redis(host=redis_host, port=redis_port)
if os.environ.get("REDIS_URL"):
url = urlparse(os.environ["REDIS_URL"])
redis_host = url.hostname or "localhost"
redis_port = url.port or 6379
redis_password = url.password
redis_user = url.username
SESSION_REDIS = redis.Redis(
host=redis_host,
port=redis_port,
username=redis_user,
password=redis_password,
)
# for flask-redis
REDIS_URL = os.environ.get("REDIS_URL", f"redis://{redis_host}:{redis_port}")
# authentication
LOGIN_VIEW = "auth_bp.login"
REQUIRED_GROUPS = ["Analytics"]
LOGIN_MESSAGE = "Please login to access this page."
AUTH_METHOD = "DEV" # LDAP, SAML, or DEV for no pass.
LOGIN_REDIRECT_URL = "/"
NOT_AUTHORIZED_URL = "auth_bp.not_authorized"
# ldap
LDAP_HOST = "ldap.host.net" # defaults to localhost
LDAP_BASE_DN = "OU=RHC & Offsite Locations,OU=Employees,DC=MyOrg,DC=net"
LDAP_USER_OBJECT_FILTER = "(|(sAMAccountName=%s)(userPrincipalName=%s))"
LDAP_USERNAME = "MYORG\\username"
LDAP_PASSWORD = "password" # noqa: S105
LDAP_USE_SSL = True
LDAP_ATTR_MAP = {
"account_name": "sAMAccountName",
"email": "userPrincipalName",
"full_name": "cn",
"first_name": "givenName",
}
# cache
CACHE_TYPE = "SimpleCache"
CACHE_DEFAULT_TIMEOUT = 300
# database
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL",
"postgresql+psycopg2://{user}:{pw}@{url}/{db}".format(
user="username", pw="password", url="server", db="atlas_automation_hub"
),
).replace("postgres://", "postgresql://")
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ENGINE_OPTIONS = {
"max_overflow": 100, # how many spare connections we can use?
"pool_size": 5, # how many queries will run symultaniously?
}
SCHEDULER_HOST = "http://127.0.0.1:5001/api"
RUNNER_HOST = "http://127.0.0.1:5002/api"
WEB_HOST = "locahost"
"""
process executor. must be thread type, not process, otherwise we cannot
have sql access inside the called functions.
"""
EXECUTOR_TYPE = "thread"
EXECUTOR_MAX_WORKERS = 12
EXECUTOR_PROPAGATE_EXCEPTIONS = True
# compression
MINIFY_HTML = True
# saml config
BASE_DIR = Path(__file__).resolve().parent
BASE_URL = "https://automationhub.MyOrg.net/"
# pylint: disable=C0301
SAML_CONFIG = {
"xmlsec_binary": "/usr/bin/xmlsec1",
"entityid": BASE_URL + "saml2/metadata/",
"allow_unknown_attributes": True,
"service": {
"sp": {
"name": "Automation Hub SP",
"name_id_format": saml2.saml.NAMEID_FORMAT_PERSISTENT,
"allow_unsolicited": True,
"endpoints": {
"assertion_consumer_service": [
(BASE_URL + "saml2/acs/", saml2.BINDING_HTTP_POST),
],
"single_logout_service": [
(BASE_URL + "saml2/ls/", saml2.BINDING_HTTP_REDIRECT),
(BASE_URL + "saml2/ls/post/", saml2.BINDING_HTTP_POST),
],
},
"force_authn": False,
"name_id_format_allow_create": True,
"required_attributes": ["emailAddress"],
"authn_requests_signed": False,
"logout_requests_signed": True,
"want_assertions_signed": True,
"want_response_signed": False,
},
},
"metadata": {
"remote": [
{
"url": "https://rhcfs.MyOrg.net/FederationMetadata/2007-06/FederationMetadata.XML", # noqa: E501
"disable_ssl_certificate_validation": True,
},
],
},
"debug": 1,
"key_file": str(BASE_DIR / "publish/cert.key"), # private part
"cert_file": str(BASE_DIR / "publish/cert.crt"), # public part
"encryption_keypairs": [
{
"key_file": str(BASE_DIR / "publish/cert.key"), # private part
"cert_file": str(BASE_DIR / "publish/cert.crt"), # public part
}
],
"contact_person": [
{
"given_name": "First Name",
"sur_name": "Last Name",
"company": "Riverside Healthcare",
"email_address": "em@i.l",
"contact_type": "technical",
},
],
"organization": {
"name": [("Riverside Healthcare", "en")],
"display_name": [("Riverside Healthcare", "en")],
"url": [(BASE_URL, "en")],
},
}
SAML_ATTR_MAP = {
"account_name": "name",
"email": "emailAddress",
"last_name": "surname",
"first_name": "givenName",
"groups": "group",
}
"""
scheduler settings
"""
SCHEDULER_JOBSTORES = {
"default": RedisJobStore(
jobs_key="atlas_hub_jobs",
run_times_key="atlas_hub_running",
host=redis_host,
port=redis_port,
username=redis_user,
password=redis_password,
)
}
SCHEDULER_EXECUTORS = {
"default": {
"type": "threadpool",
"max_workers": 100,
}
}
SCHEDULER_JOB_DEFAULTS = {
"coalesce": True,
"max_instances": 50,
"replace_existing": True,
"misfire_grace_time": 30,
}
SCHEDULER_API_ENABLED = False
"""
runner settings
"""
"""
minimum space needed to run tasks
"""
MIN_DISK_SPACE = 1 * 1024 * 1024 * 1024
MIN_FREE_MEM_PERC = 3
MIN_FREE_CPU_PERC = 3
"""
GIT connection for secure/prive repositories
"""
GIT_URL = "https://git.example.net/"
GIT_USERNAME = "username"
GIT_PASSWORD = r"password" # noqa: S105
GIT_TOKEN = r"token" # noqa: S105
GIT_VERIFY_SSL = False
HTTP_VERIFY_SSL = False
"""
Azure Devops connection
"""
DEVOPS_URL = "https://dev.azure.com/orgname/"
DEVOPS_TOKEN = r"token" # noqa: S105
"""
Default SQL Connection Settings
"""
# minutes
DEFAULT_SQL_TIMEOUT = 90
"""
SMB Connection for file storage
All extracts backups will be stored here.
"""
SMB_USERNAME = "username"
SMB_PASSWORD = "password" # noqa: S105
SMB_SERVER_IP = "10.0.0.0"
SMB_SERVER_NAME = "servername"
SMB_DEFAULT_SHARE = "BackupShare"
"""
Email connection info
"""
SMTP_SERVER = "10.0.0.0"
SMTP_PORT = 25
SMTP_SENDER_NAME = "⚒️ Atlas Hub"
SMTP_SENDER_EMAIL = "noreply@example.net"
SMTP_DEFAULT_RECIEVER = "noreply@example.net"
SMTP_SUBJECT_PREFIX = "### "
SMTP_USE_TLS = False
SMTP_USERNAME = None
SMTP_PASSWORD = None
EXECUTOR_TYPE = "thread"
EXECUTOR_MAX_WORKERS = 12
EXECUTOR_PROPAGATE_EXCEPTIONS = True
PYTHON_TASKS_ENABLED = True
ROLLUP_BIN = "./node_modules/.bin/rollup"
ROLLUP_EXTRA_ARGS = ["-c", "rollup.config.mjs"]
UGLIFYJS_BIN = "./node_modules/.bin/uglifyjs"
POSTCSS_BIN = "./node_modules/.bin/postcss"
class DevConfig(Config):
"""Configuration overrides for development.
To Use:
FLASK_ENV=development
"""
# pylint: disable=too-few-public-methods
# authentication override
AUTH_METHOD = "DEV"
DEBUG = False
DEMO = True
SESSION_COOKIE_SECURE = False
DEBUG_TB_INTERCEPT_REDIRECTS = False
# database overrides
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL",
"postgresql+psycopg2://{user}:{pw}@{url}/{db}".format(
user="username", pw="password", url="server", db="atlas_hub_dev"
),
).replace("postgres://", "postgresql://")
ASSETS_DEBUG = False
SQLALCHEMY_RECORD_QUERIES = True
class DemoConfig(Config):
"""Configuration for a demo."""
DEBUG = False
DEMO = True
AUTH_METHOD = "DEV"
PYTHON_TASKS_ENABLED = False
class TestConfig(DevConfig):
"""Configuration overrides for dev testing.
Test config is also used for public demo.
To Use:
FLASK_ENV=test
FLASK_DEBUG=0
"""
# test db:
# 1 try to get DATABASE_URL
# 2 try to build from pieces
# 3 use sqlite
# pylint: disable=too-few-public-methods
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL",
"postgresql+psycopg2://postgres@localhost/atlas_hub_scrap_test",
# "sqlite:///../test.sqlite",
).replace("postgres://", "postgresql://")
SQLALCHEMY_ENGINE_OPTIONS: dict = {}
DEMO = True
TEST = True
ASSETS_DEBUG = False
AUTH_METHOD = "DEV"
DEBUG = False
from apscheduler.executors.pool import ThreadPoolExecutor
SCHEDULER_EXECUTORS = {"default": ThreadPoolExecutor(100)}
# logins for test.
# docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=@Passw0rd>" -p 1433:1433 --name sql1 -h sql1 -d mcr.microsoft.com/mssql/server:2017-latest
SQL_SERVER_CONN = "SERVER=127.0.0.1;UID=SA;PWD=@Passw0rd>"
PG_SERVER_CONN = "host=127.0.0.1 user=postgres password=12345"
# docker run -p 22:22 -d emberstack/sftp --name sftp
SFTP_SERVER_USER = "demo"
SFTP_SERVER_PASS = "demo" # noqa: S105
# docker run -d --name ftpd_server -p 21:21 onekilo79/ftpd_test
# docker run -d --name ftpd_server -p 21:21 -p 30000-30009:30000-30009 -e FTP_USER_NAME=demo -e FTP_USER_PASS=demo -e FTP_USER_HOME=/home/demo -e "PUBLICHOST=localhost" -e "ADDED_FLAGS=-d -d" stilliard/pure-ftpd
FTP_SERVER_USER = "demo"
FTP_SERVER_PASS = "demo" # noqa: S105