maleo-foundation 0.3.33__py3-none-any.whl → 0.3.37__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 CHANGED
@@ -126,17 +126,14 @@ class BaseEnums:
126
126
  BaseEnums.RESTControllerResponseType.FILE: responses.FileResponse,
127
127
  }.get(self, responses.Response)
128
128
 
129
- class ServiceLoggerType(StrEnum):
130
- REPOSITORY = "repository"
131
- DATABASE = "database"
132
- APPLICATION = "application"
133
-
134
129
  class LoggerType(StrEnum):
135
- MIDDLEWARE = "middleware"
136
- REPOSITORY = "repository"
137
- DATABASE = "database"
138
130
  APPLICATION = "application"
131
+ CACHE = "cache"
139
132
  CLIENT = "client"
133
+ DATABASE = "database"
134
+ MIDDLEWARE = "middleware"
135
+ REPOSITORY = "repository"
136
+ SERVICE = "service"
140
137
 
141
138
  class LoggerLevel(IntEnum):
142
139
  CRITICAL = logging.CRITICAL
@@ -148,26 +145,10 @@ class BaseEnums:
148
145
  DEBUG = logging.DEBUG
149
146
  NOTSET = logging.NOTSET
150
147
 
151
- class CacheType(StrEnum):
148
+ class CacheLayer(StrEnum):
149
+ CLIENT = "client"
152
150
  REPOSITORY = "repository"
153
151
  ROUTER = "router"
154
- CLIENT = "client"
155
-
156
- class CacheTTL(IntEnum):
157
- TTL_15SC = int(15)
158
- TTL_30SC = int(30)
159
- TTL_1MN = int(1*60)
160
- TTL_5MN = int(5*60)
161
- TTL_10MN = int(10*60)
162
- TTL_30MN = int(30*60)
163
- TTL_1HR = int(1*60*60)
164
- TTL_6HR = int(6*60*60)
165
- TTL_12HR = int(12*60*60)
166
- TTL_1DY = int(1*24*60*60)
167
- TTL_3DY = int(3*24*60*60)
168
- TTL_1WK = int(1*7*24*60*60)
169
- TTL_2WK = int(2*7*24*60*60)
170
- TTL_1MO = int(1*30*24*60*60)
171
152
 
172
153
  class Expiration(IntEnum):
173
154
  EXP_15SC = int(15)
@@ -8,7 +8,7 @@ from sqlalchemy.ext.declarative import DeclarativeMeta
8
8
  from sqlalchemy.orm import sessionmaker, Session, declarative_base
9
9
  from typing import Generator
10
10
  from maleo_foundation.types import BaseTypes
11
- from maleo_foundation.utils.logging import ServiceLogger
11
+ from maleo_foundation.utils.logging import DatabaseLogger
12
12
 
13
13
  class MetadataManager:
14
14
  Base: DeclarativeMeta = declarative_base()
@@ -17,7 +17,7 @@ class MetadataManager:
17
17
  class SessionManager:
18
18
  def __init__(
19
19
  self,
20
- logger: ServiceLogger,
20
+ logger: DatabaseLogger,
21
21
  engine: Engine
22
22
  ):
23
23
  self._logger = logger
@@ -80,7 +80,7 @@ class DatabaseManager:
80
80
  def __init__(
81
81
  self,
82
82
  metadata: MetaData,
83
- logger: ServiceLogger,
83
+ logger: DatabaseLogger,
84
84
  url: BaseTypes.OptionalString = None
85
85
  ):
86
86
  self._metadata = metadata #* Define database metadata
@@ -30,8 +30,12 @@ from maleo_foundation.types import BaseTypes
30
30
  from maleo_foundation.utils.exceptions import BaseExceptions
31
31
  from maleo_foundation.utils.logging import (
32
32
  SimpleConfig,
33
- ServiceLogger,
34
- MiddlewareLogger
33
+ ApplicationLogger,
34
+ CacheLogger,
35
+ DatabaseLogger,
36
+ MiddlewareLogger,
37
+ RepositoryLogger,
38
+ ServiceLogger
35
39
  )
36
40
  from .credential import CredentialManager
37
41
  from .configuration import ConfigurationManager
@@ -65,8 +69,6 @@ class ServiceManager:
65
69
 
66
70
  self._load_keys()
67
71
  self._initialize_loggers()
68
- self._initialize_cache()
69
- self._initialize_cloud_storage()
70
72
  self._initialize_database()
71
73
  self._initialize_foundation()
