maleo-foundation 0.1.43__py3-none-any.whl → 0.1.45__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/managers/client/base.py +9 -19
- maleo_foundation/managers/client/google/base.py +3 -8
- maleo_foundation/managers/client/google/secret.py +4 -16
- maleo_foundation/managers/client/google/storage.py +5 -18
- maleo_foundation/managers/client/maleo.py +6 -10
- maleo_foundation/managers/db.py +22 -1
- maleo_foundation/managers/service.py +9 -170
- maleo_foundation/utils/logging.py +18 -43
- {maleo_foundation-0.1.43.dist-info → maleo_foundation-0.1.45.dist-info}/METADATA +1 -1
- {maleo_foundation-0.1.43.dist-info → maleo_foundation-0.1.45.dist-info}/RECORD +12 -12
- {maleo_foundation-0.1.43.dist-info → maleo_foundation-0.1.45.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.1.43.dist-info → maleo_foundation-0.1.45.dist-info}/top_level.txt +0 -0
@@ -1,35 +1,21 @@
|
|
1
|
-
from
|
2
|
-
from maleo_foundation.
|
3
|
-
from maleo_foundation.types import BaseTypes
|
4
|
-
from maleo_foundation.utils.logging import GoogleCloudLogging, ClientLogger
|
1
|
+
from maleo_foundation.utils.logging import ClientLogger
|
2
|
+
from maleo_foundation.managers.service import ServiceManager
|
5
3
|
|
6
4
|
class ClientManager:
|
7
5
|
def __init__(
|
8
6
|
self,
|
9
7
|
key:str,
|
10
8
|
name:str,
|
11
|
-
|
12
|
-
service_key:BaseTypes.OptionalString = None,
|
13
|
-
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
14
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
9
|
+
service_manager:ServiceManager
|
15
10
|
) -> None:
|
16
11
|
self._key = key
|
17
12
|
self._name = name
|
18
|
-
self.
|
19
|
-
self._service_key = service_key
|
20
|
-
self._level = level
|
21
|
-
self._google_cloud_logging = google_cloud_logging
|
13
|
+
self._service_manager = service_manager
|
22
14
|
self._initialize_logger()
|
23
15
|
self._logger.info("Initializing client manager")
|
24
16
|
|
25
17
|
def _initialize_logger(self) -> None:
|
26
|
-
self._logger = ClientLogger(
|
27
|
-
logs_dir=self._logs_dir,
|
28
|
-
client_key=self._key,
|
29
|
-
service_key=self._service_key,
|
30
|
-
level=self._level,
|
31
|
-
google_cloud_logging=self._google_cloud_logging
|
32
|
-
)
|
18
|
+
self._logger = ClientLogger(client_key=self._key, service_key=self._service_manager.configs.service.key, **self._service_manager.log_config.model_dump())
|
33
19
|
|
34
20
|
@property
|
35
21
|
def key(self) -> str:
|
@@ -39,6 +25,10 @@ class ClientManager:
|
|
39
25
|
def name(self) -> str:
|
40
26
|
return self._name
|
41
27
|
|
28
|
+
@property
|
29
|
+
def service_manager(self) -> ServiceManager:
|
30
|
+
return self._service_manager
|
31
|
+
|
42
32
|
@property
|
43
33
|
def logger(self) -> ClientLogger:
|
44
34
|
return self._logger
|
@@ -1,24 +1,19 @@
|
|
1
1
|
import os
|
2
2
|
from google.auth import default
|
3
3
|
from google.oauth2 import service_account
|
4
|
-
from typing import Optional
|
5
|
-
from maleo_foundation.enums import BaseEnums
|
6
4
|
from maleo_foundation.types import BaseTypes
|
7
5
|
from maleo_foundation.managers.client.base import ClientManager
|
8
|
-
from maleo_foundation.
|
6
|
+
from maleo_foundation.managers.service import ServiceManager
|
9
7
|
|
10
8
|
class GoogleClientManager(ClientManager):
|
11
9
|
def __init__(
|
12
10
|
self,
|
13
11
|
key:str,
|
14
12
|
name:str,
|
15
|
-
|
16
|
-
service_key:BaseTypes.OptionalString=None,
|
17
|
-
level:BaseEnums.LoggerLevel=BaseEnums.LoggerLevel.INFO,
|
18
|
-
google_cloud_logging:Optional[GoogleCloudLogging]=None,
|
13
|
+
service_manager:ServiceManager,
|
19
14
|
credentials_path:BaseTypes.OptionalString=None
|
20
15
|
) -> None:
|
21
|
-
super().__init__(key, name,
|
16
|
+
super().__init__(key, name, service_manager)
|
22
17
|
credentials_path = credentials_path or os.getenv("GOOGLE_CREDENTIALS_PATH")
|
23
18
|
try:
|
24
19
|
if credentials_path is not None:
|
@@ -2,31 +2,19 @@ from google.api_core import retry
|
|
2
2
|
from google.api_core.exceptions import NotFound
|
3
3
|
from google.cloud import secretmanager
|
4
4
|
from typing import Optional
|
5
|
-
from maleo_foundation.enums import BaseEnums
|
6
5
|
from maleo_foundation.types import BaseTypes
|
7
|
-
from maleo_foundation.
|
6
|
+
from maleo_foundation.managers.service import ServiceManager
|
8
7
|
from .base import GoogleClientManager
|
9
8
|
|
10
9
|
class GoogleSecretManager(GoogleClientManager):
|
11
10
|
def __init__(
|
12
11
|
self,
|
13
|
-
|
14
|
-
|
15
|
-
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
16
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None,
|
17
|
-
credentials_path:BaseTypes.OptionalString=None
|
12
|
+
service_manager:ServiceManager,
|
13
|
+
credentials_path:BaseTypes.OptionalString = None
|
18
14
|
) -> None:
|
19
15
|
key = "google-secret-manager"
|
20
16
|
name = "GoogleSecretManager"
|
21
|
-
super().__init__(
|
22
|
-
key=key,
|
23
|
-
name=name,
|
24
|
-
logs_dir=logs_dir,
|
25
|
-
service_key=service_key,
|
26
|
-
level=level,
|
27
|
-
google_cloud_logging=google_cloud_logging,
|
28
|
-
credentials_path=credentials_path
|
29
|
-
)
|
17
|
+
super().__init__(key, name, service_manager, credentials_path)
|
30
18
|
self._client = secretmanager.SecretManagerServiceClient(credentials=self._credentials)
|
31
19
|
self._logger.info("Client manager initialized successfully")
|
32
20
|
|
@@ -1,33 +1,20 @@
|
|
1
1
|
import os
|
2
2
|
from datetime import timedelta
|
3
3
|
from google.cloud.storage import Bucket, Client
|
4
|
-
from typing import Optional
|
5
|
-
from maleo_foundation.enums import BaseEnums
|
6
4
|
from maleo_foundation.types import BaseTypes
|
7
|
-
from maleo_foundation.
|
5
|
+
from maleo_foundation.managers.service import ServiceManager
|
8
6
|
from .base import GoogleClientManager
|
9
7
|
|
10
8
|
class GoogleCloudStorage(GoogleClientManager):
|
11
9
|
def __init__(
|
12
10
|
self,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None,
|
17
|
-
credentials_path:BaseTypes.OptionalString=None,
|
18
|
-
bucket_name:BaseTypes.OptionalString=None
|
11
|
+
service_manager:ServiceManager,
|
12
|
+
credentials_path:BaseTypes.OptionalString = None,
|
13
|
+
bucket_name:BaseTypes.OptionalString = None
|
19
14
|
) -> None:
|
20
15
|
key = "google-cloud-storage"
|
21
16
|
name = "GoogleCloudStorage"
|
22
|
-
super().__init__(
|
23
|
-
key=key,
|
24
|
-
name=name,
|
25
|
-
logs_dir=logs_dir,
|
26
|
-
service_key=service_key,
|
27
|
-
level=level,
|
28
|
-
google_cloud_logging=google_cloud_logging,
|
29
|
-
credentials_path=credentials_path
|
30
|
-
)
|
17
|
+
super().__init__(key, name, service_manager, credentials_path)
|
31
18
|
self._client = Client(credentials=self._credentials)
|
32
19
|
self._bucket_name = bucket_name or os.getenv("GCS_BUCKET_NAME")
|
33
20
|
if self._bucket_name is None:
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import httpx
|
2
2
|
from contextlib import asynccontextmanager
|
3
3
|
from pydantic import BaseModel, Field
|
4
|
-
from typing import AsyncGenerator
|
5
|
-
from maleo_foundation.
|
6
|
-
from maleo_foundation.types import BaseTypes
|
7
|
-
from maleo_foundation.utils.logging import GoogleCloudLogging, ClientLogger
|
4
|
+
from typing import AsyncGenerator
|
5
|
+
from maleo_foundation.utils.logging import ClientLogger
|
8
6
|
from maleo_foundation.managers.client.base import ClientManager
|
7
|
+
from maleo_foundation.managers.service import ServiceManager
|
9
8
|
|
10
9
|
class URL(BaseModel):
|
11
10
|
base:str = Field(..., description="Base URL")
|
@@ -93,13 +92,10 @@ class MaleoClientManager(ClientManager):
|
|
93
92
|
self,
|
94
93
|
key:str,
|
95
94
|
name:str,
|
96
|
-
|
97
|
-
|
98
|
-
level:BaseEnums.LoggerLevel=BaseEnums.LoggerLevel.INFO,
|
99
|
-
google_cloud_logging:Optional[GoogleCloudLogging]=None,
|
100
|
-
url:BaseTypes.OptionalString = None
|
95
|
+
url:str,
|
96
|
+
service_manager:ServiceManager
|
101
97
|
):
|
102
|
-
super().__init__(key, name,
|
98
|
+
super().__init__(key, name, service_manager)
|
103
99
|
self._url = url
|
104
100
|
|
105
101
|
def _initialize_controllers(self) -> None:
|
maleo_foundation/managers/db.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import os
|
2
2
|
from contextlib import contextmanager
|
3
|
+
from pydantic import BaseModel, Field, model_validator
|
3
4
|
from sqlalchemy import MetaData
|
4
5
|
from sqlalchemy.engine import Engine, create_engine
|
5
6
|
from sqlalchemy.exc import SQLAlchemyError
|
6
7
|
from sqlalchemy.ext.declarative import DeclarativeMeta
|
7
8
|
from sqlalchemy.orm import sessionmaker, Session, declarative_base
|
8
|
-
from typing import Generator
|
9
|
+
from typing import Dict, Generator
|
9
10
|
from maleo_foundation.types import BaseTypes
|
10
11
|
from maleo_foundation.utils.logging import ServiceLogger
|
11
12
|
|
@@ -57,6 +58,26 @@ class SessionManager:
|
|
57
58
|
self._logger.info("SessionManager disposed successfully")
|
58
59
|
self._logger = None
|
59
60
|
|
61
|
+
class DatabaseConfigurations(BaseModel):
|
62
|
+
username:str = Field("postgres", description="Database user's username")
|
63
|
+
password:str = Field(..., description="Database user's password")
|
64
|
+
host:str = Field(..., description="Database's host")
|
65
|
+
port:int = Field(5432, description="Database's port")
|
66
|
+
database:str = Field(..., description="Database")
|
67
|
+
|
68
|
+
@model_validator(mode='before')
|
69
|
+
@classmethod
|
70
|
+
def populate_password(cls, values:Dict):
|
71
|
+
env_value = os.getenv("DB_PASSWORD")
|
72
|
+
if env_value is None:
|
73
|
+
raise ValueError("'DB_PASSWORD' environmet variable must be set.")
|
74
|
+
values["password"] = env_value
|
75
|
+
return values
|
76
|
+
|
77
|
+
@property
|
78
|
+
def url(self) -> str:
|
79
|
+
return f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
|
80
|
+
|
60
81
|
class DatabaseManager:
|
61
82
|
def __init__(
|
62
83
|
self,
|
@@ -1,38 +1,25 @@
|
|
1
|
-
import json
|
2
|
-
import os
|
3
1
|
from fastapi import FastAPI, APIRouter
|
4
2
|
from fastapi.exceptions import RequestValidationError
|
5
3
|
from starlette.exceptions import HTTPException
|
6
4
|
from starlette.types import Lifespan, AppType
|
7
5
|
from pydantic_settings import BaseSettings
|
8
|
-
from pydantic import BaseModel, Field
|
6
|
+
from pydantic import BaseModel, Field
|
9
7
|
from sqlalchemy import MetaData
|
10
|
-
from typing import
|
8
|
+
from typing import Optional
|
11
9
|
from maleo_foundation.enums import BaseEnums
|
12
10
|
from maleo_foundation.models.transfers.general.token import BaseTokenGeneralTransfers
|
13
11
|
from maleo_foundation.models.transfers.parameters.token import BaseTokenParametersTransfers
|
14
|
-
from maleo_foundation.managers.
|
15
|
-
from maleo_foundation.managers.client.google.storage import GoogleCloudStorage
|
16
|
-
from maleo_foundation.managers.client.maleo import MaleoClientManager
|
17
|
-
from maleo_foundation.managers.db import DatabaseManager
|
12
|
+
from maleo_foundation.managers.db import DatabaseConfigurations, DatabaseManager
|
18
13
|
from maleo_foundation.managers.middleware import MiddlewareConfigurations, BaseMiddlewareConfigurations, CORSMiddlewareConfigurations, GeneralMiddlewareConfigurations, MiddlewareLoggers, MiddlewareManager
|
19
14
|
from maleo_foundation.middlewares.base import RequestProcessor
|
20
15
|
from maleo_foundation.services.token import BaseTokenService
|
21
|
-
from maleo_foundation.types import BaseTypes
|
22
16
|
from maleo_foundation.utils.exceptions import BaseExceptions
|
23
17
|
from maleo_foundation.utils.loaders.json import JSONLoader
|
24
18
|
from maleo_foundation.utils.loaders.key import KeyLoader
|
25
19
|
from maleo_foundation.utils.loaders.yaml import YAMLLoader
|
26
|
-
from maleo_foundation.utils.logging import
|
20
|
+
from maleo_foundation.utils.logging import SimpleConfig, ServiceLogger, MiddlewareLogger
|
27
21
|
from maleo_foundation.utils.mergers import BaseMergers
|
28
22
|
|
29
|
-
class LogConfig(BaseModel):
|
30
|
-
logs_dir:str = Field(..., description="Logs directory")
|
31
|
-
google_cloud_logging:GoogleCloudLogging = Field(..., description="Google cloud's logging")
|
32
|
-
|
33
|
-
class Config:
|
34
|
-
arbitrary_types_allowed=True
|
35
|
-
|
36
23
|
class Settings(BaseSettings):
|
37
24
|
ENVIRONMENT:BaseEnums.EnvironmentType = Field(..., description="Environment")
|
38
25
|
GOOGLE_CREDENTIALS_PATH:str = Field("credentials/maleo-google-service-account.json", description="Internal credential's file path")
|
@@ -87,26 +74,6 @@ class ServiceConfigurations(BaseModel):
|
|
87
74
|
host:str = Field(..., description="Service's host")
|
88
75
|
port:int = Field(..., description="Service's port")
|
89
76
|
|
90
|
-
class DatabaseConfigurations(BaseModel):
|
91
|
-
username:str = Field("postgres", description="Database user's username")
|
92
|
-
password:str = Field(..., description="Database user's password")
|
93
|
-
host:str = Field(..., description="Database's host")
|
94
|
-
port:int = Field(5432, description="Database's port")
|
95
|
-
database:str = Field(..., description="Database")
|
96
|
-
|
97
|
-
@model_validator(mode='before')
|
98
|
-
@classmethod
|
99
|
-
def populate_password(cls, values:Dict):
|
100
|
-
env_value = os.getenv("DB_PASSWORD")
|
101
|
-
if env_value is None:
|
102
|
-
raise ValueError("'DB_PASSWORD' environmet variable must be set.")
|
103
|
-
values["password"] = env_value
|
104
|
-
return values
|
105
|
-
|
106
|
-
@property
|
107
|
-
def url(self) -> str:
|
108
|
-
return f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
|
109
|
-
|
110
77
|
class RuntimeConfigurations(BaseModel):
|
111
78
|
service:ServiceConfigurations = Field(..., description="Service's configurations")
|
112
79
|
middleware:MiddlewareRuntimeConfigurations = Field(..., description="Middleware's runtime configurations")
|
@@ -181,71 +148,14 @@ class Loggers(BaseModel):
|
|
181
148
|
class Config:
|
182
149
|
arbitrary_types_allowed=True
|
183
150
|
|
184
|
-
class GoogleClientManagers(BaseModel):
|
185
|
-
secret:GoogleSecretManager = Field(..., description="Google secret manager client manager")
|
186
|
-
storage:GoogleCloudStorage = Field(..., description="Google cloud storage client manager")
|
187
|
-
|
188
|
-
class Config:
|
189
|
-
arbitrary_types_allowed=True
|
190
|
-
|
191
|
-
class MaleoClientManagerClasses(BaseModel):
|
192
|
-
metadata:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoMetadata client manager")
|
193
|
-
security:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoSecurity client manager")
|
194
|
-
storage:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoStorage client manager")
|
195
|
-
identity:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoIdentity client manager")
|
196
|
-
access:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoAccess client manager")
|
197
|
-
soapie:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoSOAPIE client manager")
|
198
|
-
fhir:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoFHIR client manager")
|
199
|
-
dicom:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoDICOM client manager")
|
200
|
-
scribe:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoScribe client manager")
|
201
|
-
cds:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoCDS client manager")
|
202
|
-
imaging:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoImaging client manager")
|
203
|
-
mcu:Optional[Type[MaleoClientManager]] = Field(None, description="MaleoMCU client manager")
|
204
|
-
|
205
|
-
class Config:
|
206
|
-
arbitrary_types_allowed=True
|
207
|
-
|
208
|
-
class MaleoClientManagers(BaseModel):
|
209
|
-
metadata:Optional[MaleoClientManager] = Field(None, description="MaleoMetadata client manager")
|
210
|
-
security:Optional[MaleoClientManager] = Field(None, description="MaleoSecurity client manager")
|
211
|
-
storage:Optional[MaleoClientManager] = Field(None, description="MaleoStorage client manager")
|
212
|
-
identity:Optional[MaleoClientManager] = Field(None, description="MaleoIdentity client manager")
|
213
|
-
access:Optional[MaleoClientManager] = Field(None, description="MaleoAccess client manager")
|
214
|
-
soapie:Optional[MaleoClientManager] = Field(None, description="MaleoSOAPIE client manager")
|
215
|
-
fhir:Optional[MaleoClientManager] = Field(None, description="MaleoFHIR client manager")
|
216
|
-
dicom:Optional[MaleoClientManager] = Field(None, description="MaleoDICOM client manager")
|
217
|
-
scribe:Optional[MaleoClientManager] = Field(None, description="MaleoScribe client manager")
|
218
|
-
cds:Optional[MaleoClientManager] = Field(None, description="MaleoCDS client manager")
|
219
|
-
imaging:Optional[MaleoClientManager] = Field(None, description="MaleoImaging client manager")
|
220
|
-
mcu:Optional[MaleoClientManager] = Field(None, description="MaleoMCU client manager")
|
221
|
-
|
222
|
-
class Config:
|
223
|
-
arbitrary_types_allowed=True
|
224
|
-
|
225
|
-
class ClientManagers(BaseModel):
|
226
|
-
google:GoogleClientManagers = Field(..., description="Google client's managers")
|
227
|
-
maleo:MaleoClientManagers = Field(..., description="Maleo client's managers")
|
228
|
-
|
229
|
-
class Config:
|
230
|
-
arbitrary_types_allowed=True
|
231
|
-
|
232
151
|
class ServiceManager:
|
233
152
|
def __init__(
|
234
153
|
self,
|
235
154
|
db_metadata:MetaData,
|
236
|
-
|
237
|
-
settings:Optional[Settings] = None
|
238
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None,
|
239
|
-
maleo_client_manager_classes:Optional[MaleoClientManagerClasses] = None
|
155
|
+
log_config:SimpleConfig,
|
156
|
+
settings:Optional[Settings] = None
|
240
157
|
):
|
241
|
-
self._db_metadata = db_metadata
|
242
|
-
|
243
|
-
if base_dir is None:
|
244
|
-
self._base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
245
|
-
else:
|
246
|
-
self._base_dir = base_dir
|
247
|
-
|
248
|
-
self._logs_dir = os.path.join(self._base_dir, "logs")
|
158
|
+
self._db_metadata = db_metadata #* Declare DB Metadata
|
249
159
|
|
250
160
|
#* Initialize settings
|
251
161
|
if settings is None:
|
@@ -253,42 +163,15 @@ class ServiceManager:
|
|
253
163
|
else:
|
254
164
|
self._settings = settings
|
255
165
|
|
256
|
-
#* Load configs
|
257
166
|
self._load_configs()
|
258
|
-
|
259
|
-
#* Initialize google cloud logging
|
260
|
-
if google_cloud_logging is None:
|
261
|
-
self._google_cloud_logging = GoogleCloudLogging()
|
262
|
-
else:
|
263
|
-
self._google_cloud_logging = google_cloud_logging
|
264
|
-
|
265
|
-
self._log_config = LogConfig(
|
266
|
-
logs_dir=self._logs_dir,
|
267
|
-
google_cloud_logging=self._google_cloud_logging
|
268
|
-
)
|
269
|
-
|
167
|
+
self._log_config = log_config #* Declare log config
|
270
168
|
self._initialize_loggers()
|
271
169
|
self._load_credentials()
|
272
170
|
self._parse_keys()
|
273
171
|
self._initialize_db()
|
274
172
|
|
275
|
-
#* Initialize maleo client managers
|
276
|
-
if maleo_client_manager_classes is None:
|
277
|
-
self._maleo_client_manager_classes = MaleoClientManagerClasses()
|
278
|
-
else:
|
279
|
-
self._maleo_client_manager_classes = maleo_client_manager_classes
|
280
|
-
self._initialize_clients()
|
281
|
-
|
282
|
-
@property
|
283
|
-
def base_dir(self) -> str:
|
284
|
-
return self._base_dir
|
285
|
-
|
286
|
-
@property
|
287
|
-
def logs_dir(self) -> str:
|
288
|
-
return self._logs_dir
|
289
|
-
|
290
173
|
@property
|
291
|
-
def log_config(self) ->
|
174
|
+
def log_config(self) -> SimpleConfig:
|
292
175
|
return self._log_config
|
293
176
|
|
294
177
|
@property
|
@@ -361,46 +244,6 @@ class ServiceManager:
|
|
361
244
|
def database(self) -> DatabaseManager:
|
362
245
|
return self._database
|
363
246
|
|
364
|
-
def _initialize_clients(self) -> None:
|
365
|
-
#* Initialize google clients
|
366
|
-
secret = GoogleSecretManager(
|
367
|
-
**self._log_config.model_dump(),
|
368
|
-
service_key=self._configs.service.key,
|
369
|
-
credentials_path=self._settings.GOOGLE_CREDENTIALS_PATH
|
370
|
-
)
|
371
|
-
storage = GoogleCloudStorage(
|
372
|
-
**self._log_config.model_dump(),
|
373
|
-
service_key=self._configs.service.key,
|
374
|
-
credentials_path=self._settings.GOOGLE_CREDENTIALS_PATH,
|
375
|
-
bucket_name=self._configs.client.google.storage.bucket_name
|
376
|
-
)
|
377
|
-
self._google_clients = GoogleClientManagers(secret=secret, storage=storage)
|
378
|
-
#* Initialize maleo clients
|
379
|
-
self._maleo_clients = MaleoClientManagers()
|
380
|
-
for client in self._maleo_client_manager_classes.__class__.__annotations__:
|
381
|
-
client_cls = getattr(self._maleo_client_manager_classes, client)
|
382
|
-
if client_cls is not None and issubclass(client_cls, MaleoClientManager):
|
383
|
-
cfg:MaleoClientConfiguration = getattr(self._configs.client.maleo, client)
|
384
|
-
client_instance = client_cls(
|
385
|
-
**cfg.model_dump(),
|
386
|
-
**self._log_config.model_dump(),
|
387
|
-
service_key=self._configs.service.key
|
388
|
-
)
|
389
|
-
setattr(self._maleo_clients, client, client_instance)
|
390
|
-
self._clients = ClientManagers(google=self._google_clients, maleo=self._maleo_clients)
|
391
|
-
|
392
|
-
@property
|
393
|
-
def google_clients(self) -> GoogleClientManagers:
|
394
|
-
return self._google_clients
|
395
|
-
|
396
|
-
@property
|
397
|
-
def maleo_clients(self) -> MaleoClientManagers:
|
398
|
-
return self._maleo_clients
|
399
|
-
|
400
|
-
@property
|
401
|
-
def clients(self) -> ClientManagers:
|
402
|
-
return self._clients
|
403
|
-
|
404
247
|
@property
|
405
248
|
def token(self) -> str:
|
406
249
|
payload = BaseTokenGeneralTransfers.BaseEncodePayload(
|
@@ -455,10 +298,6 @@ class ServiceManager:
|
|
455
298
|
if self._clients is not None:
|
456
299
|
self._clients.google.storage.dispose()
|
457
300
|
self._clients.google.secret.dispose()
|
458
|
-
for client in self._maleo_clients.__class__.__annotations__:
|
459
|
-
client_instance = getattr(self._maleo_clients, client)
|
460
|
-
if client_instance is not None and isinstance(client_instance, MaleoClientManager):
|
461
|
-
await client_instance.dispose()
|
462
301
|
self._loggers.application.info("Service manager disposed successfully")
|
463
302
|
if self._loggers is not None:
|
464
303
|
self._loggers.application.info("Disposing logger")
|
@@ -5,6 +5,7 @@ from google.auth import default
|
|
5
5
|
from google.cloud.logging import Client
|
6
6
|
from google.cloud.logging.handlers import CloudLoggingHandler
|
7
7
|
from google.oauth2 import service_account
|
8
|
+
from pydantic import BaseModel, Field
|
8
9
|
from typing import Optional
|
9
10
|
from maleo_foundation.enums import BaseEnums
|
10
11
|
from maleo_foundation.types import BaseTypes
|
@@ -39,10 +40,18 @@ class GoogleCloudLogging:
|
|
39
40
|
def create_handler(self, name:str) -> CloudLoggingHandler:
|
40
41
|
return CloudLoggingHandler(client=self._client, name=name)
|
41
42
|
|
43
|
+
class SimpleConfig(BaseModel):
|
44
|
+
dir:str = Field(..., description="Log's directory")
|
45
|
+
level:BaseEnums.LoggerLevel = Field(BaseEnums.LoggerLevel.INFO, description="Log's level")
|
46
|
+
google_cloud_logging:GoogleCloudLogging = Field(default_factory=GoogleCloudLogging, description="Google cloud logging")
|
47
|
+
|
48
|
+
class Config:
|
49
|
+
arbitrary_types_allowed=True
|
50
|
+
|
42
51
|
class BaseLogger(logging.Logger):
|
43
52
|
def __init__(
|
44
53
|
self,
|
45
|
-
|
54
|
+
dir:str,
|
46
55
|
type:BaseEnums.LoggerType,
|
47
56
|
service_key:BaseTypes.OptionalString = None,
|
48
57
|
middleware_type:Optional[BaseEnums.MiddlewareLoggerType] = None,
|
@@ -50,17 +59,6 @@ class BaseLogger(logging.Logger):
|
|
50
59
|
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
51
60
|
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
52
61
|
):
|
53
|
-
"""
|
54
|
-
Custom extended logger with file, console, and Google Cloud Logging.
|
55
|
-
|
56
|
-
- Logs are stored in `logs_dir/logs/{type}`
|
57
|
-
- Uses Google Cloud Logging if configured
|
58
|
-
|
59
|
-
Args:
|
60
|
-
logs_dir (str): Base directory for logs (e.g., "/path/to/service")
|
61
|
-
type (str): Log type (e.g., "application", "middleware")
|
62
|
-
service_key (str): The service name (e.g., "service")
|
63
|
-
"""
|
64
62
|
self._type = type #* Declare logger type
|
65
63
|
|
66
64
|
#* Ensure service_key exists
|
@@ -122,7 +120,7 @@ class BaseLogger(logging.Logger):
|
|
122
120
|
log_dir = f"{self._type}/{self._client_key}"
|
123
121
|
else:
|
124
122
|
log_dir = f"{self._type}"
|
125
|
-
self._log_dir = os.path.join(
|
123
|
+
self._log_dir = os.path.join(dir, log_dir)
|
126
124
|
os.makedirs(self._log_dir, exist_ok=True)
|
127
125
|
|
128
126
|
#* Generate timestamped filename
|
@@ -164,14 +162,14 @@ class BaseLogger(logging.Logger):
|
|
164
162
|
class MiddlewareLogger(BaseLogger):
|
165
163
|
def __init__(
|
166
164
|
self,
|
167
|
-
|
165
|
+
dir:str,
|
168
166
|
service_key:BaseTypes.OptionalString = None,
|
169
167
|
middleware_type = None,
|
170
168
|
level = BaseEnums.LoggerLevel.INFO,
|
171
169
|
google_cloud_logging = None
|
172
170
|
):
|
173
171
|
super().__init__(
|
174
|
-
|
172
|
+
dir=dir,
|
175
173
|
type=BaseEnums.LoggerType.MIDDLEWARE,
|
176
174
|
service_key=service_key,
|
177
175
|
middleware_type=middleware_type,
|
@@ -183,14 +181,14 @@ class MiddlewareLogger(BaseLogger):
|
|
183
181
|
class ServiceLogger(BaseLogger):
|
184
182
|
def __init__(
|
185
183
|
self,
|
186
|
-
|
184
|
+
dir:str,
|
187
185
|
type:BaseEnums.ServiceLoggerType,
|
188
186
|
service_key:BaseTypes.OptionalString = None,
|
189
187
|
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
190
188
|
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
191
189
|
):
|
192
190
|
super().__init__(
|
193
|
-
|
191
|
+
dir=dir,
|
194
192
|
type=type,
|
195
193
|
service_key=service_key,
|
196
194
|
middleware_type=None,
|
@@ -202,41 +200,18 @@ class ServiceLogger(BaseLogger):
|
|
202
200
|
class ClientLogger(BaseLogger):
|
203
201
|
def __init__(
|
204
202
|
self,
|
205
|
-
|
203
|
+
dir:str,
|
206
204
|
client_key:str,
|
207
205
|
service_key:BaseTypes.OptionalString = None,
|
208
206
|
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
209
207
|
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
210
208
|
):
|
211
209
|
super().__init__(
|
212
|
-
|
210
|
+
dir=dir,
|
213
211
|
type=BaseEnums.LoggerType.CLIENT,
|
214
212
|
service_key=service_key,
|
215
213
|
middleware_type=None,
|
216
214
|
client_key=client_key,
|
217
215
|
level=level,
|
218
216
|
google_cloud_logging=google_cloud_logging
|
219
|
-
)
|
220
|
-
|
221
|
-
class ClientLoggerManager:
|
222
|
-
_logger:Optional[ClientLogger] = None
|
223
|
-
|
224
|
-
@classmethod
|
225
|
-
def initialize(
|
226
|
-
cls,
|
227
|
-
logs_dir:str,
|
228
|
-
client_key:str,
|
229
|
-
service_key:BaseTypes.OptionalString = None,
|
230
|
-
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
231
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
232
|
-
) -> None:
|
233
|
-
"""Initialize client logger if not already initialized."""
|
234
|
-
if cls._logger is None:
|
235
|
-
cls.logger = ClientLogger(logs_dir=logs_dir, client_key=client_key, service_key=service_key, level=level, google_cloud_logging=google_cloud_logging)
|
236
|
-
|
237
|
-
@classmethod
|
238
|
-
def get(cls) -> ClientLogger:
|
239
|
-
"""Return client logger (if exist) or raise Runtime Error"""
|
240
|
-
if cls._logger is None:
|
241
|
-
raise RuntimeError("Logger has not been initialized. Initialize it first.")
|
242
|
-
return cls._logger
|
217
|
+
)
|
@@ -11,16 +11,16 @@ maleo_foundation/expanded_types/query.py,sha256=0yUG-JIVsanzB7KAkrRz_OsrhP6J0bRq
|
|
11
11
|
maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rveduk2cFWzuhGw,2416
|
12
12
|
maleo_foundation/expanded_types/token.py,sha256=4fRTJw6W5MYq71NksNrWNi7qYHQ4_lQwfu9WxwrMipc,355
|
13
13
|
maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
|
-
maleo_foundation/managers/db.py,sha256=
|
14
|
+
maleo_foundation/managers/db.py,sha256=lIOGE2qVofnJNqRJKaxFQ6Md3Lg5RB-oGqfZN-85diA,5522
|
15
15
|
maleo_foundation/managers/middleware.py,sha256=7CDXPMb28AR7J72TWOeKFxOlMypKezEtO9mr53a88B0,4032
|
16
|
-
maleo_foundation/managers/service.py,sha256=
|
16
|
+
maleo_foundation/managers/service.py,sha256=86pGrEldqkX8Krc9tiqpLD0oIXVzFuUYKwMFzZ5ZloE,15067
|
17
17
|
maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
-
maleo_foundation/managers/client/base.py,sha256=
|
19
|
-
maleo_foundation/managers/client/maleo.py,sha256=
|
18
|
+
maleo_foundation/managers/client/base.py,sha256=Z7_ANKbrlnShoZeSpP6N9Y0JLquDWG2FAedMvceYtt0,1120
|
19
|
+
maleo_foundation/managers/client/maleo.py,sha256=8-8pFqcv3xa9x1gJC71Bp_YlJ5jDSyqtzAzH0FOtHPI,3971
|
20
20
|
maleo_foundation/managers/client/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
-
maleo_foundation/managers/client/google/base.py,sha256=
|
22
|
-
maleo_foundation/managers/client/google/secret.py,sha256=
|
23
|
-
maleo_foundation/managers/client/google/storage.py,sha256=
|
21
|
+
maleo_foundation/managers/client/google/base.py,sha256=0_4MYc-clsnSS2hjwwe-DNaycmcwsoUeF9mm21GLpbI,1202
|
22
|
+
maleo_foundation/managers/client/google/secret.py,sha256=BNRE-VnD3GTgRtUQg2zzaitYHZ_yThTl7wRKPngqW-U,3067
|
23
|
+
maleo_foundation/managers/client/google/storage.py,sha256=d2ysrFOHAfKXWbM9u9XCxstMJgS8twSiZUshpGBfwg8,2308
|
24
24
|
maleo_foundation/middlewares/__init__.py,sha256=bqE2EIFC3rWcR2AwFPR0fk2kSFfeTRzgA24GbnuT5RA,3697
|
25
25
|
maleo_foundation/middlewares/authentication.py,sha256=mpJ4WJ25zw4SGvgpeJE9eSV3-AtK5IJtN2U8Dh9rmMk,3132
|
26
26
|
maleo_foundation/middlewares/base.py,sha256=iGc_4JZYxE0k47Dty4aFOvpgXjQY_W_4tgqYndhq3V8,10991
|
@@ -58,7 +58,7 @@ maleo_foundation/utils/__init__.py,sha256=SRPEVoqjZoO6W8rtF_Ti8VIangg6Auwm6eHbZM
|
|
58
58
|
maleo_foundation/utils/controller.py,sha256=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUUX6ipXBg,6396
|
59
59
|
maleo_foundation/utils/exceptions.py,sha256=LPPcU-6_3NbRIBZg2Nr2Ac5HF1qZJbHbMVnwfIfZg6g,3702
|
60
60
|
maleo_foundation/utils/extractor.py,sha256=SZXVYDHWGaA-Dd1BUydwF2HHdZqexEielS4CjL0Ceng,814
|
61
|
-
maleo_foundation/utils/logging.py,sha256=
|
61
|
+
maleo_foundation/utils/logging.py,sha256=cO9QLui0W9CVtQZOj_lfyuggdFaaffHkrOS12fl0i5I,8042
|
62
62
|
maleo_foundation/utils/mergers.py,sha256=DniUu3Ot4qkYH_YSw4uD1cn9cfirum4S_Opp8fMkQwA,702
|
63
63
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
64
64
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
@@ -67,7 +67,7 @@ maleo_foundation/utils/loaders/__init__.py,sha256=Dnuv7BWyglSddnbsFb96s-b3KaW7UK
|
|
67
67
|
maleo_foundation/utils/loaders/json.py,sha256=NsXLq3VZSgzmEf99tV1VtrmiudWdQ8Pzh_hI4Rm0cM8,397
|
68
68
|
maleo_foundation/utils/loaders/key.py,sha256=GZ4h1ONfp6Xx8-E8AWoGP4ajAZrwPhZRtidjn_u82Qg,2562
|
69
69
|
maleo_foundation/utils/loaders/yaml.py,sha256=jr8v3BlgmRCMTzdNgKhIYt1tnubaJXcDSSGkKVR8pbw,362
|
70
|
-
maleo_foundation-0.1.
|
71
|
-
maleo_foundation-0.1.
|
72
|
-
maleo_foundation-0.1.
|
73
|
-
maleo_foundation-0.1.
|
70
|
+
maleo_foundation-0.1.45.dist-info/METADATA,sha256=kRhwAoyM_3al1PAPkHmwJSTNwtFk81HmRF2i3twpYyw,3354
|
71
|
+
maleo_foundation-0.1.45.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
72
|
+
maleo_foundation-0.1.45.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
73
|
+
maleo_foundation-0.1.45.dist-info/RECORD,,
|
File without changes
|
File without changes
|