|
7 | 7 | from sqlalchemy import URL, AsyncAdaptedQueuePool, NullPool |
8 | 8 |
|
9 | 9 |
|
| 10 | +def _split_method_path(method_path: str) -> tuple[str, str]: |
| 11 | + """Split method and path from a string. |
| 12 | + This function takes a string in the format "METHOD:PATH" and splits it into |
| 13 | + a tuple containing the method and the path. |
| 14 | + For example, "GET:/api/v1/resource" will return ("GET", "/api/v1/resource"). |
| 15 | +
|
| 16 | + Args: |
| 17 | + method_path (str): The string to split. |
| 18 | + Returns: |
| 19 | + tuple[str, str]: The method and path. |
| 20 | + Raises: |
| 21 | + ValueError: If the string is not in the correct format. |
| 22 | + """ |
| 23 | + if not method_path.strip(): |
| 24 | + raise ValueError("Empty string provided") |
| 25 | + parts = method_path.split(":") |
| 26 | + if len(parts) != 2: |
| 27 | + raise ValueError( |
| 28 | + f"Invalid format: {method_path}. Expected format: 'METHOD:PATH'" |
| 29 | + f" (e.g. 'GET:/api/v1/resource')" |
| 30 | + ) |
| 31 | + return tuple(parts) |
| 32 | + |
| 33 | + |
| 34 | +def _split_method_path_list_string( |
| 35 | + method_path: str, |
| 36 | +) -> tuple[tuple[str, str]]: |
| 37 | + """Split a comma-separated string of method and path pairs. |
| 38 | + This function takes a string where each pair is separated by a comma, |
| 39 | + and each pair consists of a method and a path separated by a colon. |
| 40 | + For example, "GET:/api/v1/resource,POST:/api/v1/resource". |
| 41 | + It returns a tuple of tuples, where each inner tuple contains the method and path. |
| 42 | +
|
| 43 | + Args: |
| 44 | + method_path (str): The string to split. |
| 45 | + Returns: |
| 46 | + tuple[tuple[str, str]]: The method and path. |
| 47 | + Raises: |
| 48 | + ValueError: If the string is not in the correct format. |
| 49 | + """ |
| 50 | + if not method_path.strip(): |
| 51 | + return [] |
| 52 | + if not isinstance(method_path, str): |
| 53 | + raise ValueError(f"Invalid type: {type(method_path)}. Expected type: str") |
| 54 | + return tuple(_split_method_path(url.strip()) for url in method_path.split(",")) |
| 55 | + |
| 56 | + |
10 | 57 | class DatabaseConfig: |
11 | 58 | """Database configuration.""" |
12 | 59 |
|
@@ -76,8 +123,20 @@ class Config: |
76 | 123 | WORKERS_COUNT = int(os.getenv("WORKERS_COUNT", "1")) |
77 | 124 | RELOAD = os.getenv("RELOAD", "true").lower() == "true" |
78 | 125 | LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO") |
| 126 | + LOGGER_IGNORE_PATHS = _split_method_path_list_string( |
| 127 | + os.getenv("LOGGER_IGNORE_PATHS", "GET:/docs,GET:/openapi.json") |
| 128 | + ) |
79 | 129 |
|
80 | | - APPLICATION_ROOT = os.getenv("APPLICATION_ROOT", "") |
| 130 | + LOGGER_IGNORE_INPUT_BODY_PATHS = _split_method_path_list_string( |
| 131 | + os.getenv( |
| 132 | + "LOGGER_IGNORE_INPUT_BODY_PATHS", |
| 133 | + "POST:/user/register,PUT:/user/,POST:/auth/token", |
| 134 | + ) |
| 135 | + ) |
| 136 | + |
| 137 | + LOGGER_IGNORE_OUTPUT_BODY_PATHS = _split_method_path_list_string( |
| 138 | + os.getenv("LOGGER_IGNORE_OUTPUT_BODY_PATHS", "POST:/auth/token") |
| 139 | + ) |
81 | 140 |
|
82 | 141 | DATABASE: DatabaseConfig = DatabaseConfig() |
83 | 142 | AUTH: AuthConfig = AuthConfig() |
|
0 commit comments