maleo-foundation 0.3.3__py3-none-any.whl → 0.3.5__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.
Files changed (29) hide show
  1. maleo_foundation/constants.py +3 -3
  2. maleo_foundation/enums.py +18 -5
  3. maleo_foundation/managers/cache.py +9 -0
  4. maleo_foundation/managers/client/google/subscription.py +140 -0
  5. maleo_foundation/managers/configuration.py +100 -0
  6. maleo_foundation/managers/credential.py +82 -0
  7. maleo_foundation/managers/middleware.py +5 -37
  8. maleo_foundation/managers/service.py +62 -237
  9. maleo_foundation/middlewares/authentication.py +1 -7
  10. maleo_foundation/models/schemas/parameter.py +1 -1
  11. maleo_foundation/models/transfers/general/configurations/__init__.py +45 -0
  12. maleo_foundation/{managers → models/transfers/general/configurations}/cache/__init__.py +1 -8
  13. maleo_foundation/models/transfers/general/configurations/client/__init__.py +8 -0
  14. maleo_foundation/models/transfers/general/configurations/client/maleo.py +23 -0
  15. maleo_foundation/models/transfers/general/configurations/database.py +12 -0
  16. maleo_foundation/models/transfers/general/configurations/middleware.py +60 -0
  17. maleo_foundation/models/transfers/general/configurations/service.py +7 -0
  18. maleo_foundation/models/transfers/general/credentials.py +9 -0
  19. maleo_foundation/models/transfers/general/database.py +3 -2
  20. maleo_foundation/models/transfers/general/settings.py +19 -0
  21. maleo_foundation/utils/cache.py +27 -0
  22. maleo_foundation/utils/loaders/credential/google.py +134 -1
  23. maleo_foundation/utils/logging.py +1 -18
  24. {maleo_foundation-0.3.3.dist-info → maleo_foundation-0.3.5.dist-info}/METADATA +5 -2
  25. {maleo_foundation-0.3.3.dist-info → maleo_foundation-0.3.5.dist-info}/RECORD +28 -16
  26. maleo_foundation/managers/cache/base.py +0 -29
  27. /maleo_foundation/{managers → models/transfers/general/configurations}/cache/redis.py +0 -0
  28. {maleo_foundation-0.3.3.dist-info → maleo_foundation-0.3.5.dist-info}/WHEEL +0 -0
  29. {maleo_foundation-0.3.3.dist-info → maleo_foundation-0.3.5.dist-info}/top_level.txt +0 -0
@@ -1,16 +1,12 @@
1
1
  from fastapi import FastAPI, APIRouter
2
2
  from fastapi.exceptions import RequestValidationError
3
3
  from google.oauth2.service_account import Credentials
4
- from pathlib import Path
5
- from pydantic_settings import BaseSettings
6
- from pydantic import BaseModel, Field
7
4
  from redis.asyncio.client import Redis
8
5
  from redis.exceptions import RedisError
9
6
  from starlette.exceptions import HTTPException
10
7
  from starlette.types import Lifespan, AppType
11
8
  from sqlalchemy import MetaData
12
9
  from typing import Optional
13
- from uuid import UUID
14
10
  from maleo_foundation.client.manager import MaleoFoundationClientManager
15
11
  from maleo_foundation.enums import BaseEnums
16
12
  from maleo_foundation.models.schemas.general import BaseGeneralSchemas
@@ -18,126 +14,26 @@ from maleo_foundation.models.transfers.general.token \
18
14
  import MaleoFoundationTokenGeneralTransfers
19
15
  from maleo_foundation.models.transfers.parameters.token \
20
16
  import MaleoFoundationTokenParametersTransfers
