Terarea
2
The automation project
Loading...
Searching...
No Matches
mandatory.py
Go to the documentation of this file.
1
"""_summary_
2
The file that contains mandatory endpoints
3
"""
4
5
6
import
time
7
from
fastapi
import
Response, Request
8
from
display_tty
import
Disp, TOML_CONF, FILE_DESCRIPTOR, SAVE_TO_FILE, FILE_NAME
9
from
..
import
constants
as
CONST
10
from
..runtime_data
import
RuntimeData
11
from
..http_codes
import
HCI
12
13
14
class
Mandatory
:
15
"""
16
The class that contains mandatory endpoints
17
"""
18
19
def
__init__
(self, runtime_data: RuntimeData, success: int = 0, error: int = 84, debug: bool =
False
) ->
None
:
20
"""_summary_
21
The class in charge of the mandatory endpoints
22
23
Args:
24
runtime_data (RuntimeData): _description_
25
success (int, optional): _description_. Defaults to 0.
26
error (int, optional): _description_. Defaults to 84.
27
debug (bool, optional): _description_. Defaults to False.
28
"""
29
# ------------------------ Inherited variables ------------------------
30
self.
debug
: bool = debug
31
self.
success
: int = success
32
self.
error
: int = error
33
self.
runtime_data_initialised
: RuntimeData = runtime_data
34
# ------------------------- The visual logger -------------------------
35
self.
disp
: Disp = Disp(
36
TOML_CONF,
37
SAVE_TO_FILE,
38
FILE_NAME,
39
FILE_DESCRIPTOR,
40
debug=self.
debug
,
41
logger=self.__class__.__name__
42
)
43
44
def
get_about
(self, request: Request) -> Response:
45
"""_summary_
46
The endpoint corresponding to '/about'.
47
48
Returns:
49
Response: _description_: The data to send back to the user as a response.
50
"""
51
title =
"get_about"
52
self.
disp
.log_debug(title,
"Gathering data"
)
53
host = request.client.host
54
current_time = int(time.time())
55
self.
disp
.log_debug(f
"host = {host}"
, title)
56
self.
disp
.log_debug(f
"current_time = {current_time}"
, title)
57
json_body = {
58
" client "
: {
59
" host "
: host
60
},
61
" server "
: {
62
" current_time "
: current_time,
63
" services "
: self.
runtime_data_initialised
.boilerplate_non_http_initialised.get_services()
64
}
65
}
66
self.
disp
.log_debug(f
"json_body = {json_body}"
, title)
67
outgoing = HCI.success(
68
json_body,
69
content_type=CONST.CONTENT_TYPE,
70
headers=self.
runtime_data_initialised
.json_header
71
)
72
self.
disp
.log_debug(f
"ready_to_go: {outgoing}"
, title)
73
return
outgoing
src.lib.components.endpoints.mandatory.Mandatory
Definition
mandatory.py:14
src.lib.components.endpoints.mandatory.Mandatory.disp
Disp disp
Definition
mandatory.py:35
src.lib.components.endpoints.mandatory.Mandatory.__init__
None __init__(self, RuntimeData runtime_data, int success=0, int error=84, bool debug=False)
Definition
mandatory.py:19
src.lib.components.endpoints.mandatory.Mandatory.error
int error
Definition
mandatory.py:32
src.lib.components.endpoints.mandatory.Mandatory.debug
bool debug
Definition
mandatory.py:30
src.lib.components.endpoints.mandatory.Mandatory.runtime_data_initialised
RuntimeData runtime_data_initialised
Definition
mandatory.py:33
src.lib.components.endpoints.mandatory.Mandatory.success
int success
Definition
mandatory.py:31
src.lib.components.endpoints.mandatory.Mandatory.get_about
Response get_about(self, Request request)
Definition
mandatory.py:44
app
back
server
src
lib
components
endpoints
mandatory.py
Generated on Sat Feb 22 2025 14:36:42 for Terarea by
1.12.0