maleo-foundation 0.3.9__py3-none-any.whl → 0.3.10__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.
@@ -26,7 +26,7 @@ class ConfigurationManager:
26
26
  self.settings = settings
27
27
  self.credential_manager = credential_manager
28
28
 
29
- self._load_configs()
29
+ self._load_configurations()
30
30
 
31
31
  def _load_static_configurations(self) -> StaticConfigurations:
32
32
  config_path = Path(self.settings.STATIC_CONFIGURATIONS_PATH)
@@ -35,7 +35,7 @@ class ConfigurationManager:
35
35
  data = YAMLLoader.load_from_path(str(config_path))
36
36
  else:
37
37
  secret_data = self.credential_manager.secret_manager.get(
38
- f"maleo-static-config-{self.settings.ENVIRONMENT}"
38
+ f"maleo-static-configurations-{self.settings.ENVIRONMENT}"
39
39
  )
40
40
  data = YAMLLoader.load_from_string(secret_data)
41
41
 
@@ -48,7 +48,7 @@ class ConfigurationManager:
48
48
  data = YAMLLoader.load_from_path(str(config_path))
49
49
  else:
50
50
  secret_data = self.credential_manager.secret_manager.get(
51
- f"{self.settings.SERVICE_KEY}-runtime-config-{self.settings.ENVIRONMENT}"
51
+ f"{self.settings.SERVICE_KEY}-runtime-configurations-{self.settings.ENVIRONMENT}"
52
52
  )
53
53
  data = YAMLLoader.load_from_string(secret_data)
54
54
 
@@ -68,35 +68,20 @@ class ConfigurationManager:
68
68
  password=password
69
69
  )
70
70
  return CacheConfigurations(redis=redis)
71
-
72
- def _load_database_configurations(self, database_name: str) -> DatabaseConfigurations:
73
- password = self.credential_manager.secret_manager.get(
74
- f"maleo-db-password-{self.settings.ENVIRONMENT}"
75
- )
76
- host = self.credential_manager.secret_manager.get(
77
- f"maleo-db-host-{self.settings.ENVIRONMENT}"
78
- )
79
- return DatabaseConfigurations(
80
- password=password,
81
- host=host,
82
- database=database_name
83
- )
84
71
 