21
- from maleo_foundation.managers.cache import CacheConfigurations, CacheManagers
22
- from maleo_foundation.managers.cache.redis import (
23
- RedisCacheNamespaces,
24
- RedisCacheConfigurations
17
+ from maleo_foundation.models.transfers.general.configurations import (
18
+ Configurations,
19
+ Loggers
25
20
  )
26
- from maleo_foundation.managers.db import DatabaseConfigurations, DatabaseManager
27
- from maleo_foundation.managers.client.google.secret import GoogleSecretManager
21
+ from maleo_foundation.models.transfers.general.credentials import MaleoCredentials
22
+ from maleo_foundation.models.transfers.general.settings import Settings
23
+ from maleo_foundation.managers.cache import CacheManagers
24
+ from maleo_foundation.managers.db import DatabaseManager
28
25
  from maleo_foundation.managers.client.google.storage import GoogleCloudStorage
29
- from maleo_foundation.managers.middleware import (
30
- MiddlewareConfigurations,
31
- BaseMiddlewareConfigurations,
32
- CORSMiddlewareConfigurations,
33
- GeneralMiddlewareConfigurations,
34
- MiddlewareLoggers,
35
- MiddlewareManager
36
- )
26
+ from maleo_foundation.managers.client.google.secret import GoogleSecretManager
27
+ from maleo_foundation.managers.middleware import MiddlewareManager
37
28
  from maleo_foundation.types import BaseTypes
38
29
  from maleo_foundation.utils.exceptions import BaseExceptions
39
- from maleo_foundation.utils.loaders.yaml import YAMLLoader
40
30
  from maleo_foundation.utils.logging import (
41
31
  SimpleConfig,
42
32
  ServiceLogger,
43
33
  MiddlewareLogger
44
34
  )
45
- from maleo_foundation.utils.merger import deep_merge
46
-
47
- class Settings(BaseSettings):
48
- ENVIRONMENT: BaseEnums.EnvironmentType = Field(..., description="Environment")
49
- SERVICE_KEY: str = Field(..., description="Service's key")
50
- GOOGLE_CREDENTIALS_PATH: str = Field("credentials/maleo-google-service-account.json", description="Internal credential's file path")
51
- STATIC_CONFIGURATIONS_PATH: str = Field("configs/static.yaml", description="Maleo's static configurations path")
52
- RUNTIME_CONFIGURATIONS_PATH: str = Field("configs/runtime.yaml", description="Service's runtime configurations path")
53
-
54
- class MaleoCredentials(BaseModel):
55
- id: int = Field(..., description="ID")
56
- uuid: UUID = Field(..., description="UUID")
57
- username: str = Field(..., description="Username")
58
- email: str = Field(..., description="Email")
59
- password: str = Field(..., description="Password")
60
-
61
- class MiddlewareRuntimeConfigurations(BaseModel):
62
- base: BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
63
-
64
- class Config:
65
- arbitrary_types_allowed=True
66
-
67
- class ServiceConfigurations(BaseModel):
68
- key: str = Field(..., description="Service's key")
69
- name: str = Field(..., description="Service's name")
70
- host: str = Field(..., description="Service's host")
71
- port: int = Field(..., description="Service's port")
72
-
73
- class RuntimeConfigurations(BaseModel):
74
- service: ServiceConfigurations = Field(..., description="Service's configurations")
75
- middleware: MiddlewareRuntimeConfigurations = Field(..., description="Middleware's runtime configurations")
76
- database: str = Field(..., description="Database's name")
77
-
78
- class Config:
79
- arbitrary_types_allowed=True
80
-
81
- class MiddlewareStaticConfigurations(BaseModel):
82
- general: GeneralMiddlewareConfigurations = Field(..., description="Middleware's general configurations")
83
- cors: CORSMiddlewareConfigurations = Field(..., description="CORS middleware's configurations")
84
-
85
- class Config:
86
- arbitrary_types_allowed=True
87
-
88
- class MaleoClientConfiguration(BaseModel):
89
- key: str = Field(..., description="Client's key")
90
- name: str = Field(..., description="Client's name")
91
- url: str = Field(..., description="Client's URL")
92
-
93
- class MaleoClientConfigurations(BaseModel):
94
- telemetry: MaleoClientConfiguration = Field(..., description="MaleoTelemetry client's configuration")
95
- metadata: MaleoClientConfiguration = Field(..., description="MaleoMetadata client's configuration")
96
- identity: MaleoClientConfiguration = Field(..., description="MaleoIdentity client's configuration")
97
- access: MaleoClientConfiguration = Field(..., description="MaleoAccess client's configuration")
98
- workshop: MaleoClientConfiguration = Field(..., description="MaleoWorkshop client's configuration")
99
- medix: MaleoClientConfiguration = Field(..., description="MaleoMedix client's configuration")
100
- fhir: MaleoClientConfiguration = Field(..., description="MaleoFHIR client's configuration")
101
- dicom: MaleoClientConfiguration = Field(..., description="MaleoDICOM client's configuration")
102
- scribe: MaleoClientConfiguration = Field(..., description="MaleoScribe client's configuration")
103
- cds: MaleoClientConfiguration = Field(..., description="MaleoCDS client's configuration")
104
- imaging: MaleoClientConfiguration = Field(..., description="MaleoImaging client's configuration")
105
- mcu: MaleoClientConfiguration = Field(..., description="MaleoMCU client's configuration")
106
-
107
- class Config:
108
- arbitrary_types_allowed=True
109
-
110
- class ClientConfigurations(BaseModel):
111
- maleo: MaleoClientConfigurations = Field(..., description="Maleo client's configurations")
112
-
113
- class Config:
114
- arbitrary_types_allowed=True
115
-
116
- class StaticConfigurations(BaseModel):
117
- middleware: MiddlewareStaticConfigurations = Field(..., description="Middleware's static configurations")
118
- client: ClientConfigurations = Field(..., description="Client's configurations")
119
-
120
- class Config:
121
- arbitrary_types_allowed=True
122
-
123
- class Configurations(BaseModel):
124
- service: ServiceConfigurations = Field(..., description="Service's configurations")
125
- middleware: MiddlewareConfigurations = Field(..., description="Middleware's configurations")
126
- cache: CacheConfigurations = Field(..., description="Cache's configurations")
127
- database: DatabaseConfigurations = Field(..., description="Database's configurations")
128
- client: ClientConfigurations = Field(..., description="Client's configurations")
129
-
130
- class Config:
131
- arbitrary_types_allowed=True
132
-
133
- class Loggers(BaseModel):
134
- application: ServiceLogger = Field(..., description="Application logger")
135
- repository: ServiceLogger = Field(..., description="Repository logger")
136
- database: ServiceLogger = Field(..., description="Database logger")
137
- middleware: MiddlewareLoggers = Field(..., description="Middleware logger")
138
-
139
- class Config:
140
- arbitrary_types_allowed=True
35
+ from .credential import CredentialManager
36
+ from .configuration import ConfigurationManager
141
37
 
142
38
  class ServiceManager:
143
39
  def __init__(
@@ -149,13 +45,22 @@ class ServiceManager:
149
45
  self._db_metadata = db_metadata #* Declare DB Metadata
150
46
  self._log_config = log_config #* Declare log config
151
47
  self._settings = settings if settings is not None else Settings() #* Initialize settings
48
+
152
49
  #* Disable google cloud logging if environment is local
153
50
  if self._settings.ENVIRONMENT == "local":
154
51
  self._log_config.google_cloud_logging = None
155
- self._load_google_credentials()
156
- self._initialize_secret_manager()
157
- self._load_maleo_credentials()
158
- self._load_configs()
52
+
53
+ #* Initialize Managers
54
+ self._credential_manager = CredentialManager(
55
+ settings=self._settings,
56
+ log_config=self._log_config
57
+ )
58
+
59
+ self._configuration_manager = ConfigurationManager(
60
+ settings=self._settings,
61
+ credential_manager=self._credential_manager
62
+ )
63
+
159
64
  self._load_keys()
160
65
  self._initialize_loggers()
161
66
  self._initialize_cache()
@@ -163,107 +68,34 @@ class ServiceManager:
163
68
  self._initialize_db()
164
69
  self._initialize_foundation()
165
70
 
166
- @property
167
- def log_config(self) -> SimpleConfig:
168
- return self._log_config
169
-
170
71
  @property
171
72
  def settings(self) -> Settings:
172
73
  return self._settings
173
-
174
- def _load_google_credentials(self) -> None:
175
- self._google_credentials = Credentials.from_service_account_file(self._settings.GOOGLE_CREDENTIALS_PATH)
176
-
74
+
177
75
  @property
178
- def google_credentials(self) -> None:
179
- return self._google_credentials
180
-
181
- def _initialize_secret_manager(self) -> None:
182
- self._secret_manager = GoogleSecretManager(
183
- log_config=self._log_config,
184
- service_key=self._settings.SERVICE_KEY,
185
- credentials=self._google_credentials
186
- )
187
-
76
+ def log_config(self) -> SimpleConfig:
77
+ return self._log_config
78
+
79
+ @property
80
+ def google_credentials(self) -> Credentials:
81
+ return self._credential_manager.google_credentials
82
+
188
83
  @property
189
84
  def secret_manager(self) -> GoogleSecretManager:
190
- return self._secret_manager
191
-
192
- def _load_maleo_credentials(self) -> None:
193
- environment = (
194
- BaseEnums.EnvironmentType.STAGING
195
- if self._settings.ENVIRONMENT == BaseEnums.EnvironmentType.LOCAL
196
- else self._settings.ENVIRONMENT
197
- )
198
- id = int(self._secret_manager.get(f"maleo-service-account-id-{environment}"))
199
- uuid = self._secret_manager.get(f"maleo-service-account-uuid-{environment}")
200
- email = self._secret_manager.get("maleo-service-account-email")
201
- username = self._secret_manager.get("maleo-service-account-username")
202
- password = self._secret_manager.get("maleo-service-account-password")
203
- self._maleo_credentials = MaleoCredentials(
204
- id=id,
205
- uuid=UUID(uuid),
206
- username=username,
207
- email=email,
208
- password=password
209
- )
210
-
85
+ return self._credential_manager.secret_manager
86
+
211
87
  @property
212
88
  def maleo_credentials(self) -> MaleoCredentials:
213
- return self._maleo_credentials
214
-
215
- def _load_configs(self) -> None:
216
- #* Load static configurations
217
- static_configurations_path = Path(self._settings.STATIC_CONFIGURATIONS_PATH)
218
- if static_configurations_path.exists() and static_configurations_path.is_file():
219
- static_configurations = YAMLLoader.load_from_path(self._settings.STATIC_CONFIGURATIONS_PATH)
220
- else:
221
- data = self._secret_manager.get(f"maleo-static-config-{self._settings.ENVIRONMENT}")
222
- static_configurations = YAMLLoader.load_from_string(data)
223
- static_configs = StaticConfigurations.model_validate(static_configurations)
224
-
225
- #* Load runtime configurations
226
- runtime_configurations_path = Path(self._settings.RUNTIME_CONFIGURATIONS_PATH)
227
- if runtime_configurations_path.exists() and runtime_configurations_path.is_file():
228
- runtime_configurations = YAMLLoader.load_from_path(self._settings.RUNTIME_CONFIGURATIONS_PATH)
229
- else:
230
- data = self._secret_manager.get(f"{self._settings.SERVICE_KEY}-runtime-config-{self._settings.ENVIRONMENT}")
231
- runtime_configurations = YAMLLoader.load_from_string(data)
232
- runtime_configs = RuntimeConfigurations.model_validate(runtime_configurations)
233
-
234
- #* Load redis cache configurations
235
- namespaces = RedisCacheNamespaces(base=self._settings.SERVICE_KEY)
236
- host = self._secret_manager.get(name=f"maleo-redis-host-{self._settings.ENVIRONMENT}")
237
- password = self._secret_manager.get(name=f"maleo-redis-password-{self._settings.ENVIRONMENT}")
238
- redis = RedisCacheConfigurations(namespaces=namespaces, host=host, password=password)
239
- cache = CacheConfigurations(redis=redis)
240
-
241
- #* Load database configurations
242
- password = self._secret_manager.get(name=f"maleo-db-password-{self._settings.ENVIRONMENT}")
243
- host = self._secret_manager.get(name=f"maleo-db-host-{self._settings.ENVIRONMENT}")
244
- database = DatabaseConfigurations(
245
- password=password,
246
- host=host,
247
- database=runtime_configs.database
248
- )
249
-
250
- #* Load whole configurations
251
- merged_configs = deep_merge(
252
- static_configs.model_dump(),
253
- runtime_configs.model_dump(exclude={"database"}),
254
- {"cache": cache.model_dump()},
255
- {"database": database.model_dump()}
256
- )
257
- self._configs = Configurations.model_validate(merged_configs)
258
-
89
+ return self._credential_manager.maleo_credentials
90
+
259
91
  @property
260
92
  def configs(self) -> Configurations:
261
- return self._configs
93
+ return self._configuration_manager.configs
262
94
 
263
95
  def _load_keys(self) -> None:
264
- password = self._secret_manager.get(name="maleo-key-password")
265
- private = self._secret_manager.get(name="maleo-private-key")
266
- public = self._secret_manager.get(name="maleo-public-key")
96
+ password = self.secret_manager.get(name="maleo-key-password")
97
+ private = self.secret_manager.get(name="maleo-private-key")
98
+ public = self.secret_manager.get(name="maleo-public-key")
267
99
  self._keys = BaseGeneralSchemas.RSAKeys(
268
100
  password=password,
269
101
  private=private,
@@ -278,31 +110,24 @@ class ServiceManager:
278
110
  #* Service's loggers
279
111
  application = ServiceLogger(
280
112
  type=BaseEnums.LoggerType.APPLICATION,
281
- service_key=self._configs.service.key,
113
+ service_key=self.configs.service.key,
282
114
  **self._log_config.model_dump()
283
115
  )
284
116
  database = ServiceLogger(
285
117
  type=BaseEnums.LoggerType.DATABASE,
286
- service_key=self._configs.service.key,
118
+ service_key=self.configs.service.key,
287
119
  **self._log_config.model_dump()
288
120
  )
289
121
  repository = ServiceLogger(
290
122
  type=BaseEnums.LoggerType.REPOSITORY,
291
- service_key=self._configs.service.key,
292
- **self._log_config.model_dump()
293
- )
294
- #* Middleware's loggers
295
- base = MiddlewareLogger(
296
- middleware_type=BaseEnums.MiddlewareLoggerType.BASE,
297
- service_key=self._configs.service.key,
123
+ service_key=self.configs.service.key,
298
124
  **self._log_config.model_dump()
299
125
  )
300
- authentication = MiddlewareLogger(
301
- middleware_type=BaseEnums.MiddlewareLoggerType.AUTHENTICATION,
302
- service_key=self._configs.service.key,
126
+ #* Middleware's logger
127
+ middleware = MiddlewareLogger(
128
+ service_key=self.configs.service.key,
303
129
  **self._log_config.model_dump()
304
130
  )
305
- middleware = MiddlewareLoggers(base=base, authentication=authentication)
306
131
  self._loggers = Loggers(
307
132
  application=application,
308
133
  repository=repository,
@@ -316,12 +141,12 @@ class ServiceManager:
316
141
 
317
142
  def _initialize_cache(self) -> None:
318
143
  self._redis = Redis(
319
- host=self._configs.cache.redis.host,
320
- port=self._configs.cache.redis.port,
321
- db=self._configs.cache.redis.db,
322
- password=self._configs.cache.redis.password,
323
- decode_responses=self._configs.cache.redis.decode_responses,
324
- health_check_interval=self._configs.cache.redis.health_check_interval
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
325
150
  )
326
151
  self._cache = CacheManagers(redis=self._redis)
327
152
 
@@ -352,7 +177,7 @@ class ServiceManager:
352
177
  log_config=self._log_config,
353
178
  service_key=self._settings.SERVICE_KEY,
354
179
  bucket_name=f"maleo-suite-{environment}",
355
- credentials=self._google_credentials,
180
+ credentials=self.google_credentials,
356
181
  redis=self._redis
357
182
  )
358
183
 
@@ -364,7 +189,7 @@ class ServiceManager:
364
189
  self._database = DatabaseManager(
365
190
  metadata=self._db_metadata,
366
191
  logger=self._loggers.database,
367
- url=self._configs.database.url
192
+ url=self.configs.database.url
368
193
  )
369
194
 
370
195
  @property
@@ -385,12 +210,12 @@ class ServiceManager:
385
210
  def token(self) -> BaseTypes.OptionalString:
386
211
  payload = MaleoFoundationTokenGeneralTransfers.BaseEncodePayload(
387
212
  iss=None,
388
- sub=str(self._maleo_credentials.id),
213
+ sub=str(self.maleo_credentials.id),
389
214
  sr="administrator",
390
- u_i=self._maleo_credentials.id,
391
- u_uu=self._maleo_credentials.uuid,
392
- u_u=self._maleo_credentials.username,
393
- u_e=self._maleo_credentials.email,
215
+ u_i=self.maleo_credentials.id,
216
+ u_uu=self.maleo_credentials.uuid,
217
+ u_u=self.maleo_credentials.username,
218
+ u_e=self.maleo_credentials.email,
394
219
  u_ut="service",
395
220
  exp_in=1
396
221
  )
@@ -408,9 +233,9 @@ class ServiceManager:
408
233
  lifespan: Optional[Lifespan[AppType]] = None
409
234
  ) -> FastAPI:
410
235
  self._loggers.application.info("Creating FastAPI application")
411
- root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self._configs.service.key.removeprefix("maleo-")}"
236
+ root_path = "" if self._settings.ENVIRONMENT == "local" else f"/{self.configs.service.key.removeprefix("maleo-")}"
412
237
  self._app = FastAPI(
413
- title=self._configs.service.name,
238
+ title=self.configs.service.name,
414
239
  lifespan=lifespan,
415
240
  root_path=root_path
416
241
  )
@@ -420,7 +245,7 @@ class ServiceManager:
420
245
  self._loggers.application.info("Configuring middlewares")
421
246
  self._middleware = MiddlewareManager(
422
247
  app=self._app,
423
- configurations=self._configs.middleware,
248
+ configurations=self.configs.middleware,
424
249
  keys=self._keys,
425
250
  loggers=self._loggers.middleware,
426
251
  maleo_foundation=self._foundation
@@ -16,12 +16,10 @@ class Backend(AuthenticationBackend):
16
16
  def __init__(
17
17
  self,
18
18
  keys: BaseGeneralSchemas.RSAKeys,
19
- logger: MiddlewareLogger,
20
19
  maleo_foundation: MaleoFoundationClientManager
21
20
  ):
22
21
  super().__init__()
23
22
  self._keys = keys
24
- self._logger = logger
25
23
  self._maleo_foundation = maleo_foundation
26
24
 
27
25
  async def authenticate(
@@ -100,7 +98,6 @@ class Backend(AuthenticationBackend):
100
98
  def add_authentication_middleware(
101
99
  app: FastAPI,
102
100
  keys: BaseGeneralSchemas.RSAKeys,
103
- logger: MiddlewareLogger,
104
101
  maleo_foundation: MaleoFoundationClientManager
105
102
  ) -> None:
106
103
  """
@@ -110,9 +107,6 @@ def add_authentication_middleware(
110
107
  app: FastAPI
111
108
  The FastAPI application instance to which the middleware will be added.
112
109
 
113
- logger: MiddlewareLogger
114
- Authentication middleware logger to be used.
115
-
116
110
  key: str
117
111
  Public key to be used for token decoding.
118
112
 
@@ -130,6 +124,6 @@ def add_authentication_middleware(
130
124
  """
131
125
  app.add_middleware(
132
126
  AuthenticationMiddleware,
133
- backend=Backend(keys, logger, maleo_foundation),
127
+ backend=Backend(keys, maleo_foundation),
134
128
  on_error=BaseExceptions.authentication_error_handler
135
129
  )
@@ -9,7 +9,7 @@ from maleo_foundation.extended_types import ExtendedTypes
9
9
 
10
10
  class BaseParameterSchemas:
11
11
  class IdentifierType(BaseModel):
12
- identifier: BaseEnums.IdentifierTypes = Field(..., description="Data's identifier type")
12
+ identifier: BaseEnums.IdentifierType = Field(..., description="Data's identifier type")
13
13
 
14
14
  class IdentifierValue(BaseModel):
15
15
  value: BaseTypes.IdentifierValue = Field(..., description="Data's identifier value")
@@ -0,0 +1,45 @@
1
+ from pydantic import BaseModel, Field
2
+ from maleo_foundation.utils.logging import MiddlewareLogger, ServiceLogger
3
+ from .cache import CacheConfigurations
4
+ from .client import ClientConfigurations
5
+ from .database import DatabaseConfigurations
6
+ from .middleware import (
7
+ MiddlewareRuntimeConfigurations,
8
+ MiddlewareStaticConfigurations,
9
+ MiddlewareConfigurations
10
+ )
11
+ from .service import ServiceConfigurations
12
+
13
+ class RuntimeConfigurations(BaseModel):
14
+ service: ServiceConfigurations = Field(..., description="Service's configurations")
15
+ middleware: MiddlewareRuntimeConfigurations = Field(..., description="Middleware's runtime configurations")
16
+ database: str = Field(..., description="Database's name")
17
+
18
+ class Config:
19
+ arbitrary_types_allowed=True
20
+
21
+ class StaticConfigurations(BaseModel):
22
+ middleware: MiddlewareStaticConfigurations = Field(..., description="Middleware's static configurations")
23
+ client: ClientConfigurations = Field(..., description="Client's configurations")
24
+
25
+ class Config:
26
+ arbitrary_types_allowed=True
27
+
28
+ class Configurations(BaseModel):
29
+ service: ServiceConfigurations = Field(..., description="Service's configurations")
30
+ middleware: MiddlewareConfigurations = Field(..., description="Middleware's configurations")
31
+ cache: CacheConfigurations = Field(..., description="Cache's configurations")
32
+ database: DatabaseConfigurations = Field(..., description="Database's configurations")
33
+ client: ClientConfigurations = Field(..., description="Client's configurations")
34
+
35
+ class Config:
36
+ arbitrary_types_allowed=True
37
+
38
+ class Loggers(BaseModel):
39
+ application: ServiceLogger = Field(..., description="Application logger")
40
+ repository: ServiceLogger = Field(..., description="Repository logger")
41
+ database: ServiceLogger = Field(..., description="Database logger")
42
+ middleware: MiddlewareLogger = Field(..., description="Middleware logger")
43
+
44
+ class Config:
45
+ arbitrary_types_allowed=True
@@ -1,15 +1,8 @@
1
1
  from __future__ import annotations
2
2
  from pydantic import BaseModel, Field
3
- from redis.asyncio.client import Redis
4
3
  from .redis import RedisCacheConfigurations
5
4
 
6
5
  SKIP_CACHE_FUNC = lambda x: x is None
7
6
 
8
7
  class CacheConfigurations(BaseModel):
9
- redis:RedisCacheConfigurations = Field(..., description="Redis cache's configurations")
10
-
11
- class CacheManagers(BaseModel):
12
- redis:Redis = Field(..., description="Redis client")
13
-
14
- class Config:
15
- arbitrary_types_allowed=True
8
+ redis:RedisCacheConfigurations = Field(..., description="Redis cache's configurations")
@@ -0,0 +1,8 @@
1
+ from pydantic import BaseModel, Field
2
+ from .maleo import MaleoClientsConfigurations
3
+
4
+ class ClientConfigurations(BaseModel):
5
+ maleo: MaleoClientsConfigurations = Field(..., description="Maleo client's configurations")
6
+
7
+ class Config:
8
+ arbitrary_types_allowed=True
@@ -0,0 +1,23 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+ class MaleoClientConfigurations(BaseModel):
4
+ key: str = Field(..., description="Client's key")
5
+ name: str = Field(..., description="Client's name")
6
+ url: str = Field(..., description="Client's URL")
7
+
8
+ class MaleoClientsConfigurations(BaseModel):
9
+ telemetry: MaleoClientConfigurations = Field(..., description="MaleoTelemetry client's configuration")
10
+ metadata: MaleoClientConfigurations = Field(..., description="MaleoMetadata client's configuration")
11
+ identity: MaleoClientConfigurations = Field(..., description="MaleoIdentity client's configuration")
12
+ access: MaleoClientConfigurations = Field(..., description="MaleoAccess client's configuration")
13
+ workshop: MaleoClientConfigurations = Field(..., description="MaleoWorkshop client's configuration")
14
+ medix: MaleoClientConfigurations = Field(..., description="MaleoMedix client's configuration")
15
+ fhir: MaleoClientConfigurations = Field(..., description="MaleoFHIR client's configuration")
16
+ dicom: MaleoClientConfigurations = Field(..., description="MaleoDICOM client's configuration")
17
+ scribe: MaleoClientConfigurations = Field(..., description="MaleoScribe client's configuration")
18
+ cds: MaleoClientConfigurations = Field(..., description="MaleoCDS client's configuration")
19
+ imaging: MaleoClientConfigurations = Field(..., description="MaleoImaging client's configuration")
20
+ mcu: MaleoClientConfigurations = Field(..., description="MaleoMCU client's configuration")
21
+
22
+ class Config:
23
+ arbitrary_types_allowed=True
@@ -0,0 +1,12 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+ class DatabaseConfigurations(BaseModel):
4
+ username: str = Field("postgres", description="Database user's username")
5
+ password: str = Field(..., description="Database user's password")
6
+ host: str = Field(..., description="Database's host")
7
+ port: int = Field(5432, description="Database's port")
8
+ database: str = Field(..., description="Database")
9
+
10
+ @property
11
+ def url(self) -> str:
12
+ return f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"
@@ -0,0 +1,60 @@
1
+ from pydantic import BaseModel, Field
2
+ from typing import List
3
+ from maleo_foundation.utils.logging import MiddlewareLogger
4
+
5
+ _ALLOW_METHODS: List[str] = [
6
+ "GET",
7
+ "POST",
8
+ "PUT",
9
+ "PATCH",
10
+ "DELETE",
11
+ "OPTIONS"
12
+ ]
13
+ _ALLOW_HEADERS: List[str] = [
14
+ "Authorization",
15
+ "Content-Type",
16
+ "X-Request-Id",
17
+ "X-Requested-At",
18
+ "X-Signature"
19
+ ]
20
+ _EXPOSE_HEADERS: List[str] = [
21
+ "X-New-Authorization",
22
+ "X-Process-Time",
23
+ "X-Request-Id",
24
+ "X-Requested-At",
25
+ "X-Responded-At",
26
+ "X-Signature"
27
+ ]
28
+
29
+ class GeneralMiddlewareConfigurations(BaseModel):
30
+ allow_origins: List[str] = Field(default_factory=list, description="Allowed origins")
31
+ allow_methods: List[str] = Field(_ALLOW_METHODS, description="Allowed methods")
32
+ allow_headers: list[str] = Field(_ALLOW_HEADERS, description="Allowed headers")
33
+ allow_credentials: bool = Field(True, description="Allowed credentials")
34
+
35
+ class CORSMiddlewareConfigurations(BaseModel):
36
+ expose_headers: List[str] = Field(_EXPOSE_HEADERS, description="Exposed headers")
37
+
38
+ class MiddlewareStaticConfigurations(BaseModel):
39
+ general: GeneralMiddlewareConfigurations = Field(..., description="Middleware's general configurations")
40
+ cors: CORSMiddlewareConfigurations = Field(..., description="CORS middleware's configurations")
41
+
42
+ class Config:
43
+ arbitrary_types_allowed=True
44
+
45
+ class BaseMiddlewareConfigurations(BaseModel):
46
+ limit: int = Field(10, description="Request limit (per 'window' seconds)")
47
+ window: int = Field(1, description="Request limit window (seconds)")
48
+ cleanup_interval: int = Field(60, description="Interval for middleware cleanup (seconds)")
49
+ ip_timeout: int = Field(300, description="Idle IP's timeout (seconds)")
50
+
51
+ class MiddlewareRuntimeConfigurations(BaseModel):
52
+ base: BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
53
+
54
+ class Config:
55
+ arbitrary_types_allowed=True
56
+
57
+ class MiddlewareConfigurations(BaseModel):
58
+ general: GeneralMiddlewareConfigurations = Field(..., description="Middleware's general configurations")
59
+ cors: CORSMiddlewareConfigurations = Field(..., description="CORS middleware's configurations")
60
+ base: BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
@@ -0,0 +1,7 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+ class ServiceConfigurations(BaseModel):
4
+ key: str = Field(..., description="Service's key")
5
+ name: str = Field(..., description="Service's name")
6
+ host: str = Field(..., description="Service's host")
7
+ port: int = Field(..., description="Service's port")
@@ -0,0 +1,9 @@
1
+ from pydantic import BaseModel, Field
2
+ from uuid import UUID
3
+
4
+ class MaleoCredentials(BaseModel):
5
+ id: int = Field(..., description="ID")
6
+ uuid: UUID = Field(..., description="UUID")
7
+ username: str = Field(..., description="Username")
8
+ email: str = Field(..., description="Email")
9
+ password: str = Field(..., description="Password")