maleo-foundation 0.1.22__py3-none-any.whl → 0.1.24__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/enums.py +5 -0
- maleo_foundation/managers/middleware.py +4 -13
- maleo_foundation/managers/service.py +18 -1
- maleo_foundation/middlewares/authentication.py +7 -4
- {maleo_foundation-0.1.22.dist-info → maleo_foundation-0.1.24.dist-info}/METADATA +1 -1
- {maleo_foundation-0.1.22.dist-info → maleo_foundation-0.1.24.dist-info}/RECORD +8 -8
- {maleo_foundation-0.1.22.dist-info → maleo_foundation-0.1.24.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.1.22.dist-info → maleo_foundation-0.1.24.dist-info}/top_level.txt +0 -0
maleo_foundation/enums.py
CHANGED
@@ -3,6 +3,11 @@ from enum import IntEnum, StrEnum, Enum
|
|
3
3
|
from fastapi import responses
|
4
4
|
|
5
5
|
class BaseEnums:
|
6
|
+
class EnvironmentType(StrEnum):
|
7
|
+
LOCAL = "local"
|
8
|
+
STAGING = "staging"
|
9
|
+
PRODUCTION = "production"
|
10
|
+
|
6
11
|
class StatusType(StrEnum):
|
7
12
|
DELETED = "deleted"
|
8
13
|
INACTIVE = "inactive"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from fastapi import FastAPI
|
2
2
|
from pydantic import BaseModel, Field
|
3
3
|
from typing import List, Optional
|
4
|
-
from maleo_foundation.middlewares.authentication import
|
4
|
+
from maleo_foundation.middlewares.authentication import add_authentication_middleware
|
5
5
|
from maleo_foundation.middlewares.base import add_base_middleware, RequestProcessor
|
6
6
|
from maleo_foundation.middlewares.cors import add_cors_middleware
|
7
7
|
from maleo_foundation.utils.logging import MiddlewareLogger
|
@@ -46,16 +46,11 @@ class MiddlewareManager:
|
|
46
46
|
self,
|
47
47
|
loggers:MiddlewareLoggers,
|
48
48
|
key:str,
|
49
|
-
authentication_backend:Optional[Backend] = None,
|
50
49
|
request_processor:Optional[RequestProcessor] = None
|
51
50
|
):
|
52
51
|
self.add_cors()
|
53
52
|
self.add_base(logger=loggers.base, request_processor=request_processor)
|
54
|
-
|
55
|
-
self._authentication_backend = Backend(logger=loggers.authentication, key=key)
|
56
|
-
else:
|
57
|
-
self._authentication_backend = authentication_backend
|
58
|
-
self.add_authentication(backend=self._authentication_backend)
|
53
|
+
self.add_authentication(logger=loggers.authentication, key=key)
|
59
54
|
|
60
55
|
def add_cors(self) -> None:
|
61
56
|
add_cors_middleware(
|
@@ -82,9 +77,5 @@ class MiddlewareManager:
|
|
82
77
|
request_processor=request_processor
|
83
78
|
)
|
84
79
|
|
85
|
-
def add_authentication(self, logger:MiddlewareLogger, key:str
|
86
|
-
|
87
|
-
self._authentication_backend = Backend(logger=logger, key=key)
|
88
|
-
else:
|
89
|
-
self._authentication_backend = backend
|
90
|
-
add_authentication_middleware(app=self._app, backend=self._authentication_backend)
|
80
|
+
def add_authentication(self, logger:MiddlewareLogger, key:str):
|
81
|
+
add_authentication_middleware(app=self._app, logger=logger, key=key)
|
@@ -33,6 +33,7 @@ class LogConfig(BaseModel):
|
|
33
33
|
arbitrary_types_allowed=True
|
34
34
|
|
35
35
|
class Settings(BaseSettings):
|
36
|
+
ENVIRONMENT:BaseEnums.EnvironmentType = Field(..., description="Environment")
|
36
37
|
GOOGLE_CREDENTIALS_PATH:str = Field("/creds/maleo-google-service-account.json", description="Internal credential's file path")
|
37
38
|
INTERNAL_CREDENTIALS_PATH:str = Field("/creds/maleo-internal-service-account.json", description="Internal credential's file path")
|
38
39
|
PRIVATE_KEY_PATH:str = Field("/keys/maleo-private-key.pem", description="Maleo's private key path")
|
@@ -383,7 +384,23 @@ class ServiceManager:
|
|
383
384
|
return self._app
|
384
385
|
|
385
386
|
def run_app(self) -> None:
|
386
|
-
|
387
|
+
if self._settings.ENVIRONMENT == BaseEnums.EnvironmentType.LOCAL:
|
388
|
+
import importlib.util
|
389
|
+
import sys
|
390
|
+
# Get the module path and add it to sys.path if needed
|
391
|
+
spec = importlib.util.find_spec("app")
|
392
|
+
if spec and spec.origin:
|
393
|
+
module_path = os.path.dirname(os.path.dirname(spec.origin))
|
394
|
+
if module_path not in sys.path:
|
395
|
+
sys.path.insert(0, module_path)
|
396
|
+
|
397
|
+
# Create the import string for uvicorn
|
398
|
+
app_import_string = "app.main:app"
|
399
|
+
|
400
|
+
# Run with reload enabled
|
401
|
+
uvicorn.run(app_import_string, host=self._configs.service.host, port=self._configs.service.port, reload=True)
|
402
|
+
else:
|
403
|
+
uvicorn.run(self._app, host=self._configs.service.host, port=self._configs.service.port)
|
387
404
|
|
388
405
|
async def dispose(self) -> None:
|
389
406
|
self._loggers.application.info("Disposing service manager")
|
@@ -36,7 +36,7 @@ class Backend(AuthenticationBackend):
|
|
36
36
|
self._logger.info(f"Authentication - Request | IP: {client_ip} | URL: {conn.url.path} - Result | Username: {decode_token_result.data.u_u} | Email: {decode_token_result.data.u_e}")
|
37
37
|
return Credentials(token=token), User(authenticated=True, username=decode_token_result.data.u_u, email=decode_token_result.data.u_e)
|
38
38
|
|
39
|
-
def add_authentication_middleware(app:FastAPI,
|
39
|
+
def add_authentication_middleware(app:FastAPI, logger:MiddlewareLogger, key:str) -> None:
|
40
40
|
"""
|
41
41
|
Adds Authentication middleware to the FastAPI application.
|
42
42
|
|
@@ -44,8 +44,11 @@ def add_authentication_middleware(app:FastAPI, backend:Backend) -> None:
|
|
44
44
|
app: FastAPI
|
45
45
|
The FastAPI application instance to which the middleware will be added.
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
logger: MiddlewareLogger
|
48
|
+
Authentication middleware logger to be used.
|
49
|
+
|
50
|
+
key: str
|
51
|
+
Public key to be used for token decoding.
|
49
52
|
|
50
53
|
Returns:
|
51
54
|
None: The function modifies the FastAPI app by adding Base middleware.
|
@@ -59,4 +62,4 @@ def add_authentication_middleware(app:FastAPI, backend:Backend) -> None:
|
|
59
62
|
add_authentication_middleware(app=app, limit=10, window=1, cleanup_interval=60, ip_timeout=300)
|
60
63
|
```
|
61
64
|
"""
|
62
|
-
app.add_middleware(AuthenticationMiddleware, backend=
|
65
|
+
app.add_middleware(AuthenticationMiddleware, backend=Backend(logger=logger, key=key))
|
@@ -1,7 +1,7 @@
|
|
1
1
|
maleo_foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
maleo_foundation/authentication.py,sha256=iwc9cGGi5srW3goPRyuZjoPvdyA3XPgYzIEbVl-IW78,842
|
3
3
|
maleo_foundation/constants.py,sha256=aBmEfWlBqZxi0k-n6h2NM1YRLOjMnheEiLyQcjP-zCQ,1164
|
4
|
-
maleo_foundation/enums.py,sha256=
|
4
|
+
maleo_foundation/enums.py,sha256=uvwl3dl2r6BoJMEbtSETiLoyJubHup9Lc7VOg7w7zQo,2943
|
5
5
|
maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBmdc-L4,301
|
6
6
|
maleo_foundation/types.py,sha256=aKXnIgEhYGSfFqNMGLc4qIKGkINBRpkOo9R9cb2CbwI,2414
|
7
7
|
maleo_foundation/clients/__init__.py,sha256=W8vydJYeDEi6gdmOZSBFSSDsfZJtb8C05CHErZgsZ30,188
|
@@ -31,8 +31,8 @@ maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rv
|
|
31
31
|
maleo_foundation/expanded_types/token.py,sha256=4fRTJw6W5MYq71NksNrWNi7qYHQ4_lQwfu9WxwrMipc,355
|
32
32
|
maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
33
|
maleo_foundation/managers/db.py,sha256=Jf0w-9JOAG5X2quDxqqw6d2WUIX7MYGdlPGxWP0rxHs,4699
|
34
|
-
maleo_foundation/managers/middleware.py,sha256=
|
35
|
-
maleo_foundation/managers/service.py,sha256=
|
34
|
+
maleo_foundation/managers/middleware.py,sha256=7CDXPMb28AR7J72TWOeKFxOlMypKezEtO9mr53a88B0,4032
|
35
|
+
maleo_foundation/managers/service.py,sha256=DLp2y7tPQVyBCg8TB5nraeDz4Z5uX-Tr-9thA49QhuE,20040
|
36
36
|
maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
37
37
|
maleo_foundation/managers/client/base.py,sha256=K8AFV2MTZrC1jbTqxkx7eedmxodJirNIjoRXGGcppy4,1022
|
38
38
|
maleo_foundation/managers/client/http.py,sha256=dWFZlG1z4TERYBITReR5oSrlzvdhh2EtztVnsU8gCeA,2712
|
@@ -42,7 +42,7 @@ maleo_foundation/managers/client/google/base.py,sha256=1lrGoyGnYW5Xq05bVXbKqnsqq
|
|
42
42
|
maleo_foundation/managers/client/google/secret.py,sha256=bWR_3Xl_wUFqj4M48w8ZE692U7PQKX9ap0ndDJviV80,3074
|
43
43
|
maleo_foundation/managers/client/google/storage.py,sha256=041iSSaFubnZrP-pS8MiLVtOgeLQ591Iz64JekZ5K7o,2350
|
44
44
|
maleo_foundation/middlewares/__init__.py,sha256=bqE2EIFC3rWcR2AwFPR0fk2kSFfeTRzgA24GbnuT5RA,3697
|
45
|
-
maleo_foundation/middlewares/authentication.py,sha256=
|
45
|
+
maleo_foundation/middlewares/authentication.py,sha256=y67sWz6FLl6NAtUWyK4mxC661dsBeKsDYRH3o7L_ZFQ,3188
|
46
46
|
maleo_foundation/middlewares/base.py,sha256=3OaB5F57F3epKNieoAgarYM6PimoUdUl3DgpadtVuqs,11743
|
47
47
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
48
48
|
maleo_foundation/models/__init__.py,sha256=AaKehO7c1HyKhoTGRmNHDddSeBXkW-_YNrpOGBu8Ms8,246
|
@@ -83,7 +83,7 @@ maleo_foundation/utils/logging.py,sha256=MwvZmZSA8SIdfq-knEvpYIgqnSpHcyHrZY9TVHW
|
|
83
83
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
84
84
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
85
85
|
maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
|
86
|
-
maleo_foundation-0.1.
|
87
|
-
maleo_foundation-0.1.
|
88
|
-
maleo_foundation-0.1.
|
89
|
-
maleo_foundation-0.1.
|
86
|
+
maleo_foundation-0.1.24.dist-info/METADATA,sha256=7yxL5FgFIua_89OydBwsndTLQPfKvMqAZamurVMUHnE,3190
|
87
|
+
maleo_foundation-0.1.24.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
88
|
+
maleo_foundation-0.1.24.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
89
|
+
maleo_foundation-0.1.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|