85
- def _load_configs(self) -> None:
86
- static_configs = self._load_static_configurations()
87
- runtime_configs = self._load_runtime_configurations()
88
- cache_configs = self._load_cache_configurations()
89
- database_configs = self._load_database_configurations(runtime_configs.database)
90
-
91
- merged_configs = deep_merge(
92
- static_configs.model_dump(),
93
- runtime_configs.model_dump(exclude={"database"}),
94
- {"cache": cache_configs.model_dump()},
95
- {"database": database_configs.model_dump()}
72
+ def _load_configurations(self) -> None:
73
+ static_configurations = self._load_static_configurations()
74
+ runtime_configurations = self._load_runtime_configurations()
75
+ cache_configurations = self._load_cache_configurations()
76
+
77
+ merged_configurations = deep_merge(
78
+ static_configurations.model_dump(),
79
+ runtime_configurations.model_dump(),
80
+ {"cache": cache_configurations.model_dump()}
96
81
  )
97
82
 
98
- self._configs = Configurations.model_validate(merged_configs)
83
+ self._configurations = Configurations.model_validate(merged_configurations)
99
84
 
100
85
  @property
101
- def configs(self) -> Configurations:
102
- return self._configs
86
+ def configurations(self) -> Configurations:
87
+ return self._configurations
@@ -50,12 +50,13 @@ class ServiceManager:
50
50
  if self._settings.ENVIRONMENT == "local":
51
51
  self._log_config.google_cloud_logging = None
52
52
 
53
- #* Initialize Managers
53
+ #* Initialize Credential Manager
54
54
  self._credential_manager = CredentialManager(
55
55
  settings=self._settings,
56
56
  log_config=self._log_config
57
57
  )
58
58
 
59
+ #* Initialize Configuration Manager
59
60
  self._configuration_manager = ConfigurationManager(
60
61
  settings=self._settings,
61
62
  credential_manager=self._credential_manager
@@ -65,7 +66,7 @@ class ServiceManager:
65
66
  self._initialize_loggers()
66
67
  self._initialize_cache()
67
68
  self._initialize_cloud_storage()
68
- self._initialize_db()
69
+ self._initialize_database()
69
70
  self._initialize_foundation()
70
71
 
71
72
  @property
@@ -89,8 +90,8 @@ class ServiceManager:
89
90
  return self._credential_manager.maleo_credentials
90
91
 
91
92
  @property
92
- def configs(self) -> Configurations:
93
- return self._configuration_manager.configs
93
+ def configurations(self) -> Configurations:
94
+ return self._configuration_manager.configurations
94
95
 
95
96
  def _load_keys(self) -> None:
96
97
  password = self.secret_manager.get(name="maleo-key-password")
@@ -110,22 +111,22 @@ class ServiceManager:
110
111
  #* Service's loggers
111
112
  application = ServiceLogger(
112
113
  type=BaseEnums.LoggerType.APPLICATION,
113
- service_key=self.configs.service.key,
114
+ service_key=self.configurations.service.key,
114
115
  **self._log_config.model_dump()
115
116
  )
116
117
  database = ServiceLogger(
117
118
  type=BaseEnums.LoggerType.DATABASE,
118
- service_key=self.configs.service.key,
119
+ service_key=self.configurations.service.key,
119
120
  **self._log_config.model_dump()
120
121
  )
121
122
  repository = ServiceLogger(
122
123
  type=BaseEnums.LoggerType.REPOSITORY,
123
- service_key=self.configs.service.key,
124
+ service_key=self.configurations.service.key,
124
125
  **self._log_config.model_dump()
125
126
  )
126
127
  #* Middleware's logger
127
128
  middleware = MiddlewareLogger(
128
- service_key=self.configs.service.key,
129
+ service_key=self.configurations.service.key,
129
130
  **self._log_config.model_dump()
130
131
  )
131
132
  self._loggers = Loggers(
@@ -141,12 +142,12 @@ class ServiceManager:
141
142
 
142
143
  def _initialize_cache(self) -> None:
143
144
  self._redis = Redis(
144
- host=self.configs.cache.redis.host,
145
- port=self.configs.cache.redis.port,
146
- db=self.configs.cache.redis.db,
147
- password=self.configs.cache.redis.password,
148
- decode_responses=self.configs.cache.redis.decode_responses,
149
- health_check_interval=self.configs.cache.redis.health_check_interval
145
+ host=self.configurations.cache.redis.host,
146
+ port=self.configurations.cache.redis.port,
147
+ db=self.configurations.cache.redis.db,
148
+ password=self.configurations.cache.redis.password,
149
+ decode_responses=self.configurations.cache.redis.decode_responses,
150
+ health_check_interval=self.configurations.cache.redis.health_check_interval
150
151
  )
151
152
  self._cache = CacheManagers(redis=self._redis)
152
153
 
@@ -185,11 +186,11 @@ class ServiceManager:
185
186
  def cloud_storage(self) -> GoogleCloudStorage:
186
187
  return self._cloud_storage
187
188
 
188
- def _initialize_db(self) -> None:
189
+ def _initialize_database(self) -> None:
189
190
  self._database = DatabaseManager(
190
191
  metadata=self._db_metadata,
191
192
  logger=self._loggers.database,
192
- url=self.configs.database.url
193
+ url=self.configurations.database.url
193
194
  )
194
195
 
195
196
  @property
@@ -233,9 +234,9 @@ class ServiceManager:
233
234
  lifespan: Optional[Lifespan[AppType]] = None
234
235
  ) -> FastAPI:
235
236
  self._loggers.application.info("Creating FastAPI application")
236
- root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self.configs.service.key.removeprefix("maleo-")}"
237
+ root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self.configurations.service.key.removeprefix("maleo-")}"
237
238
  self._app = FastAPI(
238
- title=self.configs.service.name,
239
+ title=self.configurations.service.name,
239
240
  lifespan=lifespan,
240
241
  root_path=root_path
241
242
  )
@@ -245,7 +246,7 @@ class ServiceManager:
245
246
  self._loggers.application.info("Configuring middlewares")
