maleo-foundation 0.1.1__tar.gz → 0.1.2__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.1 → maleo_foundation-0.1.2}/PKG-INFO +1 -1
- maleo_foundation-0.1.2/maleo_foundation/clients/utils/logger.py +54 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/base.py +1 -1
- maleo_foundation-0.1.2/maleo_foundation/managers/client/http.py +82 -0
- maleo_foundation-0.1.2/maleo_foundation/managers/client/maleo.py +112 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/service.py +26 -3
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/services/token.py +0 -14
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/PKG-INFO +1 -1
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/SOURCES.txt +1 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/pyproject.toml +1 -1
- maleo_foundation-0.1.1/maleo_foundation/clients/utils/logger.py +0 -54
- maleo_foundation-0.1.1/maleo_foundation/managers/client/http.py +0 -40
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/README.md +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/general/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/general/http.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/base.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/base.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/logging.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/secret.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/storage.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/secret.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/storage.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/utils/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/constants.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/db/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/db/engine.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/db/manager.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/db/session.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/db/table.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/enums.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/client.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/general.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/query.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/service.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/token.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/extended_types.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/base.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/secret.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/storage.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/db.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/middlewares/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/middlewares/base.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/middlewares/cors.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/responses.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/general.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/parameter.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/result.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/token.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/general/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/general/token.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/parameters/client.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/parameters/general.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/parameters/service.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/parameters/token.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/client/service.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/service/general.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/service/query.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/token.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/services/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/types.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/controller.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/exceptions.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/formatter/__init__.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/formatter/case.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/keyloader.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/logger.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/logging.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/query.py +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/dependency_links.txt +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/requires.txt +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/top_level.txt +0 -0
- {maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/setup.cfg +0 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
# from typing import Dict
|
2
|
+
# from maleo_foundation.enums import BaseEnums
|
3
|
+
# from maleo_foundation.types import BaseTypes
|
4
|
+
# from maleo_foundation.utils.logger import BaseLogger
|
5
|
+
|
6
|
+
# class ClientLoggerManager:
|
7
|
+
# _loggers:Dict[type, BaseLogger] = {}
|
8
|
+
|
9
|
+
# @classmethod
|
10
|
+
# def initialize(
|
11
|
+
# cls,
|
12
|
+
# base_dir:str,
|
13
|
+
# client_name:str,
|
14
|
+
# service_name:BaseTypes.OptionalString = None,
|
15
|
+
# level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
|
16
|
+
# ) -> BaseLogger:
|
17
|
+
# """Initialize client logger if not already initialized."""
|
18
|
+
# if cls not in cls._loggers:
|
19
|
+
# cls._loggers[cls] = BaseLogger(
|
20
|
+
# base_dir=base_dir,
|
21
|
+
# type=BaseEnums.LoggerType.CLIENT,
|
22
|
+
# service_name=service_name,
|
23
|
+
# client_name=client_name,
|
24
|
+
# level=level
|
25
|
+
# )
|
26
|
+
# return cls._loggers[cls]
|
27
|
+
|
28
|
+
# @classmethod
|
29
|
+
# def get(cls) -> BaseLogger:
|
30
|
+
# """Return client logger (if exist) or raise Runtime Error"""
|
31
|
+
# if cls not in cls._loggers:
|
32
|
+
# raise RuntimeError("Logger has not been initialized. Call 'initialize' first.")
|
33
|
+
# return cls._loggers[cls]
|
34
|
+
|
35
|
+
# class MaleoFoundationLoggerManager(ClientLoggerManager):
|
36
|
+
# @classmethod
|
37
|
+
# def initialize(
|
38
|
+
# cls,
|
39
|
+
# base_dir:str,
|
40
|
+
# service_name:BaseTypes.OptionalString = None,
|
41
|
+
# level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
|
42
|
+
# ) -> BaseLogger:
|
43
|
+
# """Initialize MaleoFoundation's client logger if not already initialized."""
|
44
|
+
# return super().initialize(
|
45
|
+
# base_dir=base_dir,
|
46
|
+
# client_name="MaleoFoundation",
|
47
|
+
# service_name=service_name,
|
48
|
+
# level=level
|
49
|
+
# )
|
50
|
+
|
51
|
+
# @classmethod
|
52
|
+
# def get(cls) -> BaseLogger:
|
53
|
+
# """Return client logger (if exist) or raise Runtime Error"""
|
54
|
+
# return super().get()
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import httpx
|
2
|
+
from contextlib import asynccontextmanager
|
3
|
+
from pydantic import BaseModel, Field
|
4
|
+
from typing import AsyncGenerator, Optional
|
5
|
+
from maleo_foundation.managers.client.base import ClientManager
|
6
|
+
|
7
|
+
class HTTPClientManager:
|
8
|
+
_client:Optional[httpx.AsyncClient] = None
|
9
|
+
|
10
|
+
@classmethod
|
11
|
+
def initialize(cls) -> None:
|
12
|
+
"""Initialize the HTTP client if not already initialized."""
|
13
|
+
if cls._client is None:
|
14
|
+
cls._client = httpx.AsyncClient()
|
15
|
+
|
16
|
+
@classmethod
|
17
|
+
async def _client_handler(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
18
|
+
"""Reusable generator for client handling."""
|
19
|
+
if cls._client is None:
|
20
|
+
raise RuntimeError("Client has not been initialized. Call initialize first.")
|
21
|
+
yield cls._client
|
22
|
+
|
23
|
+
@classmethod
|
24
|
+
async def inject_client(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
25
|
+
return cls._client_handler()
|
26
|
+
|
27
|
+
@classmethod
|
28
|
+
@asynccontextmanager
|
29
|
+
async def get_client(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
30
|
+
"""
|
31
|
+
Async context manager for manual HTTP client handling.
|
32
|
+
Supports `async with HTTPClientManager.get() as client:`
|
33
|
+
"""
|
34
|
+
async for client in cls._client_handler():
|
35
|
+
yield client
|
36
|
+
|
37
|
+
@classmethod
|
38
|
+
def get_base_url(cls) -> str:
|
39
|
+
raise NotImplementedError()
|
40
|
+
|
41
|
+
@classmethod
|
42
|
+
async def dispose(cls) -> None:
|
43
|
+
"""Dispose of the HTTP client and release any resources."""
|
44
|
+
if cls._client is not None:
|
45
|
+
await cls._client.aclose()
|
46
|
+
cls._client = None
|
47
|
+
|
48
|
+
class URL(BaseModel):
|
49
|
+
base:str = Field(..., "Base URL")
|
50
|
+
|
51
|
+
@property
|
52
|
+
def api(self) -> str:
|
53
|
+
return f"{self.base}/api"
|
54
|
+
|
55
|
+
class HTTPClientManagerV2(ClientManager):
|
56
|
+
def __init__(self, key, name, logs_dir, google_cloud_logging = None):
|
57
|
+
super().__init__(key, name, logs_dir, google_cloud_logging)
|
58
|
+
self._client = httpx.AsyncClient()
|
59
|
+
|
60
|
+
async def _client_handler(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
61
|
+
"""Reusable generator for client handling."""
|
62
|
+
yield self._client
|
63
|
+
|
64
|
+
async def inject_client(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
65
|
+
return self._client_handler()
|
66
|
+
|
67
|
+
@asynccontextmanager
|
68
|
+
async def get_client(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
69
|
+
"""
|
70
|
+
Async context manager for manual HTTP client handling.
|
71
|
+
Supports `async with HTTPClientManager.get() as client:`
|
72
|
+
"""
|
73
|
+
async for client in self._client_handler():
|
74
|
+
yield client
|
75
|
+
|
76
|
+
@property
|
77
|
+
def client(self) -> httpx.AsyncClient:
|
78
|
+
return self._client
|
79
|
+
|
80
|
+
@property
|
81
|
+
def url(self) -> URL:
|
82
|
+
raise NotImplementedError()
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import httpx
|
2
|
+
from contextlib import asynccontextmanager
|
3
|
+
from pydantic import BaseModel, Field
|
4
|
+
from typing import AsyncGenerator
|
5
|
+
from maleo_foundation.types import BaseTypes
|
6
|
+
from maleo_foundation.utils.logging import ClientLogger
|
7
|
+
from maleo_foundation.managers.client.base import ClientManager
|
8
|
+
|
9
|
+
class URL(BaseModel):
|
10
|
+
base:str = Field(..., "Base URL")
|
11
|
+
|
12
|
+
@property
|
13
|
+
def api(self) -> str:
|
14
|
+
return f"{self.base}/api"
|
15
|
+
|
16
|
+
class HTTPClientControllerManager:
|
17
|
+
def __init__(self, base_url:str) -> None:
|
18
|
+
self._client = httpx.AsyncClient()
|
19
|
+
self._url = URL(base=base_url)
|
20
|
+
|
21
|
+
async def _client_handler(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
22
|
+
"""Reusable generator for client handling."""
|
23
|
+
yield self._client
|
24
|
+
|
25
|
+
async def inject_client(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
26
|
+
return self._client_handler()
|
27
|
+
|
28
|
+
@asynccontextmanager
|
29
|
+
async def get_client(self) -> AsyncGenerator[httpx.AsyncClient, None]:
|
30
|
+
"""
|
31
|
+
Async context manager for manual HTTP client handling.
|
32
|
+
Supports `async with HTTPClientManager.get() as client:`
|
33
|
+
"""
|
34
|
+
async for client in self._client_handler():
|
35
|
+
yield client
|
36
|
+
|
37
|
+
@property
|
38
|
+
def client(self) -> httpx.AsyncClient:
|
39
|
+
return self._client
|
40
|
+
|
41
|
+
@property
|
42
|
+
def url(self) -> URL:
|
43
|
+
return self._url
|
44
|
+
|
45
|
+
class ClientControllerManagers(BaseModel):
|
46
|
+
http:HTTPClientControllerManager = Field(..., description="HTTP Client Controller")
|
47
|
+
|
48
|
+
class Config:
|
49
|
+
arbitrary_types_allowed=True
|
50
|
+
|
51
|
+
class HTTPClientController:
|
52
|
+
def __init__(self, manager:HTTPClientControllerManager):
|
53
|
+
self._manager = manager
|
54
|
+
|
55
|
+
@property
|
56
|
+
def manager(self) -> HTTPClientControllerManager:
|
57
|
+
return self._manager
|
58
|
+
|
59
|
+
class ClientServiceControllers(BaseModel):
|
60
|
+
http:HTTPClientController = Field(..., description="HTTP Client Controller")
|
61
|
+
|
62
|
+
class Config:
|
63
|
+
arbitrary_types_allowed=True
|
64
|
+
|
65
|
+
class ClientControllers(BaseModel):
|
66
|
+
#* Reuse this class while also adding all controllers of the client
|
67
|
+
class Config:
|
68
|
+
arbitrary_types_allowed=True
|
69
|
+
|
70
|
+
class ClientService:
|
71
|
+
def __init__(self, controllers:ClientServiceControllers, logger:ClientLogger):
|
72
|
+
self._controllers = controllers
|
73
|
+
self._logger = logger
|
74
|
+
|
75
|
+
@property
|
76
|
+
def controllers(self) -> ClientServiceControllers:
|
77
|
+
return self._controllers
|
78
|
+
|
79
|
+
@property
|
80
|
+
def logger(self) -> ClientLogger:
|
81
|
+
return self._logger
|
82
|
+
|
83
|
+
class ClientServices(BaseModel):
|
84
|
+
#* Reuse this class while also adding all the services of the client
|
85
|
+
class Config:
|
86
|
+
arbitrary_types_allowed=True
|
87
|
+
|
88
|
+
class MaleoClientManager(ClientManager):
|
89
|
+
def __init__(self, key, name, logs_dir, google_cloud_logging = None, base_url:BaseTypes.OptionalString = None):
|
90
|
+
super().__init__(key, name, logs_dir, google_cloud_logging)
|
91
|
+
self._base_url = base_url
|
92
|
+
|
93
|
+
def _initialize_controllers(self) -> None:
|
94
|
+
#* Initialize managers
|
95
|
+
http_controller_manager = HTTPClientControllerManager(base_url=self._base_url)
|
96
|
+
self._controller_managers = ClientControllerManagers(http=http_controller_manager)
|
97
|
+
#* Initialize controllers
|
98
|
+
#! This initialied an empty controllers. Extend this function in the actual class to initialize all controllers.
|
99
|
+
self._controllers = ClientControllers()
|
100
|
+
|
101
|
+
@property
|
102
|
+
def controllers(self) -> ClientControllers:
|
103
|
+
raise self._controllers
|
104
|
+
|
105
|
+
def _initialize_services(self) -> None:
|
106
|
+
#* Initialize services
|
107
|
+
#! This initialied an empty services. Extend this function in the actual class to initialize all services.
|
108
|
+
self._services = ClientServices()
|
109
|
+
|
110
|
+
@property
|
111
|
+
def services(self) -> ClientServices:
|
112
|
+
return self._services
|
@@ -11,6 +11,7 @@ from maleo_foundation.models.transfers.parameters.token import BaseTokenParamete
|
|
11
11
|
from maleo_foundation.managers.client.google.secret import GoogleSecretManager
|
12
12
|
from maleo_foundation.managers.client.google.storage import GoogleCloudStorage
|
13
13
|
from maleo_foundation.managers.client.http import HTTPClientManager
|
14
|
+
from maleo_foundation.managers.client.maleo import MaleoClientManager
|
14
15
|
from maleo_foundation.managers.db import DatabaseManager
|
15
16
|
from maleo_foundation.services.token import BaseTokenService
|
16
17
|
from maleo_foundation.types import BaseTypes
|
@@ -102,9 +103,24 @@ class GoogleClientManagers(BaseModel):
|
|
102
103
|
class Config:
|
103
104
|
arbitrary_types_allowed=True
|
104
105
|
|
106
|
+
class MaleoClientManagers(BaseModel):
|
107
|
+
metadata:Optional[MaleoClientManager] = Field(None, description="MaleoMetadata client manager")
|
108
|
+
security:Optional[MaleoClientManager] = Field(None, description="MaleoSecurity client manager")
|
109
|
+
storage:Optional[MaleoClientManager] = Field(None, description="MaleoStorage client manager")
|
110
|
+
identity:Optional[MaleoClientManager] = Field(None, description="MaleoIdentity client manager")
|
111
|
+
access:Optional[MaleoClientManager] = Field(None, description="MaleoAccess client manager")
|
112
|
+
soapie:Optional[MaleoClientManager] = Field(None, description="MaleoSOAPIE client manager")
|
113
|
+
fhir:Optional[MaleoClientManager] = Field(None, description="MaleoFHIR client manager")
|
114
|
+
dicom:Optional[MaleoClientManager] = Field(None, description="MaleoDICOM client manager")
|
115
|
+
scribe:Optional[MaleoClientManager] = Field(None, description="MaleoScribe client manager")
|
116
|
+
cds:Optional[MaleoClientManager] = Field(None, description="MaleoCDS client manager")
|
117
|
+
imaging:Optional[MaleoClientManager] = Field(None, description="MaleoImaging client manager")
|
118
|
+
mcu:Optional[MaleoClientManager] = Field(None, description="MaleoMCU client manager")
|
119
|
+
|
105
120
|
class ClientManagers(BaseModel):
|
106
121
|
google:GoogleClientManagers = Field(..., description="Google client's managers")
|
107
122
|
http:Type[HTTPClientManager] = Field(..., description="HTTP client's manager")
|
123
|
+
maleo:MaleoClientManagers = Field(..., description="Maleo client's managers")
|
108
124
|
|
109
125
|
class Config:
|
110
126
|
arbitrary_types_allowed=True
|
@@ -116,7 +132,8 @@ class ServiceManager:
|
|
116
132
|
base_dir:BaseTypes.OptionalString = None,
|
117
133
|
settings:Optional[Settings] = None,
|
118
134
|
google_cloud_logging:Optional[GoogleCloudLogging] = None,
|
119
|
-
client_logger_managers:ClientLoggerManagers = {}
|
135
|
+
client_logger_managers:ClientLoggerManagers = {},
|
136
|
+
maleo_client_managers:Optional[MaleoClientManagers] = None
|
120
137
|
):
|
121
138
|
self._db_metadata = db_metadata
|
122
139
|
|
@@ -147,6 +164,12 @@ class ServiceManager:
|
|
147
164
|
self._load_credentials()
|
148
165
|
self._parse_keys()
|
149
166
|
self._initialize_db()
|
167
|
+
|
168
|
+
#* Initialize maleo client managers
|
169
|
+
if maleo_client_managers is None:
|
170
|
+
self._maleo_client_managers = MaleoClientManagers()
|
171
|
+
else:
|
172
|
+
self._maleo_client_managers = maleo_client_managers
|
150
173
|
self._initialize_clients()
|
151
174
|
|
152
175
|
@property
|
@@ -177,7 +200,7 @@ class ServiceManager:
|
|
177
200
|
client = self._client_logger_managers
|
178
201
|
for key, logger_manager in client.items():
|
179
202
|
application.info(f"Initializing logger manager for client '{key}'")
|
180
|
-
logger_manager.initialize()
|
203
|
+
logger_manager.initialize(logs_dir=self._logs_dir ,client_key=key)
|
181
204
|
self._loggers = Loggers(application=application, database=database, middleware=middleware, client=client)
|
182
205
|
|
183
206
|
@property
|
@@ -234,7 +257,7 @@ class ServiceManager:
|
|
234
257
|
#* Initialize http clients
|
235
258
|
self._http_client = HTTPClientManager
|
236
259
|
self._http_client.initialize()
|
237
|
-
self._clients = ClientManagers(google=self._google_clients, http=self._http_client)
|
260
|
+
self._clients = ClientManagers(google=self._google_clients, http=self._http_client, maleo=self._maleo_client_managers)
|
238
261
|
|
239
262
|
@property
|
240
263
|
def google_clients(self) -> GoogleClientManagers:
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import jwt
|
2
2
|
from cryptography.hazmat.primitives import serialization
|
3
3
|
from cryptography.hazmat.backends import default_backend
|
4
|
-
# from maleo_foundation.clients.utils.logger import MaleoFoundationLoggerManager
|
5
|
-
# from maleo_foundation.utils.exceptions import BaseExceptions
|
6
4
|
from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
|
7
5
|
from maleo_foundation.models.schemas.token import BaseTokenSchemas
|
8
6
|
from maleo_foundation.models.transfers.parameters.token import BaseTokenParametersTransfers
|
@@ -11,11 +9,6 @@ from maleo_foundation.expanded_types.token import BaseTokenResultsTypes
|
|
11
9
|
|
12
10
|
class BaseTokenService:
|
13
11
|
@staticmethod
|
14
|
-
# @BaseExceptions.service_exception_handler(
|
15
|
-
# operation="encoding a payload",
|
16
|
-
# logger_factory=MaleoFoundationLoggerManager.get,
|
17
|
-
# fail_result_class=BaseTokenResultsTransfers.Fail
|
18
|
-
# )
|
19
12
|
def encode(parameters:BaseTokenParametersTransfers.Encode) -> BaseTokenResultsTypes.Encode:
|
20
13
|
#* Serialize private key
|
21
14
|
private_key_bytes = parameters.key.encode()
|
@@ -27,17 +20,10 @@ class BaseTokenService:
|
|
27
20
|
payload = BaseTokenGeneralTransfers.EncodePayload.model_validate(parameters.payload.model_dump()).model_dump(mode="json")
|
28
21
|
token = jwt.encode(payload=payload, key=private_key, algorithm="RS256")
|
29
22
|
data = BaseTokenSchemas.Token(token=token)
|
30
|
-
# MaleoFoundationLoggerManager.get().info("Payload successfully encoded")
|
31
23
|
return BaseTokenResultsTransfers.Encode(data=data)
|
32
24
|
|
33
25
|
@staticmethod
|
34
|
-
# @BaseExceptions.service_exception_handler(
|
35
|
-
# operation="decoding a token",
|
36
|
-
# logger_factory=MaleoFoundationLoggerManager.get,
|
37
|
-
# fail_result_class=BaseTokenResultsTransfers.Fail
|
38
|
-
# )
|
39
26
|
def decode(parameters:BaseTokenParametersTransfers.Decode) -> BaseTokenResultsTypes.Decode:
|
40
27
|
payload = jwt.decode(jwt=parameters.token, key=parameters.key, algorithms=["RS256"])
|
41
28
|
data = BaseTokenGeneralTransfers.DecodePayload.model_validate(payload)
|
42
|
-
# MaleoFoundationLoggerManager.get().info("Token successfully decoded")
|
43
29
|
return BaseTokenResultsTransfers.Decode(data=data)
|
@@ -41,6 +41,7 @@ maleo_foundation/managers/service.py
|
|
41
41
|
maleo_foundation/managers/client/__init__.py
|
42
42
|
maleo_foundation/managers/client/base.py
|
43
43
|
maleo_foundation/managers/client/http.py
|
44
|
+
maleo_foundation/managers/client/maleo.py
|
44
45
|
maleo_foundation/managers/client/google/__init__.py
|
45
46
|
maleo_foundation/managers/client/google/base.py
|
46
47
|
maleo_foundation/managers/client/google/secret.py
|
@@ -1,54 +0,0 @@
|
|
1
|
-
from typing import Dict
|
2
|
-
from maleo_foundation.enums import BaseEnums
|
3
|
-
from maleo_foundation.types import BaseTypes
|
4
|
-
from maleo_foundation.utils.logger import BaseLogger
|
5
|
-
|
6
|
-
class ClientLoggerManager:
|
7
|
-
_loggers:Dict[type, BaseLogger] = {}
|
8
|
-
|
9
|
-
@classmethod
|
10
|
-
def initialize(
|
11
|
-
cls,
|
12
|
-
base_dir:str,
|
13
|
-
client_name:str,
|
14
|
-
service_name:BaseTypes.OptionalString = None,
|
15
|
-
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
|
16
|
-
) -> BaseLogger:
|
17
|
-
"""Initialize client logger if not already initialized."""
|
18
|
-
if cls not in cls._loggers:
|
19
|
-
cls._loggers[cls] = BaseLogger(
|
20
|
-
base_dir=base_dir,
|
21
|
-
type=BaseEnums.LoggerType.CLIENT,
|
22
|
-
service_name=service_name,
|
23
|
-
client_name=client_name,
|
24
|
-
level=level
|
25
|
-
)
|
26
|
-
return cls._loggers[cls]
|
27
|
-
|
28
|
-
@classmethod
|
29
|
-
def get(cls) -> BaseLogger:
|
30
|
-
"""Return client logger (if exist) or raise Runtime Error"""
|
31
|
-
if cls not in cls._loggers:
|
32
|
-
raise RuntimeError("Logger has not been initialized. Call 'initialize' first.")
|
33
|
-
return cls._loggers[cls]
|
34
|
-
|
35
|
-
class MaleoFoundationLoggerManager(ClientLoggerManager):
|
36
|
-
@classmethod
|
37
|
-
def initialize(
|
38
|
-
cls,
|
39
|
-
base_dir:str,
|
40
|
-
service_name:BaseTypes.OptionalString = None,
|
41
|
-
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO
|
42
|
-
) -> BaseLogger:
|
43
|
-
"""Initialize MaleoFoundation's client logger if not already initialized."""
|
44
|
-
return super().initialize(
|
45
|
-
base_dir=base_dir,
|
46
|
-
client_name="MaleoFoundation",
|
47
|
-
service_name=service_name,
|
48
|
-
level=level
|
49
|
-
)
|
50
|
-
|
51
|
-
@classmethod
|
52
|
-
def get(cls) -> BaseLogger:
|
53
|
-
"""Return client logger (if exist) or raise Runtime Error"""
|
54
|
-
return super().get()
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import httpx
|
2
|
-
from contextlib import asynccontextmanager
|
3
|
-
from typing import AsyncGenerator, Optional
|
4
|
-
|
5
|
-
class HTTPClientManager:
|
6
|
-
_client:Optional[httpx.AsyncClient] = None
|
7
|
-
|
8
|
-
@classmethod
|
9
|
-
def initialize(cls) -> None:
|
10
|
-
"""Initialize the HTTP client if not already initialized."""
|
11
|
-
if cls._client is None:
|
12
|
-
cls._client = httpx.AsyncClient()
|
13
|
-
|
14
|
-
@classmethod
|
15
|
-
async def _client_handler(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
16
|
-
"""Reusable generator for client handling."""
|
17
|
-
if cls._client is None:
|
18
|
-
raise RuntimeError("Client has not been initialized. Call initialize first.")
|
19
|
-
yield cls._client
|
20
|
-
|
21
|
-
@classmethod
|
22
|
-
async def inject_client(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
23
|
-
return cls._client_handler()
|
24
|
-
|
25
|
-
@classmethod
|
26
|
-
@asynccontextmanager
|
27
|
-
async def get_client(cls) -> AsyncGenerator[httpx.AsyncClient, None]:
|
28
|
-
"""
|
29
|
-
Async context manager for manual HTTP client handling.
|
30
|
-
Supports `async with HTTPClientManager.get() as client:`
|
31
|
-
"""
|
32
|
-
async for client in cls._client_handler():
|
33
|
-
yield client
|
34
|
-
|
35
|
-
@classmethod
|
36
|
-
async def dispose(cls) -> None:
|
37
|
-
"""Dispose of the HTTP client and release any resources."""
|
38
|
-
if cls._client is not None:
|
39
|
-
await cls._client.aclose()
|
40
|
-
cls._client = None
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/general/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/base.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/logging.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/secret.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/cloud/storage.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/google/storage.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/clients/utils/__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
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/general.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/expanded_types/service.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/base.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/secret.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/managers/client/google/storage.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.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/__init__.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/general.py
RENAMED
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/schemas/parameter.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/__init__.py
RENAMED
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/general/token.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
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/models/transfers/results/token.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation/utils/formatter/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{maleo_foundation-0.1.1 → maleo_foundation-0.1.2}/maleo_foundation.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|