72
74
 
@@ -121,32 +123,37 @@ class ServiceManager:
121
123
  return self._keys
122
124
 
123
125
  def _initialize_loggers(self) -> None:
124
- #* Service's loggers
125
- application = ServiceLogger(
126
- type=BaseEnums.LoggerType.APPLICATION,
126
+ application = ApplicationLogger(
127
127
  service_key=self.configurations.service.key,
128
128
  **self._log_config.model_dump()
129
129
  )
130
- database = ServiceLogger(
131
- type=BaseEnums.LoggerType.DATABASE,
130
+ cache = CacheLogger(
132
131
  service_key=self.configurations.service.key,
133
132
  **self._log_config.model_dump()
134
133
  )
135
- repository = ServiceLogger(
136
- type=BaseEnums.LoggerType.REPOSITORY,
134
+ database = DatabaseLogger(
137
135
  service_key=self.configurations.service.key,
138
136
  **self._log_config.model_dump()
139
137
  )
140
- #* Middleware's logger
141
138
  middleware = MiddlewareLogger(
142
139
  service_key=self.configurations.service.key,
143
140
  **self._log_config.model_dump()
144
141
  )
142
+ repository = RepositoryLogger(
143
+ service_key=self.configurations.service.key,
144
+ **self._log_config.model_dump()
145
+ )
146
+ service = ServiceLogger(
147
+ service_key=self.configurations.service.key,
148
+ **self._log_config.model_dump()
149
+ )
145
150
  self._loggers = Loggers(
146
151
  application=application,
147
- repository=repository,
152
+ cache=cache,
148
153
  database=database,
149
- middleware=middleware
154
+ middleware=middleware,
155
+ repository=repository,
156
+ service=service
150
157
  )
151
158
 
152
159
  @property
@@ -162,16 +169,16 @@ class ServiceManager:
162
169
  async for key in self._redis.scan_iter(f"{prefix}*"):
163
170
  await self._redis.delete(key)
164
171
 
165
- def check_redis_connection(self) -> bool:
172
+ async def check_redis_connection(self) -> bool:
166
173
  try:
167
- self._redis.ping()
168
- self._loggers.application.info("Redis connection check successful.")
174
+ await self._redis.ping()
175
+ self._loggers.cache.info("Redis connection check successful.")
169
176
  return True
170
177
  except RedisError as e:
171
- self._loggers.application.error(f"Redis connection check failed: {e}", exc_info=True)
178
+ self._loggers.cache.error(f"Redis connection check failed: {e}", exc_info=True)
172
179
  return False
173
180
 
174
- def _initialize_cache(self) -> None:
181
+ async def initialize_cache(self) -> None:
175
182
  self._redis = Redis(
176
183
  host=self.configurations.cache.redis.host,
177
184
  port=self.configurations.cache.redis.port,
@@ -180,14 +187,9 @@ class ServiceManager:
180
187
  decode_responses=self.configurations.cache.redis.decode_responses,
181
188
  health_check_interval=self.configurations.cache.redis.health_check_interval
182
189
  )
183
- self.check_redis_connection()
190
+ await self.check_redis_connection()
184
191
  self._cache = CacheManagers(redis=self._redis)
185
- try:
186
- asyncio.run(self._clear_cache())
187
- except RuntimeError:
188
- loop = asyncio.new_event_loop()
189
- asyncio.set_event_loop(loop)
190
- loop.run_until_complete(self._clear_cache())
192
+ await self._clear_cache()
191
193
 
192
194
  @property
193
195
  def redis(self) -> Redis:
@@ -197,7 +199,7 @@ class ServiceManager:
197
199
  def cache(self) -> CacheManagers:
198
200
  return self._cache
199
201
 
200
- def _initialize_cloud_storage(self) -> None:
202
+ def initialize_cloud_storage(self) -> None:
201
203
  environment = (
202
204
  BaseEnums.EnvironmentType.STAGING
203
205
  if self._settings.ENVIRONMENT == BaseEnums.EnvironmentType.LOCAL
@@ -1,5 +1,12 @@
1
1
  from pydantic import BaseModel, ConfigDict, Field
2
- from maleo_foundation.utils.logging import MiddlewareLogger, ServiceLogger
2
+ from maleo_foundation.utils.logging import (
3
+ ApplicationLogger,
4
+ CacheLogger,
5
+ DatabaseLogger,
6
+ MiddlewareLogger,
7
+ RepositoryLogger,
8
+ ServiceLogger
9
+ )
3
10
  from .cache import CacheConfigurations
4
11
  from .client import ClientConfigurations
5
12
  from .database import DatabaseConfigurations
@@ -18,7 +25,9 @@ class Configurations(BaseModel):
18
25
  class Loggers(BaseModel):
19
26
  model_config = ConfigDict(arbitrary_types_allowed=True)
20
27
 
21
- application: ServiceLogger = Field(..., description="Application logger")
22
- repository: ServiceLogger = Field(..., description="Repository logger")
23
- database: ServiceLogger = Field(..., description="Database logger")
24
- middleware: MiddlewareLogger = Field(..., description="Middleware logger")
28
+ application: ApplicationLogger = Field(..., description="Application logger")
29
+ cache: CacheLogger = Field(..., description="Cache logger")
30
+ database: DatabaseLogger = Field(..., description="Database logger")
31
+ middleware: MiddlewareLogger = Field(..., description="Middleware logger")
32
+ repository: RepositoryLogger = Field(..., description="Repository logger")
33
+ service: ServiceLogger = Field(..., description="Service logger")
@@ -72,9 +72,6 @@ class BaseLogger(logging.Logger):
72
72
 
73
73
  #* Define logger name
74
74
  if self._type == BaseEnums.LoggerType.CLIENT:
75
- #* Ensure client_key is valid if logger type is client
76
- if self._client_key is None:
77
- raise ValueError("'client_key' parameter must be provided if 'logger_type' is 'client'")
78
75
  self._name = f"{self._service_key} - {self._type} - {self._client_key}"
79
76
  else:
80
77
  self._name = f"{self._service_key} - {self._type}"
@@ -145,35 +142,34 @@ class BaseLogger(logging.Logger):
145
142
  handler.close()
146
143
  self.handlers.clear()
147
144
 
148
- class MiddlewareLogger(BaseLogger):
145
+ class ApplicationLogger(BaseLogger):
149
146
  def __init__(
150
147
  self,
151
148
  dir: str,
152
149
  service_key: BaseTypes.OptionalString = None,
153
- level = BaseEnums.LoggerLevel.INFO,
154
- google_cloud_logging = None
150
+ level: BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
151
+ google_cloud_logging: Optional[GoogleCloudLogging] = None
155
152
  ):
156
153
  super().__init__(
157
154
  dir=dir,
158
- type=BaseEnums.LoggerType.MIDDLEWARE,
155
+ type=BaseEnums.LoggerType.APPLICATION,
159
156
  service_key=service_key,
160
157
  client_key=None,
161
158
  level=level,
162
159
  google_cloud_logging=google_cloud_logging
163
160
  )
164
161
 
165
- class ServiceLogger(BaseLogger):
162
+ class CacheLogger(BaseLogger):
166
163
  def __init__(
167
164
  self,
168
165
  dir: str,
169
- type: BaseEnums.ServiceLoggerType,
170
166
  service_key: BaseTypes.OptionalString = None,
171
167
  level: BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
172
168
  google_cloud_logging: Optional[GoogleCloudLogging] = None
173
169
  ):
174
170
  super().__init__(
175
171
  dir=dir,
176
- type=type,
172
+ type=BaseEnums.LoggerType.CACHE,
177
173
  service_key=service_key,
178
174
  client_key=None,
179
175
  level=level,
@@ -196,4 +192,72 @@ class ClientLogger(BaseLogger):
196
192
  client_key=client_key,
197
193
  level=level,
198
194
  google_cloud_logging=google_cloud_logging
195
+ )
196
+
197
+ class DatabaseLogger(BaseLogger):
198
+ def __init__(
199
+ self,
200
+ dir: str,
201
+ service_key: BaseTypes.OptionalString = None,
202
+ level = BaseEnums.LoggerLevel.INFO,
203
+ google_cloud_logging = None
204
+ ):
205
+ super().__init__(
206
+ dir=dir,
207
+ type=BaseEnums.LoggerType.DATABASE,
208
+ service_key=service_key,
209
+ client_key=None,
210
+ level=level,
211
+ google_cloud_logging=google_cloud_logging
212
+ )
213
+
214
+ class MiddlewareLogger(BaseLogger):
215
+ def __init__(
216
+ self,
217
+ dir: str,
218
+ service_key: BaseTypes.OptionalString = None,
219
+ level = BaseEnums.LoggerLevel.INFO,
220
+ google_cloud_logging = None
221
+ ):
222
+ super().__init__(
223
+ dir=dir,
224
+ type=BaseEnums.LoggerType.MIDDLEWARE,
225
+ service_key=service_key,
226
+ client_key=None,
227
+ level=level,
228
+ google_cloud_logging=google_cloud_logging
229
+ )
230
+
231
+ class RepositoryLogger(BaseLogger):
232
+ def __init__(
233
+ self,
234
+ dir: str,
235
+ service_key: BaseTypes.OptionalString = None,
236
+ level: BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
237
+ google_cloud_logging: Optional[GoogleCloudLogging] = None
238
+ ):
239
+ super().__init__(
240
+ dir=dir,
241
+ type=BaseEnums.LoggerType.REPOSITORY,
242
+ service_key=service_key,
243
+ client_key=None,
244
+ level=level,
245
+ google_cloud_logging=google_cloud_logging
246
+ )
247
+
248
+ class ServiceLogger(BaseLogger):
249
+ def __init__(
250
+ self,
251
+ dir: str,
252
+ service_key: BaseTypes.OptionalString = None,
253
+ level: BaseEnums.LoggerLevel = BaseEnums.LoggerLevel.INFO,
254
+ google_cloud_logging: Optional[GoogleCloudLogging] = None
255
+ ):
256
+ super().__init__(
257
+ dir=dir,
258
+ type=BaseEnums.LoggerType.SERVICE,
259
+ service_key=service_key,
260
+ client_key=None,
261
+ level=level,
262
+ google_cloud_logging=google_cloud_logging
199
263
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.3.33
3
+ Version: 0.3.37
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -2,7 +2,7 @@ maleo_foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
2
2
  maleo_foundation/authentication.py,sha256=TSszeTEKijy95gdYM_fFGR_VtpPWKDwkP7_AOdoGCA0,1556
3
3
  maleo_foundation/authorization.py,sha256=HGXCJ47AU1YFMDSmGhrMMmlHnAyghcFZVUiPa1FSvog,283
4
4
  maleo_foundation/constants.py,sha256=LjMIy_Fcr6HLuhIuXs5lCtkyScZXXHOtBMPYx5lwg00,1446
5
- maleo_foundation/enums.py,sha256=08rkuG3Y4-8kvd5BOBhhIS0UhzBT4kAPQX4L95GqnWQ,5316
5
+ maleo_foundation/enums.py,sha256=x6hVz0gvrKRF1ng8lMgVzwfiA_F6Y4vuOU4rBOgtTUg,4758
6
6
  maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBmdc-L4,301
7
7
  maleo_foundation/rest_controller_result.py,sha256=4KbCmk70IEHj1L1bNJfFg1Y3ifnRSnmvK6dYyVJddok,2014
8
8
  maleo_foundation/types.py,sha256=bUcCR-qRlxxttMxJQnVmtBic3EXEd_urcC2P55evWPc,2451
@@ -35,9 +35,9 @@ maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
35
35
  maleo_foundation/managers/cache.py,sha256=IgcA-NAJbW83jRyApuQPbSJdth2LUpix9o-5CMWNwdI,274
36
36
  maleo_foundation/managers/configuration.py,sha256=Jcm2A_fS-styLEWZurF7nquitnSYuce05YVuxlDgxe4,1417
37
37
  maleo_foundation/managers/credential.py,sha256=i1w9bVozf7FYG8NGfLgJYRdLWBQBf35yyzVOEDgdXSA,3108
38
- maleo_foundation/managers/db.py,sha256=y5oP3bTXKeXYKqng-E_HZ-3wC0ZPtl5bls0AEEej6zM,6050
38
+ maleo_foundation/managers/db.py,sha256=Y3GrpKT8pIKP4Kr40Z4XtfW3wnj-OYhTlfx_G0cyDvg,6053
39
39
  maleo_foundation/managers/middleware.py,sha256=ecTNloglV67xoC_hqIEMIxhfQwzXRKHLI3ThJdd-lbY,2480
40
- maleo_foundation/managers/service.py,sha256=90OG8qKaDYYpGxM3OllzLABqPguBtGUYI1yFUREAaUA,11783
40
+ maleo_foundation/managers/service.py,sha256=j6dxgQPn7CNjQnmoHw70rEEUnzkcgSgsDrJuptHHpzY,11743
41
41
  maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  maleo_foundation/managers/client/base.py,sha256=o4D_y52Zxl-jOtV59o6ZCJOuS6rlUy7e2x3vs7vB5tk,4314
43
43
  maleo_foundation/managers/client/maleo.py,sha256=fhIXKeIjx0VgS8wjX0Cpk05ZHHRiPvmpUQl0890mZxw,2686
@@ -71,7 +71,7 @@ maleo_foundation/models/transfers/general/request.py,sha256=xOeBbtXygK5P6DxPyf3C
71
71
  maleo_foundation/models/transfers/general/settings.py,sha256=p0PSec_8y-gpYZjx4r29L5QAV68hHikWetGkI9qqeoo,1690
72
72
  maleo_foundation/models/transfers/general/signature.py,sha256=J9xQy2HjpCQOnES7RJqsUnDgjFPuakQ1mxyfdTdstSE,297
73
73
  maleo_foundation/models/transfers/general/token.py,sha256=PU-_wLFaY2i8pwRi9-jlk4nh7XzoTKOk0BEsUCGbD80,4979
74
- maleo_foundation/models/transfers/general/configurations/__init__.py,sha256=xKU7f5V8I-pEzOXlL0CS82Zo60CqDjdB6Bnp3LUzcsg,1272
74
+ maleo_foundation/models/transfers/general/configurations/__init__.py,sha256=B-7xmw6pye01yu2zQZU6vTevu3VDl-zALy0pfpksu0U,1508
75
75
  maleo_foundation/models/transfers/general/configurations/database.py,sha256=v-IzSm8kZa1TQByCc8dpIU-8csJN_G2irWeN4EClNlo,690
76
76
  maleo_foundation/models/transfers/general/configurations/middleware.py,sha256=-6dk6C2QBDfmTDENhsgyMHpRUGfrSxQY3BDwo_WtgAs,1710
77
77
  maleo_foundation/models/transfers/general/configurations/service.py,sha256=8lag1KXkS43IwsMGWka7L-peQ9YT1-dmWeEhQ1hnnLU,304
@@ -116,7 +116,7 @@ maleo_foundation/utils/client.py,sha256=CGwn8eH5WlwnE5tPMfMAH5V3BItBgVmYBZnXpLjT
116
116
  maleo_foundation/utils/controller.py,sha256=Ub1R-JN6spmXakYrOY7igwaNt4Sg8LASASdXymxZcCI,6954
117
117
  maleo_foundation/utils/exceptions.py,sha256=z24kzEP2geaAEElxXaEy7ln6KodebXvtlu-h1inZ_nw,6376
118
118
  maleo_foundation/utils/extractor.py,sha256=ZNX0sQKcUwwh7paUZpdR04a18s8Ru2xNXhWZl-XN3l4,2197
119
- maleo_foundation/utils/logging.py,sha256=EfigViQmvtIlktr87O91ftlj6RxYaMNegHglfX6M63c,6839
119
+ maleo_foundation/utils/logging.py,sha256=8Pf7GIrV7kywvJWBBOVs7mvptGBV4eBXuEYBaZjA-IM,8674
120
120
  maleo_foundation/utils/merger.py,sha256=MdocyCOtIhqjcmqx2mJ0V8vtwsrunRXqhRdrBCruh7Q,622
121
121
  maleo_foundation/utils/query.py,sha256=hhISpBAZ4SV_pGf7uGBC6fzLrs_yj5_8gj-kFFeeNrw,8060
122
122
  maleo_foundation/utils/repository.py,sha256=pxpws2PDyXwGACms_1azlabqzT6q1x41aYAQRablSnk,2860
@@ -133,7 +133,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
133
133
  maleo_foundation/utils/loaders/credential/google.py,sha256=ZglnLdW3lHmaKER4mwGe5N5ERus-bdsamfpwGmQYPIo,6344
134
134
  maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
135
135
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
136
- maleo_foundation-0.3.33.dist-info/METADATA,sha256=Ft7Hs95SltAHjPD1QakpOlTCAwAL4n9kR8LVI3DCZXc,3740
137
- maleo_foundation-0.3.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
138
- maleo_foundation-0.3.33.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
139
- maleo_foundation-0.3.33.dist-info/RECORD,,
136
+ maleo_foundation-0.3.37.dist-info/METADATA,sha256=g41kKHz_LAJNi_GCrbtwcsrzEz43sT8_GH3Acc6a42o,3740
137
+ maleo_foundation-0.3.37.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
138
+ maleo_foundation-0.3.37.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
139
+ maleo_foundation-0.3.37.dist-info/RECORD,,