246
247
  self._middleware = MiddlewareManager(
247
248
  app=self._app,
248
- configurations=self.configs.middleware,
249
+ configurations=self.configurations.middleware,
249
250
  keys=self._keys,
250
251
  logger=self._loggers.middleware,
251
252
  maleo_foundation=self._foundation
@@ -13,7 +13,7 @@ from .service import ServiceConfigurations
13
13
  class RuntimeConfigurations(BaseModel):
14
14
  service: ServiceConfigurations = Field(..., description="Service's configurations")
15
15
  middleware: MiddlewareRuntimeConfigurations = Field(..., description="Middleware's runtime configurations")
16
- database: str = Field(..., description="Database's name")
16
+ database: DatabaseConfigurations = Field(..., description="Database's configurations")
17
17
 
18
18
  class Config:
19
19
  arbitrary_types_allowed=True
@@ -1,11 +1,13 @@
1
1
  from pydantic import BaseModel, Field
2
+ from maleo_foundation.enums import BaseEnums
2
3
 
3
4
  class DatabaseConfigurations(BaseModel):
5
+ environment: BaseEnums.EnvironmentType = Field(..., description="Database's environment")
4
6
  username: str = Field("postgres", description="Database user's username")
5
7
  password: str = Field(..., description="Database user's password")
6
8
  host: str = Field(..., description="Database's host")
7
9
  port: int = Field(5432, description="Database's port")
8
- database: str = Field(..., description="Database")
10
+ database: str = Field(..., description="Database's name")
9
11
 
10
12
  @property
11
13
  def url(self) -> str:
@@ -1,6 +1,8 @@
1
1
  from pydantic_settings import BaseSettings
2
- from pydantic import Field
2
+ from pydantic import Field, model_validator
3
+ from typing import Self
3
4
  from maleo_foundation.enums import BaseEnums
5
+ from maleo_foundation.types import BaseTypes
4
6
 
5
7
  class Settings(BaseSettings):
6
8
  ENVIRONMENT: BaseEnums.EnvironmentType = Field(..., description="Environment")
@@ -9,11 +11,67 @@ class Settings(BaseSettings):
9
11
  "/credentials/maleo-google-service-account.json",
10
12
  description="Internal credential's file path"
11
13
  )
