maleo-foundation 0.2.99__tar.gz → 0.3.1__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.
Files changed (133) hide show
  1. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/PKG-INFO +1 -1
  2. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/enums.py +16 -1
  3. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/db.py +16 -1
  4. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/service.py +11 -1
  5. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/middlewares/base.py +4 -2
  6. maleo_foundation-0.2.99/maleo_foundation/models/transfers/general/pubsub.py → maleo_foundation-0.3.1/maleo_foundation/models/transfers/general/database.py +3 -3
  7. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/general/request.py +15 -7
  8. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/cleaner.py +3 -3
  9. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/extractor.py +3 -3
  10. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation.egg-info/PKG-INFO +1 -1
  11. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation.egg-info/SOURCES.txt +1 -1
  12. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/pyproject.toml +1 -1
  13. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/README.md +0 -0
  14. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/__init__.py +0 -0
  15. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/authentication.py +0 -0
  16. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/authorization.py +0 -0
  17. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/__init__.py +0 -0
  18. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/manager.py +0 -0
  19. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/__init__.py +0 -0
  20. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/encryption/__init__.py +0 -0
  21. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/encryption/aes.py +0 -0
  22. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/encryption/rsa.py +0 -0
  23. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/hash/__init__.py +0 -0
  24. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/hash/bcrypt.py +0 -0
  25. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/hash/hmac.py +0 -0
  26. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/hash/sha256.py +0 -0
  27. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/key.py +0 -0
  28. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/signature.py +0 -0
  29. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/client/services/token.py +0 -0
  30. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/constants.py +0 -0
  31. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/__init__.py +0 -0
  32. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/client.py +0 -0
  33. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/encryption/__init__.py +0 -0
  34. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/encryption/aes.py +0 -0
  35. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/encryption/rsa.py +0 -0
  36. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/general.py +0 -0
  37. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/hash.py +0 -0
  38. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/key.py +0 -0
  39. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/repository.py +0 -0
  40. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/service.py +0 -0
  41. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/signature.py +0 -0
  42. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/expanded_types/token.py +0 -0
  43. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/extended_types.py +0 -0
  44. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/__init__.py +0 -0
  45. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/cache/__init__.py +0 -0
  46. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/cache/base.py +0 -0
  47. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/cache/redis.py +0 -0
  48. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/__init__.py +0 -0
  49. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/base.py +0 -0
  50. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/google/__init__.py +0 -0
  51. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/google/base.py +0 -0
  52. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/google/parameter.py +0 -0
  53. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/google/secret.py +0 -0
  54. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/google/storage.py +0 -0
  55. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/client/maleo.py +0 -0
  56. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/managers/middleware.py +0 -0
  57. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/middlewares/authentication.py +0 -0
  58. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/middlewares/cors.py +0 -0
  59. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/__init__.py +0 -0
  60. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/responses.py +0 -0
  61. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/__init__.py +0 -0
  62. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/encryption.py +0 -0
  63. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/general.py +0 -0
  64. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/hash.py +0 -0
  65. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/key.py +0 -0
  66. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/parameter.py +0 -0
  67. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/result.py +0 -0
  68. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/signature.py +0 -0
  69. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/schemas/token.py +0 -0
  70. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/table.py +0 -0
  71. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/__init__.py +0 -0
  72. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/general/__init__.py +0 -0
  73. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/general/key.py +0 -0
  74. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/general/signature.py +0 -0
  75. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/general/token.py +0 -0
  76. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
  77. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/client.py +0 -0
  78. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/encryption/__init__.py +0 -0
  79. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/encryption/aes.py +0 -0
  80. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/encryption/rsa.py +0 -0
  81. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/general.py +0 -0
  82. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/hash/__init__.py +0 -0
  83. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/hash/bcrypt.py +0 -0
  84. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/hash/hmac.py +0 -0
  85. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/hash/sha256.py +0 -0
  86. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/key.py +0 -0
  87. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/service.py +0 -0
  88. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/signature.py +0 -0
  89. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/parameters/token.py +0 -0
  90. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/__init__.py +0 -0
  91. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
  92. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
  93. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
  94. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/client/service.py +0 -0
  95. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/encryption/__init__.py +0 -0
  96. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/encryption/aes.py +0 -0
  97. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/encryption/rsa.py +0 -0
  98. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/hash.py +0 -0
  99. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/key.py +0 -0
  100. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
  101. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
  102. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
  103. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/service/general.py +0 -0
  104. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/service/repository.py +0 -0
  105. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/signature.py +0 -0
  106. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/models/transfers/results/token.py +0 -0
  107. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/rest_controller_result.py +0 -0
  108. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/types.py +0 -0
  109. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/__init__.py +0 -0
  110. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/client.py +0 -0
  111. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/controller.py +0 -0
  112. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/dependencies/__init__.py +0 -0
  113. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/dependencies/auth.py +0 -0
  114. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/dependencies/context.py +0 -0
  115. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/exceptions.py +0 -0
  116. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/formatter/__init__.py +0 -0
  117. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/formatter/case.py +0 -0
  118. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/__init__.py +0 -0
  119. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/credential/__init__.py +0 -0
  120. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/credential/google.py +0 -0
  121. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/json.py +0 -0
  122. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/key/__init__.py +0 -0
  123. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/key/rsa.py +0 -0
  124. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/loaders/yaml.py +0 -0
  125. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/logging.py +0 -0
  126. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/merger.py +0 -0
  127. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/query.py +0 -0
  128. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/repository.py +0 -0
  129. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation/utils/searcher.py +0 -0
  130. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation.egg-info/dependency_links.txt +0 -0
  131. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation.egg-info/requires.txt +0 -0
  132. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/maleo_foundation.egg-info/top_level.txt +0 -0
  133. {maleo_foundation-0.2.99 → maleo_foundation-0.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.99
3
+ Version: 0.3.1
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -169,4 +169,19 @@ class BaseEnums:
169
169
  EXP_3DY = int(3*24*60*60)
170
170
  EXP_1WK = int(1*7*24*60*60)
171
171
  EXP_2WK = int(2*7*24*60*60)
172
- EXP_1MO = int(1*30*24*60*60)
172
+ EXP_1MO = int(1*30*24*60*60)
173
+
174
+ class Service(StrEnum):
175
+ TELEMETRY = "maleo-telemetry"
176
+ METADATA = "maleo-metadata"
177
+ IDENTITY = "maleo-identity"
178
+ ACCESS = "maleo-access"
179
+ WORKSHOP = "maleo-workshop"
180
+ SOAPIE = "maleo-soapie"
181
+ MEDIX = "maleo-medix"
182
+ FHIR = "maleo-fhir"
183
+ DICOM = "maleo-dicom"
184
+ SCRIBE = "maleo-scribe"
185
+ CDS = "maleo-cds"
186
+ IMAGING = "maleo-imaging"
187
+ MCU = "maleo-mcu"
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  from contextlib import contextmanager
3
3
  from pydantic import BaseModel, Field
4
- from sqlalchemy import MetaData
4
+ from sqlalchemy import MetaData, text
5
5
  from sqlalchemy.engine import Engine, create_engine
6
6
  from sqlalchemy.exc import SQLAlchemyError
7
7
  from sqlalchemy.ext.declarative import DeclarativeMeta
@@ -124,6 +124,21 @@ class DatabaseManager:
124
124
  def session(self) -> SessionManager:
125
125
  return self._session
126
126
 
127
+ def check_connection(self) -> bool:
128
+ """Check database connectivity by executing a simple query."""
129
+ self._logger.info("Checking database connectivity...")
130
+ try:
131
+ with self._session.get() as session:
132
+ session.execute(text("SELECT 1"))
133
+ self._logger.info("Database connectivity check successful.")
134
+ return True
135
+ except SQLAlchemyError as se:
136
+ self._logger.error(f"Database connectivity check failed: {se}", exc_info=True)
137
+ return False
138
+ except Exception as e:
139
+ self._logger.error(f"Unexpected error during connectivity check: {e}", exc_info=True)
140
+ return False
141
+
127
142
  def dispose(self) -> None:
128
143
  #* Dispose session
129
144
  if self._session is not None:
@@ -5,6 +5,7 @@ from pathlib import Path
5
5
  from pydantic_settings import BaseSettings
6
6
  from pydantic import BaseModel, Field
7
7
  from redis.asyncio.client import Redis
8
+ from redis.exceptions import RedisError
8
9
  from starlette.exceptions import HTTPException
9
10
  from starlette.types import Lifespan, AppType
10
11
  from sqlalchemy import MetaData
@@ -332,6 +333,15 @@ class ServiceManager:
332
333
  def cache(self) -> CacheManagers:
333
334
  return self._cache
334
335
 
336
+ def check_redis_connection(self) -> bool:
337
+ try:
338
+ self._redis.ping()
339
+ self._loggers.application.info("Redis connection check successful.")
340
+ return True
341
+ except RedisError as e:
342
+ self._loggers.application.error(f"Redis connection check failed: {e}", exc_info=True)
343
+ return False
344
+
335
345
  def _initialize_cloud_storage(self) -> None:
336
346
  environment = (
337
347
  BaseEnums.EnvironmentType.STAGING
@@ -395,7 +405,7 @@ class ServiceManager:
395
405
  def create_app(
396
406
  self,
397
407
  router: APIRouter,
398
- lifespan: Optional[Lifespan[AppType]]=None
408
+ lifespan: Optional[Lifespan[AppType]] = None
399
409
  ) -> FastAPI:
400
410
  self._loggers.application.info("Creating FastAPI application")
401
411
  root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self._configs.service.key.removeprefix("maleo-")}"
@@ -217,7 +217,8 @@ class RequestLogger:
217
217
  log_func(
218
218
  f"Request | ID: {request_context.request_id} {authentication_info} | "
219
219
  f"IP: {request_context.ip_address} | Host: {request_context.host} | "
220
- f"Method: {request_context.method} | URL: {request_context.url} - "
220
+ f"Method: {request_context.method} | URL: {request_context.url} | "
221
+ f"Query Parameters: {request_context.query_params} - "
221
222
  f"Response | Status: {response.status_code}"
222
223
  )
223
224
 
@@ -239,7 +240,8 @@ class RequestLogger:
239
240
  self.logger.error(
240
241
  f"Request | ID: {request_context.request_id} {authentication_info} | "
241
242
  f"IP: {request_context.ip_address} | Host: {request_context.host} | "
242
- f"Method: {request_context.method} | URL: {request_context.url} - "
243
+ f"Method: {request_context.method} | URL: {request_context.url} | "
244
+ f"Query Parameters: {request_context.query_params} - "
243
245
  f"Response | Status: 500 | Exception:\n{json.dumps(error_details, indent=4)}"
244
246
  )
245
247
 
@@ -1,7 +1,7 @@
1
1
  from datetime import datetime, timezone
2
2
  from uuid import UUID
3
- from pydantic import BaseModel, Field, model_validator
4
- from typing import Dict, Optional, Any
3
+ from pydantic import BaseModel, Field
4
+ from typing import Optional
5
5
  from .request import RequestContext
6
6
  from .token import MaleoFoundationTokenGeneralTransfers
7
7
  from maleo_foundation.types import BaseTypes
@@ -27,7 +27,7 @@ class DatabaseAccess(BaseModel):
27
27
  "organization_id": None if self.organization_id is None else {"int": self.organization_id},
28
28
  "user_id": self.user_id,
29
29
  "token_string": None if self.token_string is None else {"string": self.token_string},
30
- "token_payload": None if self.token_payload is None else self.token_payload.to_google_pubsub_object(),
30
+ "token_payload": None if self.token_payload is None else {"TokenPayload": self.token_payload.to_google_pubsub_object()},
31
31
  "service": self.service,
32
32
  "table": self.table,
33
33
  "data_id": self.data_id,
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
  from datetime import datetime, timezone
3
- from pydantic import BaseModel, Field
3
+ from pydantic import BaseModel, Field, field_serializer
4
+ from starlette.datastructures import QueryParams
4
5
  from typing import Dict, Any
5
6
  from uuid import UUID
6
7
  from maleo_foundation.types import BaseTypes
@@ -10,8 +11,8 @@ class RequestContext(BaseModel):
10
11
  requested_at: datetime = Field(datetime.now(tz=timezone.utc), description="Request timestamp")
11
12
  method: str = Field(..., description="Request's method")
12
13
  url: str = Field(..., description="Request's URL")
13
- path_params: Dict = Field(..., description="Request's path parameters")
14
- query_params: Dict = Field(..., description="Request's query parameters")
14
+ path_params: BaseTypes.OptionalStringToAnyDict = Field(None, description="Request's path parameters")
15
+ query_params: BaseTypes.OptionalString = Field(None, description="Request's query parameters")
15
16
  ip_address: str = Field("unknown", description="Client's IP address")
16
17
  is_internal: BaseTypes.OptionalBoolean = Field(None, description="True if IP is internal")
17
18
  user_agent: BaseTypes.OptionalString = Field(None, description="User-Agent string")
@@ -24,14 +25,21 @@ class RequestContext(BaseModel):
24
25
  forwarded_proto: BaseTypes.OptionalString = Field(None, description="Forwarded protocol (http/https)")
25
26
  language: BaseTypes.OptionalString = Field(None, description="Accepted languages from client")
26
27
 
28
+ class Config:
29
+ arbitrary_types_allowed = True
30
+
31
+ @field_serializer('query_params', when_used='json')
32
+ def serialize_query_params(self, qp: QueryParams, _info) -> str:
33
+ return str(qp)
34
+
27
35
  def to_google_pubsub_object(self) -> Dict[str, Any]:
28
36
  result = {
29
37
  "request_id": str(self.request_id),
30
38
  "requested_at": self.requested_at.isoformat(),
31
39
  "method": self.method,
32
40
  "url": self.url,
33
- "path_params": {"map": self.path_params},
34
- "query_params": {"map": self.query_params},
41
+ "path_params": None if self.path_params is None else {"map": self.path_params},
42
+ "query_params": None if self.query_params is None else {"string": self.query_params},
35
43
  "ip_address": self.ip_address,
36
44
  "is_internal": None if self.is_internal is None else {"boolean": self.is_internal},
37
45
  "user_agent": None if self.user_agent is None else {"string": self.user_agent},
@@ -54,8 +62,8 @@ class RequestContext(BaseModel):
54
62
  requested_at = datetime.fromisoformat(obj["requested_at"]),
55
63
  method = obj["method"],
56
64
  url = obj["url"],
57
- path_params = obj["path_params"]["map"] or {},
58
- query_params = obj["query_params"]["map"] or {},
65
+ path_params = None if obj["path_params`"] is None else obj["path_params"]["map"],
66
+ query_params = None if obj["query_params"] is None else obj["query_params"]["string"],
59
67
  ip_address = obj["ip_address"],
60
68
  is_internal = None if obj["is_internal"] is None else bool(obj["is_internal"]["boolean"]),
61
69
  user_agent = None if obj["user_agent"] is None else obj["user_agent"]["string"],
@@ -2,13 +2,13 @@ from typing import Any, Dict, List, Optional
2
2
 
3
3
  def clean_pubsub_message(
4
4
  msg:Dict[str, Any],
5
- enums:Optional[List[str]] = None
5
+ custom_types:Optional[List[str]] = None
6
6
  ) -> Dict[str, Any]:
7
7
  for k, v in msg.items():
8
- # Clean enums
8
+ # Clean custom_types
9
9
  if isinstance(v, dict) and len(v) == 1:
10
10
  only_key = next(iter(v))
11
- if enums is not None and only_key in enums:
11
+ if custom_types is not None and only_key in custom_types:
12
12
  msg[k] = v[only_key]
13
13
 
14
14
  # Clean "map"
@@ -39,10 +39,10 @@ def extract_request_context(request: Request) -> RequestContext:
39
39
  requested_at=datetime.now(tz=timezone.utc),
40
40
  method=request.method,
41
41
  url=request.url.path,
42
- path_params=dict(request.path_params),
43
- query_params=dict(request.query_params),
42
+ path_params=None if not request.path_params else request.path_params,
43
+ query_params=None if not request.query_params else str(request.query_params),
44
44
  ip_address=ip_address,
45
- is_internal=ip_address.startswith("10.") or ip_address.startswith("192.168.") or ip_address.startswith("172."),
45
+ is_internal=None if ip_address=="unknown" else (ip_address.startswith("10.") or ip_address.startswith("192.168.") or ip_address.startswith("172.")),
46
46
  user_agent=headers.get("user-agent"),
47
47
  ua_browser=ua_browser,
48
48
  ua_mobile=headers.get("sec-ch-ua-mobile"),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.2.99
3
+ Version: 0.3.1
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -70,8 +70,8 @@ maleo_foundation/models/schemas/signature.py
70
70
  maleo_foundation/models/schemas/token.py
71
71
  maleo_foundation/models/transfers/__init__.py
72
72
  maleo_foundation/models/transfers/general/__init__.py
73
+ maleo_foundation/models/transfers/general/database.py
73
74
  maleo_foundation/models/transfers/general/key.py
74
- maleo_foundation/models/transfers/general/pubsub.py
75
75
  maleo_foundation/models/transfers/general/request.py
76
76
  maleo_foundation/models/transfers/general/signature.py
77
77
  maleo_foundation/models/transfers/general/token.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maleo_foundation"
7
- version = "0.2.99"
7
+ version = "0.3.1"
8
8
  description = "Foundation package for Maleo"
9
9
  authors = [
10
10
  { name = "Agra Bima Yuda", email = "agra@nexmedis.com" }