maleo-foundation 0.0.99__py3-none-any.whl → 0.1.1__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/google/secret.py +2 -0
- maleo_foundation/managers/client/google/storage.py +2 -0
- maleo_foundation/managers/db.py +10 -4
- maleo_foundation/managers/service.py +13 -3
- maleo_foundation/utils/logging.py +24 -1
- {maleo_foundation-0.0.99.dist-info → maleo_foundation-0.1.1.dist-info}/METADATA +1 -1
- {maleo_foundation-0.0.99.dist-info → maleo_foundation-0.1.1.dist-info}/RECORD +9 -9
- {maleo_foundation-0.0.99.dist-info → maleo_foundation-0.1.1.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.0.99.dist-info → maleo_foundation-0.1.1.dist-info}/top_level.txt +0 -0
@@ -23,7 +23,9 @@ class GoogleSecretManager(GoogleClientManager):
|
|
23
23
|
|
24
24
|
def dispose(self) -> None:
|
25
25
|
if self._client is not None:
|
26
|
+
self._logger.info("Disposing Google Secret Manager (GSM) client manager")
|
26
27
|
self._client = None
|
28
|
+
self._logger.info("Google Secret Manager (GCS) client manager disposed successfully")
|
27
29
|
|
28
30
|
@retry.Retry(predicate=retry.if_exception_type(Exception), timeout=5)
|
29
31
|
def get(self, name:str, version:str = "latest") -> Optional[str]:
|
@@ -35,8 +35,10 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
35
35
|
|
36
36
|
def dispose(self) -> None:
|
37
37
|
if self._client is not None:
|
38
|
+
self._logger.info("Disposing Google Cloud Storage (GCS) client manager")
|
38
39
|
self._client.close()
|
39
40
|
self._client = None
|
41
|
+
self._logger.info("Google Cloud Storage (GCS) client manager disposed successfully")
|
40
42
|
|
41
43
|
def generate_signed_url(self, location:str) -> str:
|
42
44
|
"""
|
maleo_foundation/managers/db.py
CHANGED
@@ -101,16 +101,22 @@ class DatabaseManager:
|
|
101
101
|
def dispose(self) -> None:
|
102
102
|
#* Dispose session
|
103
103
|
if self._session is not None:
|
104
|
+
self._logger.info("Disposing Session Manager")
|
104
105
|
self._session.dispose()
|
105
106
|
self._session = None
|
106
107
|
#* Dispose engine
|
107
108
|
if self._engine is not None:
|
109
|
+
self._logger.info("Disposing Engine Manager")
|
108
110
|
self._engine.dispose()
|
109
111
|
self._engine = None
|
112
|
+
self._logger.info("Engine Manager disposed successfully")
|
113
|
+
#* Dispose metadata
|
114
|
+
if self._metadata is not None:
|
115
|
+
self._logger.info("Disposing DB Metadata")
|
116
|
+
self._metadata = None
|
117
|
+
self._logger.info("DB Metadata diposed succesfully")
|
110
118
|
#* Dispose logger
|
111
119
|
if self._logger is not None:
|
120
|
+
self._logger.info("Disposing database's logger")
|
112
121
|
self._logger.dispose()
|
113
|
-
self._logger = None
|
114
|
-
#* Dispose metadata
|
115
|
-
if self._metadata is not None:
|
116
|
-
self._metadata = None
|
122
|
+
self._logger = None
|
@@ -15,7 +15,7 @@ from maleo_foundation.managers.db import DatabaseManager
|
|
15
15
|
from maleo_foundation.services.token import BaseTokenService
|
16
16
|
from maleo_foundation.types import BaseTypes
|
17
17
|
from maleo_foundation.utils.keyloader import load_key
|
18
|
-
from maleo_foundation.utils.logging import GoogleCloudLogging, ServiceLogger
|
18
|
+
from maleo_foundation.utils.logging import GoogleCloudLogging, ServiceLogger, ClientLoggerManager
|
19
19
|
|
20
20
|
class Settings(BaseSettings):
|
21
21
|
GOOGLE_CREDENTIALS_PATH:str = Field("/creds/maleo-google-service-account.json", description="Internal credential's file path")
|
@@ -84,10 +84,13 @@ class Configurations(BaseModel):
|
|
84
84
|
class Config:
|
85
85
|
arbitrary_types_allowed=True
|
86
86
|
|
87
|
+
ClientLoggerManagers = Dict[str, ClientLoggerManager]
|
88
|
+
|
87
89
|
class Loggers(BaseModel):
|
88
90
|
application:ServiceLogger = Field(..., description="Application logger")
|
89
91
|
database:ServiceLogger = Field(..., description="Database logger")
|
90
92
|
middleware:ServiceLogger = Field(..., description="Middleware logger")
|
93
|
+
client:ClientLoggerManagers = Field(default_factory=dict, description="Client logger manager")
|
91
94
|
|
92
95
|
class Config:
|
93
96
|
arbitrary_types_allowed=True
|
@@ -112,7 +115,8 @@ class ServiceManager:
|
|
112
115
|
db_metadata:MetaData,
|
113
116
|
base_dir:BaseTypes.OptionalString = None,
|
114
117
|
settings:Optional[Settings] = None,
|
115
|
-
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
118
|
+
google_cloud_logging:Optional[GoogleCloudLogging] = None,
|
119
|
+
client_logger_managers:ClientLoggerManagers = {}
|
116
120
|
):
|
117
121
|
self._db_metadata = db_metadata
|
118
122
|
|
@@ -138,6 +142,7 @@ class ServiceManager:
|
|
138
142
|
else:
|
139
143
|
self._google_cloud_logging = google_cloud_logging
|
140
144
|
|
145
|
+
self._client_logger_managers = client_logger_managers
|
141
146
|
self._initialize_loggers()
|
142
147
|
self._load_credentials()
|
143
148
|
self._parse_keys()
|
@@ -169,7 +174,11 @@ class ServiceManager:
|
|
169
174
|
application = ServiceLogger(logs_dir=self._logs_dir, type=BaseEnums.LoggerType.APPLICATION, google_cloud_logging=self._google_cloud_logging)
|
170
175
|
database = ServiceLogger(logs_dir=self._logs_dir, type=BaseEnums.LoggerType.DATABASE, google_cloud_logging=self._google_cloud_logging)
|
171
176
|
middleware = ServiceLogger(logs_dir=self._logs_dir, type=BaseEnums.LoggerType.MIDDLEWARE, google_cloud_logging=self._google_cloud_logging)
|
172
|
-
|
177
|
+
client = self._client_logger_managers
|
178
|
+
for key, logger_manager in client.items():
|
179
|
+
application.info(f"Initializing logger manager for client '{key}'")
|
180
|
+
logger_manager.initialize()
|
181
|
+
self._loggers = Loggers(application=application, database=database, middleware=middleware, client=client)
|
173
182
|
|
174
183
|
@property
|
175
184
|
def loggers(self) -> Loggers:
|
@@ -258,6 +267,7 @@ class ServiceManager:
|
|
258
267
|
return result.data.token
|
259
268
|
|
260
269
|
async def dispose(self) -> None:
|
270
|
+
self._loggers.application.info("Disposing service manager")
|
261
271
|
if self._database is not None:
|
262
272
|
self._database.dispose()
|
263
273
|
self._database = None
|
@@ -179,4 +179,27 @@ class ClientLogger(BaseLogger):
|
|
179
179
|
client_key=client_key,
|
180
180
|
level=level,
|
181
181
|
google_cloud_logging=google_cloud_logging
|
182
|
-
)
|
182
|
+
)
|
183
|
+
|
184
|
+
class ClientLoggerManager:
|
185
|
+
_logger:Optional[ClientLogger] = None
|
186
|
+
|
187
|
+
@classmethod
|
188
|
+
def initialize(
|
189
|
+
cls,
|
190
|
+
logs_dir:str,
|
191
|
+
client_key:str,
|
192
|
+
service_key:BaseTypes.OptionalString = None,
|
193
|
+
level:BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
|
194
|
+
google_cloud_logging:Optional[GoogleCloudLogging] = None
|
195
|
+
) -> None:
|
196
|
+
"""Initialize client logger if not already initialized."""
|
197
|
+
if cls._logger is None:
|
198
|
+
cls.logger = ClientLogger(logs_dir=logs_dir, client_key=client_key, service_key=service_key, level=level, google_cloud_logging=google_cloud_logging)
|
199
|
+
|
200
|
+
@classmethod
|
201
|
+
def get(cls) -> ClientLogger:
|
202
|
+
"""Return client logger (if exist) or raise Runtime Error"""
|
203
|
+
if cls._logger is None:
|
204
|
+
raise RuntimeError("Logger has not been initialized. Initialize it first.")
|
205
|
+
return cls._logger
|
@@ -29,15 +29,15 @@ maleo_foundation/expanded_types/query.py,sha256=0yUG-JIVsanzB7KAkrRz_OsrhP6J0bRq
|
|
29
29
|
maleo_foundation/expanded_types/service.py,sha256=q8jpKdbCbLWwH1UPQavKpVE14rC5rveduk2cFWzuhGw,2416
|
30
30
|
maleo_foundation/expanded_types/token.py,sha256=4fRTJw6W5MYq71NksNrWNi7qYHQ4_lQwfu9WxwrMipc,355
|
31
31
|
maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
32
|
-
maleo_foundation/managers/db.py,sha256=
|
33
|
-
maleo_foundation/managers/service.py,sha256=
|
32
|
+
maleo_foundation/managers/db.py,sha256=rbB5W2rSxV2xcexh9j79U4ZKgAuA61t8ZD2IKppg22k,4867
|
33
|
+
maleo_foundation/managers/service.py,sha256=z7DUQC0a3z18rTH2k26WNhYdeQk8tkuQ90Vh3Dh25jM,11798
|
34
34
|
maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
35
35
|
maleo_foundation/managers/client/base.py,sha256=lFn3B4SKjZfpeb9aYFY1iyut9juNM6l91yHXoqntPhM,949
|
36
36
|
maleo_foundation/managers/client/http.py,sha256=gAPEpIyA4XzEpToxZGPj6HAuK9VwdoSG54lR8OoVK1c,1374
|
37
37
|
maleo_foundation/managers/client/google/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
38
|
maleo_foundation/managers/client/google/base.py,sha256=1lrGoyGnYW5Xq05bVXbKqnsqqmFPnsqZCBPK5-DINDA,1037
|
39
|
-
maleo_foundation/managers/client/google/secret.py,sha256=
|
40
|
-
maleo_foundation/managers/client/google/storage.py,sha256=
|
39
|
+
maleo_foundation/managers/client/google/secret.py,sha256=iKXaF8qNDXRYbmosS9bAXQFYwRdDZ3Kh2yKhBAaOoEI,3061
|
40
|
+
maleo_foundation/managers/client/google/storage.py,sha256=KaT4XrNpy-p6Bi1TcN0c4BK-vrfzCYxwKzMq4i3saNA,2335
|
41
41
|
maleo_foundation/middlewares/__init__.py,sha256=bqE2EIFC3rWcR2AwFPR0fk2kSFfeTRzgA24GbnuT5RA,3697
|
42
42
|
maleo_foundation/middlewares/base.py,sha256=KcpODNs0DQXX8Cwc6T9dC6aiZIqxTLtuJjVAGWXPSKk,11633
|
43
43
|
maleo_foundation/middlewares/cors.py,sha256=9uvBvY2N6Vxa9RP_YtESxcWo6Doi6uS0lzAG9iLY7Uc,2288
|
@@ -74,11 +74,11 @@ maleo_foundation/utils/controller.py,sha256=ECzPzpw36zBAjKcWcDbUAhIJGbc6UpeypdUU
|
|
74
74
|
maleo_foundation/utils/exceptions.py,sha256=nk3rD57fDR-D7BQkU1JEKV-Mu7FGMpLSEsqxdDZdKjU,4532
|
75
75
|
maleo_foundation/utils/keyloader.py,sha256=g7LYypj7UolmSgHRGXMFgVaWr55UayMdtKXR5NmB7VM,2341
|
76
76
|
maleo_foundation/utils/logger.py,sha256=uTvzzKnGjbxRVLHbiMDw2zKKWNaCwV35sxgjDStEwNQ,3569
|
77
|
-
maleo_foundation/utils/logging.py,sha256=
|
77
|
+
maleo_foundation/utils/logging.py,sha256=DuAaKQ1X7lB0y6udR-GF95BRKeluh0JoYN0K_jcNlZ0,7313
|
78
78
|
maleo_foundation/utils/query.py,sha256=ODQ3adOYQNj5E2cRW9ytbjBz56nEDcnfq8mQ6YZbCCM,4375
|
79
79
|
maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
|
80
80
|
maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
|
81
|
-
maleo_foundation-0.
|
82
|
-
maleo_foundation-0.
|
83
|
-
maleo_foundation-0.
|
84
|
-
maleo_foundation-0.
|
81
|
+
maleo_foundation-0.1.1.dist-info/METADATA,sha256=E-2sNgATRZq6_s8L_Oyf6FEMju_ORqOelV8TUnpwdkE,3189
|
82
|
+
maleo_foundation-0.1.1.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
83
|
+
maleo_foundation-0.1.1.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
|
84
|
+
maleo_foundation-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|