12
- STATIC_CONFIGURATIONS_PATH: str = Field(
13
- "configs/static.yaml",
14
+ USE_LOCAL_STATIC_CONFIGURATIONS: bool = Field(
15
+ False,
16
+ description="Whether to use local static configurations"
17
+ )
18
+ STATIC_CONFIGURATIONS_PATH: BaseTypes.OptionalString = Field(
19
+ None,
14
20
  description="Maleo's static configurations path"
15
21
  )
16
- RUNTIME_CONFIGURATIONS_PATH: str = Field(
17
- "configs/runtime.yaml",
22
+ USE_LOCAL_RUNTIME_CONFIGURATIONS: bool = Field(
23
+ False,
24
+ description="Whether to use local runtime configurations"
25
+ )
26
+ RUNTIME_CONFIGURATIONS_PATH: BaseTypes.OptionalString = Field(
27
+ None,
18
28
  description="Service's runtime configurations path"
19
- )
29
+ )
30
+
31
+ @classmethod
32
+ @model_validator(mode="before")
33
+ def define_configurations_path(
34
+ cls,
35
+ values: BaseTypes.StringToAnyDict
36
+ ) -> BaseTypes.StringToAnyDict:
37
+ # Define and check environment
38
+ environment: BaseTypes.OptionalString = values.get("ENVIRONMENT", None)
39
+ if environment is None:
40
+ raise ValueError("'ENVIRONMENT' variable not defined/found")
41
+
42
+ # Define and check service key
43
+ service_key: BaseTypes.OptionalString = values.get("SERVICE_KEY", None)
44
+ if service_key is None:
45
+ raise ValueError("'SERVICE_KEY' variable not defined/found")
46
+
47
+ # Define and check use local static configurations
48
+ use_local_static_configurations: BaseTypes.OptionalBoolean = values.get("USE_LOCAL_STATIC_CONFIGURATIONS", None)
49
+ if use_local_static_configurations is None:
50
+ raise ValueError("'USE_LOCAL_STATIC_CONFIGURATIONS' variable not defined/found")
51
+
52
+ # Define static configurations path if necessary
53
+ static_configurations_path: BaseTypes.OptionalString = values.get("STATIC_CONFIGURATIONS_PATH", None)
54
+ if use_local_static_configurations and static_configurations_path is None:
55
+ values["STATIC_CONFIGURATIONS_PATH"] = f"/configurations/maleo-static-configurations-{environment}"
56
+
57
+ # Define and check use local runtime configurations
58
+ use_local_runtime_configurations: BaseTypes.OptionalBoolean = values.get("USE_LOCAL_RUNTIME_CONFIGURATIONS", None)
59
+ if use_local_runtime_configurations is None:
60
+ raise ValueError("'USE_LOCAL_RUNTIME_CONFIGURATIONS' variable not defined/found")
61
+
62
+ # Define runtime configurations path if necessary
63
+ runtime_configurations_path: BaseTypes.OptionalString = values.get("RUNTIME_CONFIGURATIONS_PATH", None)
64
+ if use_local_runtime_configurations and runtime_configurations_path is None:
65
+ values["RUNTIME_CONFIGURATIONS_PATH"] = f"/configurations/{service_key}-runtime-configurations-{environment}"
66
+
67
+ return values
68
+
69
+ @model_validator(mode="after")
70
+ def validate_configurations_path(self) -> Self:
71
+ if self.USE_LOCAL_STATIC_CONFIGURATIONS and self.STATIC_CONFIGURATIONS_PATH is None:
72
+ raise ValueError("Static configurations path must exist if use local static configurations is set to true")
73
+
74
+ if self.USE_LOCAL_RUNTIME_CONFIGURATIONS and self.RUNTIME_CONFIGURATIONS_PATH is None:
75
+ raise ValueError("Runtime configurations path must exist if use local runtime configurations is set to true")
76
+
77
+ return self
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.3.9
3
+ Version: 0.3.10
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -33,11 +33,11 @@ maleo_foundation/expanded_types/encryption/aes.py,sha256=1rj43qjIO0TePpr1mErT_NJ
33
33
  maleo_foundation/expanded_types/encryption/rsa.py,sha256=Esf_H8nMz2kOLAWa3M7dlD-sFdFIZylNjB_qB20Yaww,488
34
34
  maleo_foundation/managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  maleo_foundation/managers/cache.py,sha256=91IvQGCXC3QkhB61m6qLDMaRykmMYOwzMgrSOodfY1A,257
36
- maleo_foundation/managers/configuration.py,sha256=hffeNqAuqRTPVv7ZBT7jOC95blfgn5fNCxFPZnl-WSQ,3980
36
+ maleo_foundation/managers/configuration.py,sha256=JPXgxNVBO_i7Znqwa36uMMXLU9LBDldvak-jKoP75W0,3420
37
37
  maleo_foundation/managers/credential.py,sha256=pTsd1sPFw64cOfSffqsdJFkVfsciqxjAvvt6RZJCkDY,3116
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=1YrVqYGdC1bY8mZxHraa4uq43PB2LzHem8dYAzkKTWg,10681
40
+ maleo_foundation/managers/service.py,sha256=1rqxXMJ9E-pla0LuhKZ83JS4boTnUhiXxn1EbzYQlWA,10859
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=JCbuIWu5gW--o7H8xvWtSNb_Of3d05FKLRTcvDciLfE,2662
@@ -68,11 +68,11 @@ maleo_foundation/models/transfers/general/credentials.py,sha256=kLS0ymFipQmL3QaA
68
68
  maleo_foundation/models/transfers/general/database.py,sha256=E3bWaMlvxIRrEGUT29AN5k42FNI5MnrmLq9rnEh0igE,2033
69
69
  maleo_foundation/models/transfers/general/key.py,sha256=S37SqD3qwTbgMk7785hW7Kl9d4Kouh4uPZcGoyMQ_-Q,755
70
70
  maleo_foundation/models/transfers/general/request.py,sha256=NTYFOmucc4bMfoocBeHGNLs6mbRdqXyVtp1_yDiv_Gg,4849
71
- maleo_foundation/models/transfers/general/settings.py,sha256=gR-IB-j137h2LkbHjjU43TWMtDt54VkvE75UPk9o590,734
71
+ maleo_foundation/models/transfers/general/settings.py,sha256=bEvsbhlFi5DO2tS3OmxL2LAG3q1cesW3ceYsT5iGNsE,3702
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=-23Mm8_i_NRMagdNvGaL25pcscnmrXO-R7kAEgACkEI,1981
75
- maleo_foundation/models/transfers/general/configurations/database.py,sha256=7osPd5NTf8wYEevcPT_60yEAcC0W9-MrW4lSwLi8nqQ,544
74
+ maleo_foundation/models/transfers/general/configurations/__init__.py,sha256=ZYXbqNkj-PHNuS8PsPtMB291s88K3wGi_PK2zJSeiX4,2010
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=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
@@ -134,7 +134,7 @@ maleo_foundation/utils/loaders/credential/__init__.py,sha256=qopTKvcMVoTFwyRijeg
134
134
  maleo_foundation/utils/loaders/credential/google.py,sha256=vmVObdAyXehb3L6ASOuUJ63mNvGPb9fiXSpdRndN-4A,6528
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.9.dist-info/METADATA,sha256=_IEwOxUJRRKiWlKtJ45I4-5WOIJVeaskuX6kh3buuq4,3739
138
- maleo_foundation-0.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
139
- maleo_foundation-0.3.9.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
140
- maleo_foundation-0.3.9.dist-info/RECORD,,
137
+ maleo_foundation-0.3.10.dist-info/METADATA,sha256=WC7PtWk0jsVpJqU8rnErqEcam_3nsXaSmWG1YMcZf_0,3740
138
+ maleo_foundation-0.3.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
139
+ maleo_foundation-0.3.10.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
140
+ maleo_foundation-0.3.10.dist-info/RECORD,,