maleo-foundation 0.3.12__py3-none-any.whl → 0.3.14__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.
@@ -17,7 +17,7 @@ OptionalController = Optional[Controller]
17
17
  class SubscriptionConfigurations(BaseModel):
18
18
  subscription_name: str
19
19
  max_messages: int = 10
20
- ack_deadline: int = 30
20
+ ack_deadline: int = 10
21
21
  controller: OptionalController = None
22
22
 
23
23
  class SubscriptionManager(GoogleClientManager):
@@ -72,31 +72,43 @@ class ServiceManager:
72
72
  @property
73
73
  def settings(self) -> Settings:
74
74
  return self._settings
75
-
75
+
76
76
  @property
77
77
  def log_config(self) -> SimpleConfig:
78
78
  return self._log_config
79
-
79
+
80
80
  @property
81
81
  def google_credentials(self) -> Credentials:
82
82
  return self._credential_manager.google_credentials
83
-
83
+
84
84
  @property
85
85
  def secret_manager(self) -> GoogleSecretManager:
86
86
  return self._credential_manager.secret_manager
87
-
87
+
88
88
  @property
89
89
  def maleo_credentials(self) -> MaleoCredentials:
90
90
  return self._credential_manager.maleo_credentials
91
-
91
+
92
92
  @property
93
93
  def configurations(self) -> Configurations:
94
94
  return self._configuration_manager.configurations
95
95
 
96
96
  def _load_keys(self) -> None:
97
- password = self.secret_manager.get(name="maleo-key-password")
98
- private = self.secret_manager.get(name="maleo-private-key")
99
- public = self.secret_manager.get(name="maleo-public-key")
97
+ if self.settings.KEY_PASSWORD is not None:
98
+ password = self.settings.KEY_PASSWORD
99
+ else:
100
+ password = self.secret_manager.get(name="maleo-key-password")
101
+
102
+ if self.settings.PRIVATE_KEY is not None:
103
+ private = self.settings.PRIVATE_KEY
104
+ else:
105
+ private = self.secret_manager.get(name="maleo-private-key")
106
+
107
+ if self.settings.PUBLIC_KEY is not None:
108
+ public = self.settings.PUBLIC_KEY
109
+ else:
110
+ public = self.secret_manager.get(name="maleo-public-key")
111
+
100
112
  self._keys = BaseGeneralSchemas.RSAKeys(
101
113
  password=password,
102
114
  private=private,
@@ -231,12 +243,14 @@ class ServiceManager:
231
243
  def create_app(
232
244
  self,
233
245
  router: APIRouter,
234
- lifespan: Optional[Lifespan[AppType]] = None
246
+ lifespan: Optional[Lifespan[AppType]] = None,
247
+ version: str = "unknown"
235
248
  ) -> FastAPI:
236
249
  self._loggers.application.info("Creating FastAPI application")
237
- root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self.configurations.service.key.removeprefix("maleo-")}"
250
+ root_path = self._settings.ROOT_PATH
238
251
  self._app = FastAPI(
239
252
  title=self.configurations.service.name,
253
+ version=version,
240
254
  lifespan=lifespan,
241
255
  root_path=root_path
242
256
  )
@@ -21,5 +21,5 @@ class RedisCacheConfigurations(BaseModel):
21
21
  port: int = Field(6379, description="Redis instance's port")
22
22
  db: int = Field(0, description="Redis instance's db")
23
23
  password: BaseTypes.OptionalString = Field(None, description="AUTH password")
24
- decode_responses: bool = Field(False, description="Whether to decode responses")
24
+ decode_responses: bool = Field(True, description="Whether to decode responses")
25
25
  health_check_interval: int = Field(30, description="Health check interval")
@@ -7,6 +7,7 @@ from maleo_foundation.types import BaseTypes
7
7
  class Settings(BaseSettings):
8
8
  ENVIRONMENT: BaseEnums.EnvironmentType = Field(..., description="Environment")
9
9
  SERVICE_KEY: str = Field(..., description="Service's key")
