maleo-foundation 0.1.67__tar.gz → 0.1.69__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/PKG-INFO +1 -1
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/authentication.py +14 -2
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/middleware.py +2 -2
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/middlewares/authentication.py +9 -11
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/middlewares/base.py +15 -3
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/responses.py +2 -1
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/exceptions.py +8 -6
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/PKG-INFO +1 -1
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/SOURCES.txt +0 -1
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/pyproject.toml +1 -1
- maleo_foundation-0.1.67/maleo_foundation/middlewares/__init__.py +0 -98
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/README.md +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/manager.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/constants.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/enums.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/client.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/general.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/query.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/service.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/extended_types.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/base.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/google/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/google/base.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/google/secret.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/google/storage.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/maleo.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/db.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/service.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/middlewares/cors.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/general.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/parameter.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/result.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/table.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/general/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/general/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/general/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/client.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/general.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/service.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/parameters/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/client/service.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/service/general.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/service/query.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/signature.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/results/token.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/types.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/controller.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/extractor.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/formatter/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/formatter/case.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/loaders/__init__.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/loaders/json.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/loaders/key.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/loaders/yaml.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/logging.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/mergers.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/query.py +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/dependency_links.txt +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/requires.txt +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/top_level.txt +0 -0
- {maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/setup.cfg +0 -0
@@ -3,16 +3,28 @@ from starlette.authentication import (
|
|
3
3
|
BaseUser
|
4
4
|
)
|
5
5
|
from typing import Optional, Sequence
|
6
|
+
from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
|
7
|
+
from maleo_foundation.types import BaseTypes
|
6
8
|
|
7
9
|
class Credentials(AuthCredentials):
|
8
10
|
def __init__(
|
9
11
|
self,
|
10
|
-
token:
|
12
|
+
token:BaseTypes.OptionalString = None,
|
13
|
+
payload:Optional[BaseTokenGeneralTransfers.DecodePayload] = None,
|
11
14
|
scopes:Optional[Sequence[str]] = None
|
12
15
|
) -> None:
|
13
|
-
self.
|
16
|
+
self._token = token
|
17
|
+
self._payload = payload
|
14
18
|
super().__init__(scopes)
|
15
19
|
|
20
|
+
@property
|
21
|
+
def token(self) -> BaseTypes.OptionalString:
|
22
|
+
return self._token
|
23
|
+
|
24
|
+
@property
|
25
|
+
def payload(self) -> Optional[BaseTokenGeneralTransfers.DecodePayload]:
|
26
|
+
return self._payload
|
27
|
+
|
16
28
|
class User(BaseUser):
|
17
29
|
def __init__(
|
18
30
|
self,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
from fastapi import FastAPI
|
2
2
|
from pydantic import BaseModel, Field
|
3
|
-
from typing import List
|
3
|
+
from typing import List
|
4
4
|
from maleo_foundation.client.manager import MaleoFoundationClientManager
|
5
5
|
from maleo_foundation.models.schemas import BaseGeneralSchemas
|
6
6
|
from maleo_foundation.middlewares.authentication import add_authentication_middleware
|
7
|
-
from maleo_foundation.middlewares.base import add_base_middleware
|
7
|
+
from maleo_foundation.middlewares.base import add_base_middleware
|
8
8
|
from maleo_foundation.middlewares.cors import add_cors_middleware
|
9
9
|
from maleo_foundation.utils.logging import MiddlewareLogger
|
10
10
|
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/middlewares/authentication.py
RENAMED
@@ -1,5 +1,6 @@
|
|
1
|
+
from datetime import datetime, timezone
|
1
2
|
from fastapi import FastAPI
|
2
|
-
from starlette.authentication import AuthenticationBackend
|
3
|
+
from starlette.authentication import AuthenticationBackend, AuthenticationError
|
3
4
|
from starlette.middleware.authentication import AuthenticationMiddleware
|
4
5
|
from starlette.requests import HTTPConnection
|
5
6
|
from typing import Tuple
|
@@ -7,7 +8,7 @@ from maleo_foundation.authentication import Credentials, User
|
|
7
8
|
from maleo_foundation.client.manager import MaleoFoundationClientManager
|
8
9
|
from maleo_foundation.models.schemas import BaseGeneralSchemas
|
9
10
|
from maleo_foundation.models.transfers.parameters.token import BaseTokenParametersTransfers
|
10
|
-
from maleo_foundation.utils.
|
11
|
+
from maleo_foundation.utils.exceptions import BaseExceptions
|
11
12
|
from maleo_foundation.utils.logging import MiddlewareLogger
|
12
13
|
|
13
14
|
class Backend(AuthenticationBackend):
|
@@ -18,25 +19,22 @@ class Backend(AuthenticationBackend):
|
|
18
19
|
self._maleo_foundation = maleo_foundation
|
19
20
|
|
20
21
|
async def authenticate(self, conn:HTTPConnection) -> Tuple[Credentials, User]:
|
21
|
-
client_ip = BaseExtractors.extract_client_ip(conn)
|
22
22
|
if "Authorization" not in conn.headers:
|
23
|
-
self._logger.info(f"Request | IP: {client_ip} | URL: {conn.url.path} - Result | General: Header did not contain authorization")
|
24
23
|
return Credentials(), User(authenticated=False)
|
25
24
|
|
26
25
|
auth = conn.headers["Authorization"]
|
27
26
|
scheme, token = auth.split()
|
28
27
|
if scheme != 'Bearer':
|
29
|
-
|
30
|
-
return Credentials(), User(authenticated=False)
|
28
|
+
raise AuthenticationError("Authorization scheme must be Bearer token")
|
31
29
|
|
32
30
|
decode_token_parameters = BaseTokenParametersTransfers.Decode(key=self._keys.public, token=token)
|
33
31
|
decode_token_result = self._maleo_foundation.services.token.decode(parameters=decode_token_parameters)
|
34
32
|
if not decode_token_result.success:
|
35
|
-
|
36
|
-
|
33
|
+
raise AuthenticationError("Invalid Bearer token, unable to decode token")
|
34
|
+
if decode_token_result.data.exp_dt <= datetime.now(tz=timezone.utc):
|
35
|
+
raise AuthenticationError("Expired Bearer token, request new or refresh token")
|
37
36
|
|
38
|
-
|
39
|
-
return Credentials(token=token), User(authenticated=True, username=decode_token_result.data.u_u, email=decode_token_result.data.u_e)
|
37
|
+
return Credentials(token=token, payload=decode_token_result.data, scopes=["authenticated"]), User(authenticated=True, username=decode_token_result.data.u_u, email=decode_token_result.data.u_e)
|
40
38
|
|
41
39
|
def add_authentication_middleware(app:FastAPI, keys:BaseGeneralSchemas.RSAKeys, logger:MiddlewareLogger, maleo_foundation:MaleoFoundationClientManager) -> None:
|
42
40
|
"""
|
@@ -64,4 +62,4 @@ def add_authentication_middleware(app:FastAPI, keys:BaseGeneralSchemas.RSAKeys,
|
|
64
62
|
add_authentication_middleware(app=app, limit=10, window=1, cleanup_interval=60, ip_timeout=300)
|
65
63
|
```
|
66
64
|
"""
|
67
|
-
app.add_middleware(AuthenticationMiddleware, backend=Backend(keys, logger, maleo_foundation))
|
65
|
+
app.add_middleware(AuthenticationMiddleware, backend=Backend(keys, logger, maleo_foundation), on_error=BaseExceptions.authentication_error_handler)
|
@@ -8,6 +8,7 @@ from fastapi import FastAPI, Request, Response, status
|
|
8
8
|
from fastapi.responses import JSONResponse
|
9
9
|
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
|
10
10
|
from typing import Awaitable, Callable, Optional, Sequence
|
11
|
+
from maleo_foundation.authentication import Credentials, User
|
11
12
|
from maleo_foundation.client.manager import MaleoFoundationClientManager
|
12
13
|
from maleo_foundation.models.schemas import BaseGeneralSchemas
|
13
14
|
from maleo_foundation.models.responses import BaseResponses
|
@@ -136,6 +137,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
136
137
|
def _build_response(
|
137
138
|
self,
|
138
139
|
request:Request,
|
140
|
+
authentication_info:str,
|
139
141
|
response:Response,
|
140
142
|
request_timestamp:datetime,
|
141
143
|
response_timestamp:datetime,
|
@@ -146,7 +148,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
146
148
|
response = self._add_response_headers(request, response, request_timestamp, response_timestamp, process_time)
|
147
149
|
log_func = getattr(self._logger, log_level)
|
148
150
|
log_func(
|
149
|
-
f"Request | IP: {client_ip} | Method: {request.method} | URL: {request.url.path} | "
|
151
|
+
f"Request {authentication_info} | IP: {client_ip} | Method: {request.method} | URL: {request.url.path} | "
|
150
152
|
f"Headers: {dict(request.headers)} - Response | Status: {response.status_code} | "
|
151
153
|
)
|
152
154
|
return response
|
@@ -154,11 +156,12 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
154
156
|
def _handle_exception(
|
155
157
|
self,
|
156
158
|
request:Request,
|
159
|
+
authentication_info:str,
|
157
160
|
error,
|
158
161
|
request_timestamp:datetime,
|
159
162
|
response_timestamp:datetime,
|
160
163
|
process_time:int,
|
161
|
-
client_ip
|
164
|
+
client_ip:str = "unknown"
|
162
165
|
):
|
163
166
|
traceback_str = traceback.format_exc().split("\n")
|
164
167
|
error_details = {
|
@@ -176,7 +179,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
176
179
|
)
|
177
180
|
|
178
181
|
self._logger.error(
|
179
|
-
f"Request | IP: {client_ip} | Method: {request.method} | URL: {request.url.path} | "
|
182
|
+
f"Request {authentication_info} | IP: {client_ip} | Method: {request.method} | URL: {request.url.path} | "
|
180
183
|
f"Headers: {dict(request.headers)} - Response | Status: 500 | Exception:\n{json.dumps(error_details, indent=4)}"
|
181
184
|
)
|
182
185
|
|
@@ -190,12 +193,18 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
190
193
|
request_timestamp = datetime.now(tz=timezone.utc) #* Record the request timestamp
|
191
194
|
start_time = time.perf_counter() #* Record the start time
|
192
195
|
client_ip = BaseExtractors.extract_client_ip(request) #* Get request IP with improved extraction
|
196
|
+
user:User = request.user
|
197
|
+
if not user.is_authenticated:
|
198
|
+
authentication_info = "| Unauthenticated"
|
199
|
+
else:
|
200
|
+
authentication_info = f"| Username: {user.display_name} | Email:{user.identity}"
|
193
201
|
|
194
202
|
try:
|
195
203
|
#* 1. Rate limit check
|
196
204
|
if self._check_rate_limit(client_ip):
|
197
205
|
return self._build_response(
|
198
206
|
request=request,
|
207
|
+
authentication_info=authentication_info,
|
199
208
|
response=JSONResponse(
|
200
209
|
content=BaseResponses.RateLimitExceeded().model_dump(),
|
201
210
|
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
@@ -212,6 +221,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
212
221
|
if pre_response is not None:
|
213
222
|
return self._build_response(
|
214
223
|
request=request,
|
224
|
+
authentication_info=authentication_info,
|
215
225
|
response=pre_response,
|
216
226
|
request_timestamp=request_timestamp,
|
217
227
|
response_timestamp=datetime.now(tz=timezone.utc),
|
@@ -224,6 +234,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
224
234
|
response = await call_next(request)
|
225
235
|
response = self._build_response(
|
226
236
|
request=request,
|
237
|
+
authentication_info=authentication_info,
|
227
238
|
response=response,
|
228
239
|
request_timestamp=request_timestamp,
|
229
240
|
response_timestamp=datetime.now(tz=timezone.utc),
|
@@ -237,6 +248,7 @@ class BaseMiddleware(BaseHTTPMiddleware):
|
|
237
248
|
except Exception as e:
|
238
249
|
return self._handle_exception(
|
239
250
|
request=request,
|
251
|
+
authentication_info=authentication_info,
|
240
252
|
error=e,
|
241
253
|
request_timestamp=request_timestamp,
|
242
254
|
response_timestamp=datetime.now(tz=timezone.utc),
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from fastapi import status
|
3
3
|
from pydantic import Field, model_validator
|
4
|
+
from typing import Dict, Type, Union
|
4
5
|
from maleo_foundation.models.schemas.general import BaseGeneralSchemas
|
5
6
|
from maleo_foundation.models.schemas.result import BaseResultSchemas
|
6
7
|
from maleo_foundation.types import BaseTypes
|
@@ -88,7 +89,7 @@ class BaseResponses:
|
|
88
89
|
return values
|
89
90
|
|
90
91
|
#* ----- ----- Responses Class ----- ----- *#
|
91
|
-
other_responses={
|
92
|
+
other_responses:Dict[int, Dict[str, Union[str, Type[Fail]]]]={
|
92
93
|
status.HTTP_400_BAD_REQUEST: {
|
93
94
|
"description": "Bad Request Response",
|
94
95
|
"model": BadRequest
|
@@ -11,17 +11,19 @@ from maleo_foundation.models.transfers.results.service.query import BaseServiceQ
|
|
11
11
|
from maleo_foundation.utils.logging import BaseLogger
|
12
12
|
|
13
13
|
class BaseExceptions:
|
14
|
+
@staticmethod
|
15
|
+
def authentication_error_handler(request:Request, exc:Exception):
|
16
|
+
return JSONResponse(content=BaseResponses.Unauthorized(other=str(exc)).model_dump(), status_code=status.HTTP_401_UNAUTHORIZED)
|
17
|
+
|
14
18
|
@staticmethod
|
15
19
|
async def validation_exception_handler(request:Request, exc:RequestValidationError):
|
16
|
-
return JSONResponse(
|
20
|
+
return JSONResponse(content=BaseResponses.ValidationError(other=exc.errors()).model_dump(), status_code=status.HTTP_422_UNPROCESSABLE_ENTITY)
|
17
21
|
|
18
22
|
@staticmethod
|
19
23
|
async def http_exception_handler(request:Request, exc:StarletteHTTPException):
|
20
|
-
if exc.status_code
|
21
|
-
return JSONResponse(
|
22
|
-
|
23
|
-
#* Handle other HTTP exceptions normally
|
24
|
-
return None
|
24
|
+
if exc.status_code in BaseResponses.other_responses:
|
25
|
+
return JSONResponse(content=BaseResponses.other_responses[exc.status_code]["model"]().model_dump(), status_code=exc.status_code)
|
26
|
+
return JSONResponse(content=BaseResponses.ServerError().model_dump(), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
25
27
|
|
26
28
|
@staticmethod
|
27
29
|
def database_exception_handler(
|
@@ -34,7 +34,6 @@ maleo_foundation/managers/client/google/__init__.py
|
|
34
34
|
maleo_foundation/managers/client/google/base.py
|
35
35
|
maleo_foundation/managers/client/google/secret.py
|
36
36
|
maleo_foundation/managers/client/google/storage.py
|
37
|
-
maleo_foundation/middlewares/__init__.py
|
38
37
|
maleo_foundation/middlewares/authentication.py
|
39
38
|
maleo_foundation/middlewares/base.py
|
40
39
|
maleo_foundation/middlewares/cors.py
|
@@ -1,98 +0,0 @@
|
|
1
|
-
from fastapi import FastAPI
|
2
|
-
from logging import Logger
|
3
|
-
from typing import Optional, Sequence
|
4
|
-
from .base import add_base_middleware, RequestProcessor
|
5
|
-
from .cors import add_cors_middleware
|
6
|
-
|
7
|
-
class MiddlewareManager:
|
8
|
-
_default_limit:int = 10
|
9
|
-
_default_window:int = 1
|
10
|
-
_default_cleanup_interval:int = 60
|
11
|
-
_default_ip_timeout:int = 300
|
12
|
-
_default_allow_origins:Sequence[str] = ()
|
13
|
-
_default_allow_methods:Sequence[str] = ("GET",)
|
14
|
-
_default_allow_headers:Sequence[str] = ()
|
15
|
-
_default_allow_credentials:bool = False
|
16
|
-
_default_expose_headers:Sequence[str] = ()
|
17
|
-
_default_request_processor:Optional[RequestProcessor] = None
|
18
|
-
|
19
|
-
def __init__(self, app:FastAPI):
|
20
|
-
self.app = app
|
21
|
-
|
22
|
-
def add_all_middlewares(
|
23
|
-
self,
|
24
|
-
logger:Logger,
|
25
|
-
limit:int = _default_limit,
|
26
|
-
window:int = _default_window,
|
27
|
-
cleanup_interval:int = _default_cleanup_interval,
|
28
|
-
ip_timeout:int = _default_ip_timeout,
|
29
|
-
allow_origins:Sequence[str] = _default_allow_origins,
|
30
|
-
allow_methods:Sequence[str] = _default_allow_methods,
|
31
|
-
allow_headers:Sequence[str] = _default_allow_headers,
|
32
|
-
allow_credentials:bool = _default_allow_credentials,
|
33
|
-
expose_headers:Sequence[str] = _default_expose_headers,
|
34
|
-
request_processor:Optional[RequestProcessor] = _default_request_processor
|
35
|
-
):
|
36
|
-
self.add_cors_middleware(
|
37
|
-
allow_origins=allow_origins,
|
38
|
-
allow_methods=allow_methods,
|
39
|
-
allow_headers=allow_headers,
|
40
|
-
allow_credentials=allow_credentials,
|
41
|
-
expose_headers=expose_headers
|
42
|
-
)
|
43
|
-
self.add_base_middleware(
|
44
|
-
logger=logger,
|
45
|
-
allow_origins=allow_origins,
|
46
|
-
allow_methods=allow_methods,
|
47
|
-
allow_headers=allow_headers,
|
48
|
-
allow_credentials=allow_credentials,
|
49
|
-
limit=limit,
|
50
|
-
window=window,
|
51
|
-
cleanup_interval=cleanup_interval,
|
52
|
-
ip_timeout=ip_timeout,
|
53
|
-
request_processor=request_processor
|
54
|
-
)
|
55
|
-
|
56
|
-
def add_cors_middleware(
|
57
|
-
self,
|
58
|
-
allow_origins:Sequence[str] = _default_allow_origins,
|
59
|
-
allow_methods:Sequence[str] = _default_allow_methods,
|
60
|
-
allow_headers:Sequence[str] = _default_allow_headers,
|
61
|
-
allow_credentials:bool = _default_allow_credentials,
|
62
|
-
expose_headers:Sequence[str] = _default_expose_headers
|
63
|
-
):
|
64
|
-
add_cors_middleware(
|
65
|
-
app=self.app,
|
66
|
-
allow_origins=allow_origins,
|
67
|
-
allow_methods=allow_methods,
|
68
|
-
allow_headers=allow_headers,
|
69
|
-
allow_credentials=allow_credentials,
|
70
|
-
expose_headers=expose_headers
|
71
|
-
)
|
72
|
-
|
73
|
-
def add_base_middleware(
|
74
|
-
self,
|
75
|
-
logger:Logger,
|
76
|
-
allow_origins:Sequence[str] = _default_allow_origins,
|
77
|
-
allow_methods:Sequence[str] = _default_allow_methods,
|
78
|
-
allow_headers:Sequence[str] = _default_allow_headers,
|
79
|
-
allow_credentials:bool = _default_allow_credentials,
|
80
|
-
limit:int = _default_limit,
|
81
|
-
window:int = _default_window,
|
82
|
-
cleanup_interval:int = _default_cleanup_interval,
|
83
|
-
ip_timeout:int = _default_ip_timeout,
|
84
|
-
request_processor:Optional[RequestProcessor] = _default_request_processor
|
85
|
-
):
|
86
|
-
add_base_middleware(
|
87
|
-
app=self.app,
|
88
|
-
logger=logger,
|
89
|
-
allow_origins=allow_origins,
|
90
|
-
allow_methods=allow_methods,
|
91
|
-
allow_headers=allow_headers,
|
92
|
-
allow_credentials=allow_credentials,
|
93
|
-
limit=limit,
|
94
|
-
window=window,
|
95
|
-
cleanup_interval=cleanup_interval,
|
96
|
-
ip_timeout=ip_timeout,
|
97
|
-
request_processor=request_processor
|
98
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/client/services/token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/client.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/general.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/query.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/service.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/expanded_types/token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/base.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/google/base.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/managers/client/maleo.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/general.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/parameter.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/result.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/signature.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/schemas/token.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/models/transfers/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/formatter/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/formatter/case.py
RENAMED
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation/utils/loaders/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.67 → maleo_foundation-0.1.69}/maleo_foundation.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|