-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
112 lines (87 loc) · 3.54 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
"""Module containing default config values."""
from typing import Union, Type
from numbers import Number
class Config(object):
DEBUG = False
TESTING = False
JWT_CLAIMS_IN_REFRESH_TOKEN = True
JWT_SECRET_KEY = ''
SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
SQLALCHEMY_TRACK_MODIFICATIONS = False
DB_UNIQUE_CONSTRAIN_FAIL = 'UNIQUE constraint failed'
REVERSE_PROXY_COUNT = 0
LOGGING_CONFIGS = ['logging_config.json']
JSON_SORT_KEYS = False
JSONIFY_PRETTYPRINT_REGULAR = False
DEBUG_DONT_CONNECT_TO_API = False
DEBUG_DONT_SEND_MAIL = False
GENERATED_PASSWORD_BYTES = 8
# Should be regex compatible with https://docs.python.org/3/library/re.html
# as well as https://www.w3schools.com/TAGS/att_input_pattern.asp
EMAIL_ADDRESS_FILTER = ".*"
GRAPH_API_AUTH_AUTHORITY = "https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000"
GRAPH_API_AUTH_CLIENT_ID = "00000000-0000-0000-0000-000000000000"
GRAPH_API_AUTH_PUBKEY_THUMBPRINT = "0000000000000000000000000000000000000000"
GRAPH_API_AUTH_PRIVKEY_PATH = "/path/to/ms365AccountCreator.key"
GRAPH_API_USER_MAIL_DOMAIN = "example.onmicrosoft.com"
GRAPH_API_GROUPS_FOR_NEW_USERS = ["00000000-0000-0000-0000-000000000000"]
MAIL_SERVER_HOST = ""
MAIL_SERVER_PORT = 25
MAIL_SERVER_SSL = False
MAIL_SERVER_STARTTLS = True
MAIL_SERVER_LOGIN = True
MAIL_SERVER_USER = ""
MAIL_SERVER_PW = ""
MAIL_SENDING_ADDRESS = ""
SUPPORT_EMAIL = ""
OPENAPI_VERSION = "3.0.2"
OPENAPI_JSON_PATH = "api-spec.json"
OPENAPI_URL_PREFIX = "/api"
OPENAPI_REDOC_PATH = "/redoc"
OPENAPI_REDOC_URL = (
"https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"
)
OPENAPI_SWAGGER_UI_PATH = "/swagger-ui"
OPENAPI_SWAGGER_UI_URL = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/"
class ProductionConfig(Config):
pass
class DebugConfig(Config):
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
JWT_SECRET_KEY = 'debug'
DEBUG_DONT_CONNECT_TO_API = True
LOGGING_CONFIGS = ['logging_config.json', 'logging_config_debug.json']
# do not propagate exceptions in debug mode
# this makes it hard to test the api and an api client at the same time
PROPAGATE_EXCEPTIONS = False
class TestingConfig(Config):
TESTING = True
def coerce_value_to(value: Union[str, Number, bool], target_type: Union[Type[str], Type[Number], Type[bool], Type[int], Type[float]]):
"""Coearce a config value to the given target type if possible."""
if isinstance(value, target_type):
return value
if target_type == bool:
if isinstance(value, Number):
return bool(value)
if isinstance(value, str):
return value.lower() == 'true' # assume anything not 'true' as false
if value is None:
return None
if target_type == Number or target_type == float:
if isinstance(value, bool):
return 1 if value else 0
if isinstance(value, str):
if value.isdecimal():
return int(value)
else:
try:
return float(value)
except ValueError as exc:
raise ValueError(f'Could not coerce {value} to float.') from exc
if target_type == int:
if isinstance(value, bool):
return 1 if value else 0
if isinstance(value, str):
if value.isdecimal():
return int(value)
raise ValueError(f'Could not coerce {value} to {target_type}.')