10
+ ROOT_PATH: str = Field("", description="Application's root path")
10
11
  GOOGLE_CREDENTIALS_PATH: str = Field(
11
12
  "/credentials/maleo-google-service-account.json",
12
13
  description="Internal credential's file path"
@@ -27,6 +28,18 @@ class Settings(BaseSettings):
27
28
  None,
28
29
  description="Service's runtime configurations path"
29
30
  )
31
+ KEY_PASSWORD: BaseTypes.OptionalString = Field(
32
+ None,
33
+ description="Key's password"
34
+ )
35
+ PRIVATE_KEY: BaseTypes.OptionalString = Field(
36
+ None,
37
+ description="Private key"
38
+ )
39
+ PUBLIC_KEY: BaseTypes.OptionalString = Field(
40
+ None,
41
+ description="Public key"
42
+ )
30
43
 
31
44
  @classmethod
32
45
  @model_validator(mode="before")
maleo_foundation/types.py CHANGED
@@ -1,5 +1,4 @@
1
1
  from datetime import date, datetime
2
- from pathlib import Path
3
2
  from typing import Dict, Optional, Union, Literal, List, Any
4
3
  from uuid import UUID
5
4
  from maleo_foundation.enums import BaseEnums
@@ -25,9 +24,6 @@ class BaseTypes:
25
24
  OptionalInteger = Optional[int]
26
25
  OptionalListOfIntegers = Optional[List[int]]
27
26
 
28
- #* Path-related types
29
- OptionalPath = Optional[Path]
30
-
31
27
  #* String-related types
32
28
  ListOfStrings = List[str]
33
29
  OptionalString = Optional[str]
@@ -17,7 +17,7 @@ class GoogleCredentialsLoader:
17
17
  2. GOOGLE_CREDENTIALS_PATH environment variable
18
18
  3. GOOGLE_APPLICATION_CREDENTIALS environment variable
19
19
  4. Service account from default credentials (if available)
20
-
20
+
21
21
  Always returns google.oauth2.service_account.Credentials with project_id.
22
22
  Raises ValueError if service account credentials cannot be loaded or project_id is missing.
