2 This is the file in charge of containing the constants that run the server.
5from typing
import List, Any
9from display_tty
import IDISP
10IDISP.logger.name =
"Constants"
14dotenv.load_dotenv(
".env")
15ENV = dict(dotenv.dotenv_values())
18TOML_CONF = toml.load(
"config.toml")
23 Get the content of an environement variable.
26 variable_name (str): _description_
29 str: _description_: the value of that variable, otherwise an exception is raised.
31 data = environement.get(variable_name)
34 f
"Variable {variable_name} not found in the environement"
41 Get the value of a configuration variable from the TOML file.
44 toml_conf (dict): The loaded TOML configuration as a dictionary.
45 section (str): The section of the TOML file to search in.
46 key (str): The key within the section to fetch.
47 default: The default value to return if the key is not found. Defaults to None.
50 str: The value of the configuration variable, or the default value if the key is not found.
53 KeyError: If the section is not found in the TOML configuration.
56 keys = section.split(
'.')
57 current_section = toml_conf
60 if k
in current_section:
61 current_section = current_section[k]
64 f
"Section '{section}' not found in TOML configuration."
67 if key
in current_section:
68 msg = f
"current_section[{key}] = {current_section[key]} : "
69 msg += f
"{type(current_section[key])}"
70 IDISP.log_debug(msg,
"_get_toml_variable")
71 if current_section[key] ==
"none":
73 "The value none has been converted to None.",
77 return current_section[key]
79 msg = f
"Key '{key}' not found in section '{section}' "
80 msg +=
"of TOML configuration."
85 IDISP.log_warning(f
"{e}",
"_get_toml_variable")
91 TOML_CONF,
"Server_configuration.debug_mode",
"debug",
False
120 TOML_CONF,
"Server_configuration",
"workers",
None
123 TOML_CONF,
"Server_configuration",
"lifespan",
"auto"
126 TOML_CONF,
"Server_configuration",
"timeout_keep_alive", 30
131 TOML_CONF,
"Server_configuration.status_codes",
"success", 0
134 TOML_CONF,
"Server_configuration.status_codes",
"error", -84
139 TOML_CONF,
"Server_configuration.debug_mode",
"debug",
False
144 TOML_CONF,
"Server_configuration.development",
"reload",
False
147 TOML_CONF,
"Server_configuration.development",
"reload_dirs",
None
150 TOML_CONF,
"Server_configuration.development",
"log_level",
"info"
153 TOML_CONF,
"Server_configuration.development",
"use_colours",
True
158 TOML_CONF,
"Server_configuration.production",
"proxy_headers",
True
161 TOML_CONF,
"Server_configuration.production",
"forwarded_allow_ips",
None
166 TOML_CONF,
"Server_configuration.database",
"pool_name",
None
169 TOML_CONF,
"Server_configuration.database",
"max_pool_connections", 10
172 TOML_CONF,
"Server_configuration.database",
"reset_pool_node_connection",
True
175 TOML_CONF,
"Server_configuration.database",
"connection_timeout", 10
178 TOML_CONF,
"Server_configuration.database",
"local_infile",
False
181 TOML_CONF,
"Server_configuration.database",
"init_command",
None
184 TOML_CONF,
"Server_configuration.database",
"default_file",
None
187 TOML_CONF,
"Server_configuration.database",
"ssl_key",
None
190 TOML_CONF,
"Server_configuration.database",
"ssl_cert",
None
193 TOML_CONF,
"Server_configuration.database",
"ssl_ca",
None
196 TOML_CONF,
"Server_configuration.database",
"ssl_cipher",
None
199 TOML_CONF,
"Server_configuration.database",
"ssl_verify_cert",
False
202 TOML_CONF,
"Server_configuration.database",
"ssl",
None
205 TOML_CONF,
"Server_configuration.database",
"autocommit",
False
208 TOML_CONF,
"Server_configuration.database",
"collation",
"utf8mb4_unicode_ci"
214 TOML_CONF,
"Crons",
"clean_tokens_interval", 1800
217 TOML_CONF,
"Crons",
"enable_test_crons",
False
220 TOML_CONF,
"Crons",
"test_cron_interval", 200
223 TOML_CONF,
"Crons",
"check_actions_interval", 300
226 TOML_CONF,
"Crons",
"clean_verification",
True
229 TOML_CONF,
"Crons",
"clean_verification_interval", 900
232 TOML_CONF,
"Crons",
"renew_oath_tokens",
True
235 TOML_CONF,
"Crons",
"renew_oath_tokens_interval", 1800
240 TOML_CONF,
"Verification",
"email_verification_delay", 120
243 TOML_CONF,
"Verification",
"check_token_size", 4
246 TOML_CONF,
"Verification",
"random_min", 100000
249 TOML_CONF,
"Verification",
"random_max", 999999
254 TOML_CONF,
"Services",
"api_request_delay", 5
258JSON_TITLE: str =
"title"
259JSON_MESSAGE: str =
"msg"
260JSON_ERROR: str =
"error"
261JSON_RESP: str =
"resp"
262JSON_LOGGED_IN: str =
"logged in"
263JSON_UID: str =
"user_uid"
266JSON_HEADER_APP_NAME: str =
"app_sender"
267JSON_HEADER_HOST: str =
"serving_host"
268JSON_HEADER_PORT: str =
"serving_port"
269CONTENT_TYPE: str =
"JSON"
272TAB_ACCOUNTS =
"Users"
273TAB_ACTIONS =
"Actions"
274TAB_SERVICES =
"Services"
275TAB_CONNECTIONS =
"Connections"
276TAB_VERIFICATION =
"Verification"
277TAB_ACTIVE_OAUTHS =
"ActiveOauths"
278TAB_ACTION_LOGGING =
"ActionLoging"
279TAB_ACTION_TEMPLATE =
"ActionTemplate"
280TAB_USER_OAUTH_CONNECTION =
"UserOauthConnection"
283CHAR_NODE_KEY: str =
"node"
284CHAR_ACTIVE_KEY: str =
"active"
285CHAR_NAME_KEY: str =
"name"
286CHAR_UID_KEY: str =
"uid"
287CHAR_ID_DEFAULT_INDEX: int = 0
291USERNAME_INDEX_DB: int = 1
292PASSWORD_INDEX_DB: int = 2
293FIRSTNAME_INDEX_DB: int = 3
294LASTNAME_INDEX_DB: int = 4
295BIRTHDAY_INDEX_DB: int = 5
296GENDER_INDEX_DB: int = 7
297ROLE_INDEX_DB: int = 10
298UD_USERNAME_KEY: str =
"username"
299UD_FIRSTNAME_KEY: str =
"firstname"
300UD_LASTNAME_KEY: str =
"lastname"
301UD_BIRTHDAY_KEY: str =
"birthday"
302UD_GENDER_KEY: str =
"gender"
303UD_ROLE_KEY: str =
"role"
304UD_ADMIN_KEY: str =
"admin"
305UD_LOGIN_TIME_KEY: str =
"login_time"
306UD_LOGGED_IN_KEY: str =
"logged_in"
309PATH_KEY: str =
"path"
310ENDPOINT_KEY: str =
"endpoint"
311METHOD_KEY: str =
"method"
312ALLOWED_METHODS: List[str] = [
320REQUEST_TOKEN_KEY =
"token"
321REQUEST_BEARER_KEY =
"authorization"
324THREAD_CACHE_REFRESH_DELAY = 10
327UA_TOKEN_LIFESPAN: int = 7200
328UA_EMAIL_KEY: str =
"email"
329UA_LIFESPAN_KEY: str =
"lifespan"
332USER_INFO_BANNED: List[str] = [
"password",
"method",
"favicon"]
333USER_INFO_ADMIN_NODE: str =
"admin"
str _get_environement_variable(dotenv environement, str variable_name)
Any _get_toml_variable(dict toml_conf, str section, str key, default=None)