maleo-foundation 0.1.68__py3-none-any.whl → 0.1.69__py3-none-any.whl
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/middlewares/authentication.py +0 -6
- maleo_foundation/models/responses.py +2 -1
- maleo_foundation/utils/exceptions.py +3 -5
- {maleo_foundation-0.1.68.dist-info → maleo_foundation-0.1.69.dist-info}/METADATA +1 -1
- {maleo_foundation-0.1.68.dist-info → maleo_foundation-0.1.69.dist-info}/RECORD +7 -7
- {maleo_foundation-0.1.68.dist-info → maleo_foundation-0.1.69.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.1.68.dist-info → maleo_foundation-0.1.69.dist-info}/top_level.txt +0 -0
@@ -9,7 +9,6 @@ from maleo_foundation.client.manager import MaleoFoundationClientManager
|
|
9
9
|
from maleo_foundation.models.schemas import BaseGeneralSchemas
|
10
10
|
from maleo_foundation.models.transfers.parameters.token import BaseTokenParametersTransfers
|
11
11
|
from maleo_foundation.utils.exceptions import BaseExceptions
|
12
|
-
from maleo_foundation.utils.extractor import BaseExtractors
|
13
12
|
from maleo_foundation.utils.logging import MiddlewareLogger
|
14
13
|
|
15
14
|
class Backend(AuthenticationBackend):
|
@@ -20,26 +19,21 @@ class Backend(AuthenticationBackend):
|
|
20
19
|
self._maleo_foundation = maleo_foundation
|
21
20
|
|
22
21
|
async def authenticate(self, conn:HTTPConnection) -> Tuple[Credentials, User]:
|
23
|
-
client_ip = BaseExtractors.extract_client_ip(conn)
|
24
22
|
if "Authorization" not in conn.headers:
|
25
|
-
self._logger.info(f"Request | IP: {client_ip} | URL: {conn.url.path} - Result | General: Header did not contain authorization")
|
26
23
|
return Credentials(), User(authenticated=False)
|
27
24
|
|
28
25
|
auth = conn.headers["Authorization"]
|
29
26
|
scheme, token = auth.split()
|
30
27
|
if scheme != 'Bearer':
|
31
|
-
self._logger.info(f"Request | IP: {client_ip} | URL: {conn.url.path} - Result | General: Authorization scheme is not Bearer")
|
32
28
|
raise AuthenticationError("Authorization scheme must be Bearer token")
|
33
29
|
|
34
30
|
decode_token_parameters = BaseTokenParametersTransfers.Decode(key=self._keys.public, token=token)
|
35
31
|
decode_token_result = self._maleo_foundation.services.token.decode(parameters=decode_token_parameters)
|
36
32
|
if not decode_token_result.success:
|
37
|
-
self._logger.error(f"Request | IP: {client_ip} | URL: {conn.url.path} - Result | General: Failed decoding authorization token")
|
38
33
|
raise AuthenticationError("Invalid Bearer token, unable to decode token")
|
39
34
|
if decode_token_result.data.exp_dt <= datetime.now(tz=timezone.utc):
|
40
35
|
raise AuthenticationError("Expired Bearer token, request new or refresh token")
|
41
36
|
|
42
|
-
self._logger.info(f"Request | IP: {client_ip} | URL: {conn.url.path} - Result | Username: {decode_token_result.data.u_u} | Email: {decode_token_result.data.u_e}")
|
43
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)
|
44
38
|
|
45
39
|
def add_authentication_middleware(app:FastAPI, keys:BaseGeneralSchemas.RSAKeys, logger:MiddlewareLogger, maleo_foundation:MaleoFoundationClientManager) -> None:
|
@@ -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
|
@@ -21,11 +21,9 @@ class BaseExceptions:
|
|
21
21
|
|
22
22
|
@staticmethod
|
23
23
|
async def http_exception_handler(request:Request, exc:StarletteHTTPException):
|
24
|
-
if exc.status_code
|
25
|
-
return JSONResponse(content=BaseResponses.
|
26
|
-
|
27
|
-
#* Handle other HTTP exceptions normally
|
28
|
-
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)
|
29
27
|
|
30
28
|
@staticmethod
|
31
29
|
def database_exception_handler(
|
@@ -27,11 +27,11 @@ maleo_foundation/managers/client/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5J
|
|
27
27
|
maleo_foundation/managers/client/google/base.py,sha256=j3W18Pmcu9jJ5wK12bbWBI6r8cVt5f7QmGU9uIJgKrU,1249
|
28
28
|
maleo_foundation/managers/client/google/secret.py,sha256=Uh01RoOp8QOIvu8X4AGJzOJRlrfAeXHO8ZFvmKo7A-E,3114
|
29
29
|
maleo_foundation/managers/client/google/storage.py,sha256=MPuVpLTl0QJhlBOqpxv5UtD3ANO1WCCE1sRrfHnlCZM,2355
|
30
|
-
maleo_foundation/middlewares/authentication.py,sha256=
|
30
|
+
maleo_foundation/middlewares/authentication.py,sha256=zIq4zeQnrogSURqQDtOMAx7D1cMCcG6ZScYyaFw7onM,3173
|
31
31
|
maleo_foundation/middlewares/base.py,sha256=0ntvQ5G7sFIYKPRItSODs9-zqneQ_Reg2WtHGsziRwc,13164
|
32
32
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
33
33
|
maleo_foundation/models/__init__.py,sha256=AaKehO7c1HyKhoTGRmNHDddSeBXkW-_YNrpOGBu8Ms8,246
|
34
|
-
maleo_foundation/models/responses.py,sha256=
|
34
|
+
maleo_foundation/models/responses.py,sha256=yKK_5p0dYCnUx-09mRKHkBv485bcngaCp9lwTSp_y4A,4846
|
35
35
|
maleo_foundation/models/table.py,sha256=Dk5GXeO0gbBBPN2PJtZhlUx2x3vMbT4dxTBc3YLBbuc,1199
|
36
36
|
maleo_foundation/models/schemas/__init__.py,sha256=Xj8Ahsqyra-fmEaVcGPok5GOOsPQlKcknHYMvbjvENA,277
|
37
37
|
maleo_foundation/models/schemas/general.py,sha256=KGPP67ciKeL8cvOS3kYrVwmRx3kD33OcS88UmMn1JPE,3822
|
@@ -63,7 +63,7 @@ maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256
|
|
63
63
|
maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
|
64
64
|
maleo_foundation/utils/__init__.py,sha256=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZMdOthY,520
|
65
65
|
maleo_foundation/utils/controller.py,sha256=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUUX6ipXBg,6396
|
66
|
-
maleo_foundation/utils/exceptions.py,sha256=
|
66
|
+
maleo_foundation/utils/exceptions.py,sha256=hstsXST24mbJLuDtAfcdC0FxMgH3IkG97A026CvaX-w,4034
|
67
67
|
maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
|
68
68
|
maleo_foundation/utils/logging.py,sha256=bBi73GTwRK8Ll4m5vSNHGymXUrbRsSNQYZ1vF7Iq1z8,8052
|
69
69
|
maleo_foundation/utils/mergers.py,sha256=DniUu3Ot4qkYH_YSw4uD1cn9cfirum4S_Opp8fMkQwA,702
|
@@ -74,7 +74,7 @@ maleo_foundation/utils/loaders/__init__.py,sha256=Dnuv7BWyglSddnbsFb96s-b3KaW7UK
|
|
74
74
|
maleo_foundation/utils/loaders/json.py,sha256=NsXLq3VZSgzmEf99tV1VtrmiudWdQ8Pzh_hI4Rm0cM8,397
|
75
75
|
maleo_foundation/utils/loaders/key.py,sha256=GZ4h1ONfp6Xx8-E8AWoGP4ajAZrwPhZRtidjn_u82Qg,2562
|
76
76
|
maleo_foundation/utils/loaders/yaml.py,sha256=jr8v3BlgmRCMTzdNgKhIYt1tnubaJXcDSSGkKVR8pbw,362
|
77
|
-
maleo_foundation-0.1.
|
78
|
-
maleo_foundation-0.1.
|
79
|
-
maleo_foundation-0.1.
|
80
|
-
maleo_foundation-0.1.
|
77
|
+
maleo_foundation-0.1.69.dist-info/METADATA,sha256=zP9UT6LTPNd2Pi64NaL5L3p0YWrZFsm8T2tJr75DTdI,3390
|
78
|
+
maleo_foundation-0.1.69.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
79
|
+
maleo_foundation-0.1.69.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
80
|
+
maleo_foundation-0.1.69.dist-info/RECORD,,
|
File without changes
|
File without changes
|