23
23
  """
@@ -26,24 +26,24 @@ class GoogleCredentialsLoader:
26
26
  credentials_path = Path(credentials_path)
27
27
  if credentials_path.exists() and credentials_path.is_file():
28
28
  return GoogleCredentialsLoader._load_from_file(credentials_path)
29
-
29
+
30
30
  # Try GOOGLE_CREDENTIALS_PATH environment variable
31
31
  env_credentials_path = os.getenv("GOOGLE_CREDENTIALS_PATH")
32
32
  if env_credentials_path:
33
33
  credentials_path = Path(env_credentials_path)
34
34
  if credentials_path.exists() and credentials_path.is_file():
35
35
  return GoogleCredentialsLoader._load_from_file(credentials_path)
36
-
36
+
37
37
  # Try GOOGLE_APPLICATION_CREDENTIALS environment variable
38
38
  app_credentials_path = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
39
39
  if app_credentials_path:
40
40
  credentials_path = Path(app_credentials_path)
41
41
  if credentials_path.exists() and credentials_path.is_file():
42
42
  return GoogleCredentialsLoader._load_from_file(credentials_path)
43
-
43
+
44
44
  # Try to get service account from default credentials
45
45
  return GoogleCredentialsLoader._load_from_default()
46
-
46
+
47
47
  @staticmethod
48
48
  def _load_from_file(credentials_path: Path) -> Credentials:
49
49
  """Load credentials from a service account file."""
@@ -51,31 +51,31 @@ class GoogleCredentialsLoader:
51
51
  # First, read and validate the service account file
52
52
  with open(credentials_path, 'r') as f:
53
53
  service_account_info = json.load(f)
54
-
54
+
55
55
  # Ensure project_id is present in the file
56
56
  if 'project_id' not in service_account_info or not service_account_info['project_id']:
57
57
  raise ValueError(f"Service account file {credentials_path} does not contain project_id")
58
-
58
+
59
59
  # Load credentials from the file
60
60
  credentials = Credentials.from_service_account_file(str(credentials_path))
61
-
61
+
62
62
  # Double-check that project_id is available in the credentials object
63
63
  if not credentials.project_id:
64
64
  raise ValueError(f"Loaded credentials from {credentials_path} do not have project_id")
65
-
65
+
66
66
  return credentials
67
-
67
+
68
68
  except json.JSONDecodeError as e:
69
69
  raise ValueError(f"Invalid JSON in credentials file {credentials_path}: {str(e)}")
70
70
  except Exception as e:
71
71
  raise ValueError(f"Failed to load credentials from file {credentials_path}: {str(e)}")
72
-
72
+
73
73
  @staticmethod
74
74
  def _load_from_default() -> Credentials:
75
75
  """Load service account credentials from default sources."""
76
76
  try:
77
77
  credentials, _ = default()
78
-
78
+
79
79
  # Check if the default credentials are service account credentials
80
80
  if isinstance(credentials, Credentials):
81
81
  # Already service account credentials
@@ -86,7 +86,7 @@ class GoogleCredentialsLoader:
86
86
  "Service account credentials loaded from default source do not have project_id. "
87
87
  "Please ensure your service account key file contains the project_id field."
88
88
  )
89
-
89
+
90
90
  return credentials
91
91
  else:
92
92
  # Default credentials are not service account credentials
@@ -96,7 +96,7 @@ class GoogleCredentialsLoader:
96
96
  "Please provide a service account key file via GOOGLE_CREDENTIALS_PATH, "
97
97
  "GOOGLE_APPLICATION_CREDENTIALS, or the credentials_path parameter."
98
98
  )
99
-
99
+
100
100
  except Exception as e:
101
101
  if "service account" in str(e).lower() or "project_id" in str(e).lower():
102
102
  raise
@@ -105,7 +105,7 @@ class GoogleCredentialsLoader:
105
105
  "Please provide a service account key file via GOOGLE_CREDENTIALS_PATH, "
106
106
  "GOOGLE_APPLICATION_CREDENTIALS, or the credentials_path parameter."
107
107
  )
108
-
108
+
109
109
  @staticmethod
110
110
  def _get_project_id_from_env() -> str:
111
111
  """Get project_id from environment variables."""
@@ -115,24 +115,24 @@ class GoogleCredentialsLoader:
115
115
  os.getenv("GCP_PROJECT") or
116
116
  os.getenv("PROJECT_ID")
117
117
  )
118
-
118
+
119
119
  if not project_id:
120
120
  raise RuntimeError(
121
121
  "project_id is required but not found. Please set one of the following environment variables: "
122
122
  "GOOGLE_CLOUD_PROJECT, GCLOUD_PROJECT, GCP_PROJECT, or PROJECT_ID, "
123
123
  "or ensure your service account key file contains the project_id field."
124
124
  )
125
-
125
+
126
126
  return project_id
127
-
127
+
128
128
  @staticmethod
129
129
  def validate_credentials(credentials: Credentials) -> None:
130
130
  """Validate that credentials are service account credentials with project_id."""
131
131
  if not isinstance(credentials, Credentials):
132
132
  raise ValueError("Credentials must be google.oauth2.service_account.Credentials")
133
-
133
+
134
134
  if not credentials.project_id:
135
135
  raise ValueError("Service account credentials must have project_id")
136
-
136
+
137
137
  if not credentials.service_account_email:
138
138
  raise ValueError("Service account credentials must have service_account_email")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.3.12
3
+ Version: 0.3.14
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -5,7 +5,7 @@ maleo_foundation/constants.py,sha256=LjMIy_Fcr6HLuhIuXs5lCtkyScZXXHOtBMPYx5lwg00
5
5
  maleo_foundation/enums.py,sha256=08rkuG3Y4-8kvd5BOBhhIS0UhzBT4kAPQX4L95GqnWQ,5316
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
- maleo_foundation/types.py,sha256=VFdnBuEh5QW_ytaZ4sNBqb6XxALU5g0RtzP0fR4svNY,2537
8
+ maleo_foundation/types.py,sha256=bUcCR-qRlxxttMxJQnVmtBic3EXEd_urcC2P55evWPc,2451
9
9
  maleo_foundation/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  maleo_foundation/client/manager.py,sha256=zI6LCRQmBynK3LYU8tfd9RXE2QIzaOTzl12B24tpAxw,2720
11
11
  maleo_foundation/client/services/__init__.py,sha256=uIBnAeQ9a2otQbUAbKBQfYrkEUugXjxXoV8W5QYHuic,1051
@@ -37,7 +37,7 @@ maleo_foundation/managers/configuration.py,sha256=IyefI1GDDRYf5FRjxpJ2LfYiRL1fuz
37
37
  maleo_foundation/managers/credential.py,sha256=i1w9bVozf7FYG8NGfLgJYRdLWBQBf35yyzVOEDgdXSA,3108
38
38
  maleo_foundation/managers/db.py,sha256=y5oP3bTXKeXYKqng-E_HZ-3wC0ZPtl5bls0AEEej6zM,6050
39
39
  maleo_foundation/managers/middleware.py,sha256=ecTNloglV67xoC_hqIEMIxhfQwzXRKHLI3ThJdd-lbY,2480
40
- maleo_foundation/managers/service.py,sha256=1rqxXMJ9E-pla0LuhKZ83JS4boTnUhiXxn1EbzYQlWA,10859
40
+ maleo_foundation/managers/service.py,sha256=UxQnWjfzqCR_e8n18-oSgM61Z9yuA93FmuqQ_vp6vmo,11168
41
41
  maleo_foundation/managers/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  maleo_foundation/managers/client/base.py,sha256=j5_CsToA_7nn_2mP9TWWz7qKalXSWqxfKY_9gTNGJJA,4282
43
43
  maleo_foundation/managers/client/maleo.py,sha256=DoMmRitPQkBKvi92NtW20awUQRhcaBXdBzfDyFdSM3Q,2669
@@ -46,7 +46,7 @@ maleo_foundation/managers/client/google/base.py,sha256=sxALVZIyKUUbNamMrXSlyb3ft
46
46
  maleo_foundation/managers/client/google/parameter.py,sha256=Jy-rMz_xhepmxBI2rWPxdP8AENBbiApg04nO6cIGXN8,1429
47
47
  maleo_foundation/managers/client/google/secret.py,sha256=m-mjaLvYMLgAEn1OxmP0IVTYFQi1jSpDdutLxNA6t6g,4620
48
48
  maleo_foundation/managers/client/google/storage.py,sha256=lEPw4N07nV9r7KjvF2Pb3RM1ZQBK9Riqj7vh6XOEY5Q,5417
49
- maleo_foundation/managers/client/google/subscription.py,sha256=1kb9ftuzDNynXwEMh2gFwL3BUCcNp-cmo4AoHnJjNg8,5177
49
+ maleo_foundation/managers/client/google/subscription.py,sha256=-mTMKu-85RLXaqGzLK3odQ-jRgkqWUms5cjPRq6rtq0,5177
50
50
  maleo_foundation/middlewares/authentication.py,sha256=OXtISL-blyWXn-bsFuWlo0Wn_Go3V-rQLCQZEGmvBNY,4658
51
51
  maleo_foundation/middlewares/base.py,sha256=IszulI930Fm4T4LQZJIyV8kebAlXt4joR6knB3QZUgA,16437
52
52
  maleo_foundation/middlewares/cors.py,sha256=9hLh_h253bvIn7-A7mUblyrJQ37XNpV7aLeHW6ZTHz8,2294
@@ -68,7 +68,7 @@ maleo_foundation/models/transfers/general/credentials.py,sha256=kLS0ymFipQmL3QaA
68
68
  maleo_foundation/models/transfers/general/database.py,sha256=bFNPd-1x3jNHPscwCk0besnpwartAeLY2e5PfKVyI4M,1201
69
69
  maleo_foundation/models/transfers/general/key.py,sha256=S37SqD3qwTbgMk7785hW7Kl9d4Kouh4uPZcGoyMQ_-Q,755
70
70
  maleo_foundation/models/transfers/general/request.py,sha256=b-Bi8yEETtX58GiG1ROFcLGnc2LjMeccXYWqteHNwpY,1777
71
- maleo_foundation/models/transfers/general/settings.py,sha256=bEvsbhlFi5DO2tS3OmxL2LAG3q1cesW3ceYsT5iGNsE,3702
71
+ maleo_foundation/models/transfers/general/settings.py,sha256=aGknx8K-GWLPSn2eEkdlmZuYAtnurHeKOS2RWyPN-zI,4089
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
74
  maleo_foundation/models/transfers/general/configurations/__init__.py,sha256=ZYXbqNkj-PHNuS8PsPtMB291s88K3wGi_PK2zJSeiX4,2010
@@ -76,7 +76,7 @@ maleo_foundation/models/transfers/general/configurations/database.py,sha256=v-Iz
76
76
  maleo_foundation/models/transfers/general/configurations/middleware.py,sha256=1BulO00lb7Xe537--rD_11GFrUKS8YxWHx2RkWfHqtg,2292
77
77
  maleo_foundation/models/transfers/general/configurations/service.py,sha256=8lag1KXkS43IwsMGWka7L-peQ9YT1-dmWeEhQ1hnnLU,304
78
78
  maleo_foundation/models/transfers/general/configurations/cache/__init__.py,sha256=a7p5LWkQJlgcfKpdJrKnCfe1LUAnwltXwTOThANlR6s,286
79
- maleo_foundation/models/transfers/general/configurations/cache/redis.py,sha256=LMxBNCmal6JjsAi7FTeN191PR1zFGw4jjfrJ9lJ_zu0,1162
79
+ maleo_foundation/models/transfers/general/configurations/cache/redis.py,sha256=CFUkIgE6OyFeHcVBqShI8NBbG1G0wpJg6b2t8Ssq3OI,1161
80
80
  maleo_foundation/models/transfers/general/configurations/client/__init__.py,sha256=XSJp-y7TzXaz_cD3AG_Cnt4YQFv3tYGfam4U0FqUrhE,275
81
81
  maleo_foundation/models/transfers/general/configurations/client/maleo.py,sha256=p6NRPWL6eKZCVU_irBCS2iuTQl-QylYuHwV8Rht30GI,1560
82
82
  maleo_foundation/models/transfers/parameters/__init__.py,sha256=oKW4RPIEISISRjsJzD8lsCGY1HhZRTzshPpWHcJu86k,353
@@ -131,10 +131,10 @@ maleo_foundation/utils/loaders/__init__.py,sha256=P_3ycGfeDXFjAi8bE4iLWHxBveqUId
131
131
  maleo_foundation/utils/loaders/json.py,sha256=Uw8v_nfkNMPvcpDYrFwqZBkACyxWzzd6M7klhHbo5JI,508
132
132
  maleo_foundation/utils/loaders/yaml.py,sha256=V2AMjkwoxi1awdahifjtEALvUZ11VL9pZWGtQ7qrNJs,503
133
133
  maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg7rejnG4I684FjUwh70tvhtVM,141
134
- maleo_foundation/utils/loaders/credential/google.py,sha256=vmVObdAyXehb3L6ASOuUJ63mNvGPb9fiXSpdRndN-4A,6528
134
+ maleo_foundation/utils/loaders/credential/google.py,sha256=ZglnLdW3lHmaKER4mwGe5N5ERus-bdsamfpwGmQYPIo,6344
135
135
  maleo_foundation/utils/loaders/key/__init__.py,sha256=hVygcC2ImHc_aVrSrOmyedR8tMUZokWUKCKOSh5ctbo,106
136
136
  maleo_foundation/utils/loaders/key/rsa.py,sha256=gDhyX6iTFtHiluuhFCozaZ3pOLKU2Y9TlrNMK_GVyGU,3796
137
- maleo_foundation-0.3.12.dist-info/METADATA,sha256=EGdGe8N4zLGGDJ7w6NK6V_6JmDV9_2EdnMFeuNAeHOY,3740
138
- maleo_foundation-0.3.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
139
- maleo_foundation-0.3.12.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
140
- maleo_foundation-0.3.12.dist-info/RECORD,,
137
+ maleo_foundation-0.3.14.dist-info/METADATA,sha256=2IjSFuWCkXn1Rhl8ylgco8zFDMHdUrAi8wMBSrOH690,3740
138
+ maleo_foundation-0.3.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
139
+ maleo_foundation-0.3.14.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
140
+ maleo_foundation-0.3.14.dist-info/RECORD,,