2 File in charge of referencing all the paths_initialised supported by the server.
4from typing
import Union, List, Dict, Any
5from display_tty
import Disp, TOML_CONF, FILE_DESCRIPTOR, SAVE_TO_FILE, FILE_NAME
6from .runtime_data
import RuntimeData
7from .constants
import PATH_KEY, ENDPOINT_KEY, METHOD_KEY, ALLOWED_METHODS
14 def __init__(self, runtime_data: RuntimeData, success: int = 0, error: int = 84, debug: bool =
False) ->
None:
18 success (int, optional): _description_. Defaults to 0.
19 error (int, optional): _description_. Defaults to 84.
24 self.
routes: List[Dict[str, Any]] = []
33 logger=self.__class__.__name__
36 def add_path(self, path: str, endpoint: object, method: Union[str, List[str]]) -> int:
38 This function is in charge of adding a path to the list of paths_initialised.
41 path (str): _description_: The path to call for the endpoint to be triggered
42 endpoint (str): _description_: The function that represents the endpoint
43 method (str, list): _description_: The method used for the provided path (GET, PUT, POST, etc)
46 int: _description_: success if it succeeded, error if there was an error in the data.
48 self.
disp.log_debug(f
"Adding path <{path}>",
"add_path")
50 if isinstance(path, (str))
is False or isinstance(method, (str, list))
is False or callable(endpoint)
is False:
52 f
"Failed to insert {path} with method {method}",
"add_path"
55 if isinstance(method, str)
is True and method.upper()
not in ALLOWED_METHODS:
56 msg = f
"Failed to insert {path}, method {method} not allowed"
57 self.
disp.log_error(msg,
"add_path")
59 if isinstance(method, list)
is True:
61 if isinstance(i, str)
is False or i.upper()
not in ALLOWED_METHODS:
62 msg = f
"Failed to insert {path}, method {i} not allowed"
63 self.
disp.log_error(msg,
"add_path")
65 if isinstance(method, str)
is True:
68 {PATH_KEY: path, ENDPOINT_KEY: endpoint, METHOD_KEY: method}
74 This function is in charge of adding the default paths_initialised to the list of paths_initialised.
77 "Loading default paths_initialised",
78 "load_default_paths_initialised"
84 Function in charge of loading the routes into the api.
86 app (FastAPI): _description_
88 self.
disp.log_info(
"injecting routes",
"inject_routes")
90 self.
disp.log_debug(f
"route = {route}",
"inject_routes")
94 methods=route[METHOD_KEY]
None __init__(self, RuntimeData runtime_data, int success=0, int error=84, bool debug=False)
int add_path(self, str path, object endpoint, Union[str, List[str]] method)
RuntimeData runtime_data_initialised
None load_default_paths_initialised(self)