maleo-foundation 0.2.96__py3-none-any.whl → 0.2.97__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 (63) hide show
  1. maleo_foundation/authentication.py +9 -9
  2. maleo_foundation/authorization.py +2 -2
  3. maleo_foundation/client/manager.py +11 -2
  4. maleo_foundation/client/services/encryption/aes.py +2 -2
  5. maleo_foundation/client/services/encryption/rsa.py +2 -2
  6. maleo_foundation/client/services/key.py +6 -3
  7. maleo_foundation/client/services/signature.py +2 -2
  8. maleo_foundation/client/services/token.py +2 -2
  9. maleo_foundation/constants.py +7 -7
  10. maleo_foundation/managers/cache/base.py +5 -1
  11. maleo_foundation/managers/cache/redis.py +12 -12
  12. maleo_foundation/managers/client/base.py +8 -8
  13. maleo_foundation/managers/client/google/base.py +6 -6
  14. maleo_foundation/managers/client/google/parameter.py +12 -5
  15. maleo_foundation/managers/client/google/secret.py +22 -7
  16. maleo_foundation/managers/client/google/storage.py +17 -17
  17. maleo_foundation/managers/client/maleo.py +9 -9
  18. maleo_foundation/managers/db.py +12 -12
  19. maleo_foundation/managers/middleware.py +22 -22
  20. maleo_foundation/managers/service.py +52 -52
  21. maleo_foundation/middlewares/authentication.py +11 -8
  22. maleo_foundation/middlewares/base.py +68 -64
  23. maleo_foundation/middlewares/cors.py +6 -6
  24. maleo_foundation/models/responses.py +37 -37
  25. maleo_foundation/models/schemas/encryption.py +5 -5
  26. maleo_foundation/models/schemas/general.py +33 -33
  27. maleo_foundation/models/schemas/hash.py +4 -4
  28. maleo_foundation/models/schemas/key.py +4 -4
  29. maleo_foundation/models/schemas/parameter.py +15 -15
  30. maleo_foundation/models/schemas/result.py +47 -47
  31. maleo_foundation/models/schemas/signature.py +5 -5
  32. maleo_foundation/models/schemas/token.py +4 -4
  33. maleo_foundation/models/transfers/general/__init__.py +63 -18
  34. maleo_foundation/models/transfers/general/key.py +4 -4
  35. maleo_foundation/models/transfers/general/token.py +71 -20
  36. maleo_foundation/models/transfers/parameters/token.py +1 -1
  37. maleo_foundation/models/transfers/results/client/controllers/http.py +4 -4
  38. maleo_foundation/models/transfers/results/encryption/aes.py +2 -2
  39. maleo_foundation/models/transfers/results/encryption/rsa.py +2 -2
  40. maleo_foundation/models/transfers/results/hash.py +2 -2
  41. maleo_foundation/models/transfers/results/key.py +3 -3
  42. maleo_foundation/models/transfers/results/signature.py +2 -2
  43. maleo_foundation/models/transfers/results/token.py +2 -2
  44. maleo_foundation/utils/cleaner.py +22 -0
  45. maleo_foundation/utils/client.py +6 -6
  46. maleo_foundation/utils/controller.py +8 -8
  47. maleo_foundation/utils/dependencies/auth.py +2 -2
  48. maleo_foundation/utils/dependencies/context.py +1 -1
  49. maleo_foundation/utils/exceptions.py +10 -10
  50. maleo_foundation/utils/extractor.py +2 -2
  51. maleo_foundation/utils/formatter/case.py +4 -4
  52. maleo_foundation/utils/loaders/credential/google.py +3 -1
  53. maleo_foundation/utils/loaders/json.py +2 -2
  54. maleo_foundation/utils/loaders/yaml.py +2 -2
  55. maleo_foundation/utils/logging.py +30 -24
  56. maleo_foundation/utils/merger.py +5 -2
  57. maleo_foundation/utils/query.py +48 -44
  58. maleo_foundation/utils/repository.py +8 -8
  59. maleo_foundation/utils/searcher.py +4 -1
  60. {maleo_foundation-0.2.96.dist-info → maleo_foundation-0.2.97.dist-info}/METADATA +1 -1
  61. {maleo_foundation-0.2.96.dist-info → maleo_foundation-0.2.97.dist-info}/RECORD +63 -62
  62. {maleo_foundation-0.2.96.dist-info → maleo_foundation-0.2.97.dist-info}/WHEEL +0 -0
  63. {maleo_foundation-0.2.96.dist-info → maleo_foundation-0.2.97.dist-info}/top_level.txt +0 -0
@@ -6,14 +6,14 @@ from maleo_foundation.models.transfers.general.token import MaleoFoundationToken
6
6
  from maleo_foundation.types import BaseTypes
7
7
 
8
8
  class Token(BaseModel):
9
- type:BaseEnums.TokenType = Field(..., description="Token's type")
10
- payload:MaleoFoundationTokenGeneralTransfers.DecodePayload = Field(..., description="Token's payload")
9
+ type: BaseEnums.TokenType = Field(..., description="Token's type")
10
+ payload: MaleoFoundationTokenGeneralTransfers.DecodePayload = Field(..., description="Token's payload")
11
11
 
12
12
  class Credentials(AuthCredentials):
13
13
  def __init__(
14
14
  self,
15
- token:Optional[Token] = None,
16
- scopes:Optional[Sequence[str]] = None
15
+ token: Optional[Token] = None,
16
+ scopes: Optional[Sequence[str]] = None
17
17
  ) -> None:
18
18
  self._token = token
19
19
  super().__init__(scopes)
@@ -25,9 +25,9 @@ class Credentials(AuthCredentials):
25
25
  class User(BaseUser):
26
26
  def __init__(
27
27
  self,
28
- authenticated:bool = True,
29
- username:str = "",
30
- email:str = ""
28
+ authenticated: bool = True,
29
+ username: str = "",
30
+ email: str = ""
31
31
  ) -> None:
32
32
  self._authenticated = authenticated
33
33
  self._username = username
@@ -46,8 +46,8 @@ class User(BaseUser):
46
46
  return self._email
47
47
 
48
48
  class Authentication(BaseModel):
49
- credentials:Credentials = Field(..., description="Credentials's information")
50
- user:User = Field(..., description="User's information")
49
+ credentials: Credentials = Field(..., description="Credentials's information")
50
+ user: User = Field(..., description="User's information")
51
51
 
52
52
  class Config:
53
53
  arbitrary_types_allowed=True
@@ -4,5 +4,5 @@ from pydantic import BaseModel, Field
4
4
  TOKEN_SCHEME = HTTPBearer()
5
5
 
6
6
  class Authorization(BaseModel):
7
- scheme:str = Field(..., description="Authorization's scheme")
8
- credentials:str = Field(..., description="Authorization's credentials")
7
+ scheme: str = Field(..., description="Authorization's scheme")
8
+ credentials: str = Field(..., description="Authorization's credentials")
@@ -21,10 +21,19 @@ from maleo_foundation.client.services import (
21
21
  )
22
22
 
23
23
  class MaleoFoundationClientManager(ClientManager):
24
- def __init__(self, log_config:SimpleConfig, service_key:BaseTypes.OptionalString=None):
24
+ def __init__(
25
+ self,
26
+ log_config: SimpleConfig,
27
+ service_key: BaseTypes.OptionalString = None
28
+ ) -> None:
25
29
  key = "maleo-foundation"
26
30
  name = "MaleoFoundation"
27
- super().__init__(key, name, log_config, service_key)
31
+ super().__init__(
32
+ key,
33
+ name,
34
+ log_config,
35
+ service_key
36
+ )
28
37
  self._initialize_services()
29
38
  self._logger.info("Client manager initialized successfully")
30
39
 
@@ -16,7 +16,7 @@ from maleo_foundation.utils.exceptions import BaseExceptions
16
16
  class MaleoFoundationAESEncryptionClientService(ClientService):
17
17
  def encrypt(
18
18
  self,
19
- parameters:MaleoFoundationAESEncryptionParametersTransfers.Encrypt
19
+ parameters: MaleoFoundationAESEncryptionParametersTransfers.Encrypt
20
20
  ) -> MaleoFoundationAESEncryptionResultsTypes.Encrypt:
21
21
  """Encrypt a plaintext using AES algorithm."""
22
22
  @BaseExceptions.service_exception_handler(
@@ -55,7 +55,7 @@ class MaleoFoundationAESEncryptionClientService(ClientService):
55
55
 
56
56
  def decrypt(
57
57
  self,
58
- parameters:MaleoFoundationAESEncryptionParametersTransfers.Decrypt
58
+ parameters: MaleoFoundationAESEncryptionParametersTransfers.Decrypt
59
59
  ) -> MaleoFoundationAESEncryptionResultsTypes.Decrypt:
60
60
  """Decrypt a ciphertext using AES algorithm."""
61
61
  @BaseExceptions.service_exception_handler(
@@ -17,7 +17,7 @@ from maleo_foundation.utils.loaders.key.rsa import RSAKeyLoader
17
17
  class MaleoFoundationRSAEncryptionClientService(ClientService):
18
18
  def encrypt(
19
19
  self,
20
- parameters:MaleoFoundationRSAEncryptionParametersTransfers.Encrypt
20
+ parameters: MaleoFoundationRSAEncryptionParametersTransfers.Encrypt
21
21
  ) -> MaleoFoundationRSAEncryptionResultsTypes.Encrypt:
22
22
  """Encrypt a plaintext using RSA algorithm."""
23
23
  @BaseExceptions.service_exception_handler(
@@ -67,7 +67,7 @@ class MaleoFoundationRSAEncryptionClientService(ClientService):
67
67
 
68
68
  def decrypt(
69
69
  self,
70
- parameters:MaleoFoundationRSAEncryptionParametersTransfers.Decrypt
70
+ parameters: MaleoFoundationRSAEncryptionParametersTransfers.Decrypt
71
71
  ) -> MaleoFoundationRSAEncryptionResultsTypes.Decrypt:
72
72
  """Decrypt a ciphertext using RSA algorithm."""
73
73
  @BaseExceptions.service_exception_handler(
@@ -15,7 +15,7 @@ from maleo_foundation.utils.exceptions import BaseExceptions
15
15
  class MaleoFoundationKeyClientService(ClientService):
16
16
  def create_private(
17
17
  self,
18
- parameters:MaleoFoundationKeyParametersTransfers.CreatePrivateOrPair
18
+ parameters: MaleoFoundationKeyParametersTransfers.CreatePrivateOrPair
19
19
  ) -> MaleoFoundationKeyResultsTypes.CreatePrivate:
20
20
  """Create an RSA private key with X.509 encoding in .pem format."""
21
21
  @BaseExceptions.service_exception_handler(
@@ -54,7 +54,7 @@ class MaleoFoundationKeyClientService(ClientService):
54
54
 
55
55
  def create_public(
56
56
  self,
57
- parameters:MaleoFoundationKeyParametersTransfers.CreatePublic
57
+ parameters: MaleoFoundationKeyParametersTransfers.CreatePublic
58
58
  ) -> MaleoFoundationKeyResultsTypes.CreatePublic:
59
59
  """Create an RSA public key with X.509 encoding in .pem format."""
60
60
  @BaseExceptions.service_exception_handler(
@@ -86,7 +86,10 @@ class MaleoFoundationKeyClientService(ClientService):
86
86
  return MaleoFoundationKeyResultsTransfers.CreatePublic(data=data)
87
87
  return _impl()
88
88
 
89
- def create_pair(self, parameters:MaleoFoundationKeyParametersTransfers.CreatePrivateOrPair) -> MaleoFoundationKeyResultsTypes.CreatePair:
89
+ def create_pair(
90
+ self,
91
+ parameters: MaleoFoundationKeyParametersTransfers.CreatePrivateOrPair
92
+ ) -> MaleoFoundationKeyResultsTypes.CreatePair:
90
93
  """Create an RSA key pair with X.509 encoding in .pem format."""
91
94
  @BaseExceptions.service_exception_handler(
92
95
  operation="creating key pair",
@@ -17,7 +17,7 @@ from maleo_foundation.utils.loaders.key.rsa import RSAKeyLoader
17
17
  class MaleoFoundationSignatureClientService(ClientService):
18
18
  def sign(
19
19
  self,
20
- parameters:MaleoFoundationSignatureParametersTransfers.Sign
20
+ parameters: MaleoFoundationSignatureParametersTransfers.Sign
21
21
  ) -> MaleoFoundationSignatureResultsTypes.Sign:
22
22
  @BaseExceptions.service_exception_handler(
23
23
  operation="signing single message",
@@ -59,7 +59,7 @@ class MaleoFoundationSignatureClientService(ClientService):
59
59
 
60
60
  def verify(
61
61
  self,
62
- parameters:MaleoFoundationSignatureParametersTransfers.Verify
62
+ parameters: MaleoFoundationSignatureParametersTransfers.Verify
63
63
  ) -> MaleoFoundationSignatureResultsTypes.Verify:
64
64
  @BaseExceptions.service_exception_handler(
65
65
  operation="verify single signature",
@@ -17,7 +17,7 @@ from maleo_foundation.utils.loaders.key.rsa import RSAKeyLoader
17
17
  class MaleoFoundationTokenClientService(ClientService):
18
18
  def encode(
19
19
  self,
20
- parameters:MaleoFoundationTokenParametersTransfers.Encode
20
+ parameters: MaleoFoundationTokenParametersTransfers.Encode
21
21
  ) -> MaleoFoundationTokenResultsTypes.Encode:
22
22
  @BaseExceptions.service_exception_handler(
23
23
  operation="encoding a payload into a token",
@@ -72,7 +72,7 @@ class MaleoFoundationTokenClientService(ClientService):
72
72
 
73
73
  def decode(
74
74
  self,
75
- parameters:MaleoFoundationTokenParametersTransfers.Decode
75
+ parameters: MaleoFoundationTokenParametersTransfers.Decode
76
76
  ) -> MaleoFoundationTokenResultsTypes.Decode:
77
77
  @BaseExceptions.service_exception_handler(
78
78
  operation="decoding a token into a payload",
@@ -4,13 +4,13 @@ from uuid import UUID
4
4
  from maleo_foundation.enums import BaseEnums
5
5
  from maleo_foundation.types import BaseTypes
6
6
 
7
- EMAIL_REGEX:str = r"^[^\s@]+@[^\s@]+\.[^\s@]+$"
7
+ EMAIL_REGEX: str = r"^[^\s@]+@[^\s@]+\.[^\s@]+$"
8
8
  TOKEN_COOKIE_KEY_NAME="token"
9
- REFRESH_TOKEN_DURATION_DAYS:int = 7
10
- ACCESS_TOKEN_DURATION_MINUTES:int = 5
9
+ REFRESH_TOKEN_DURATION_DAYS: int = 7
10
+ ACCESS_TOKEN_DURATION_MINUTES: int = 5
11
11
  SORT_COLUMN_PATTERN = re.compile(r'^[a-z_]+\.(asc|desc)$')
12
12
  DATE_FILTER_PATTERN = re.compile(r'^[a-z_]+(?:\|from::\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))?(?:\|to::\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))?$')
13
- STATUS_UPDATE_CRITERIAS:dict[
13
+ STATUS_UPDATE_CRITERIAS: dict[
14
14
  BaseEnums.StatusUpdateType,
15
15
  BaseTypes.OptionalListOfStatuses
16
16
  ] = {
@@ -25,19 +25,19 @@ STATUS_UPDATE_CRITERIAS:dict[
25
25
  BaseEnums.StatusType.ACTIVE,
26
26
  ]
27
27
  }
28
- IDENTIFIER_TYPE_VALUE_TYPE_MAP:dict[
28
+ IDENTIFIER_TYPE_VALUE_TYPE_MAP: dict[
29
29
  BaseEnums.IdentifierTypes,
30
30
  object
31
31
  ] = {
32
32
  BaseEnums.IdentifierTypes.ID: int,
33
33
  BaseEnums.IdentifierTypes.UUID: UUID
34
34
  }
35
- ALL_STATUSES:List[BaseEnums.StatusType] = [
35
+ ALL_STATUSES: List[BaseEnums.StatusType] = [
36
36
  BaseEnums.StatusType.ACTIVE,
37
37
  BaseEnums.StatusType.INACTIVE,
38
38
  BaseEnums.StatusType.DELETED
39
39
  ]
40
- VISIBLE_STATUSES:List[BaseEnums.StatusType] = [
40
+ VISIBLE_STATUSES: List[BaseEnums.StatusType] = [
41
41
  BaseEnums.StatusType.ACTIVE,
42
42
  BaseEnums.StatusType.INACTIVE
43
43
  ]
@@ -4,7 +4,11 @@ from fastapi.encoders import jsonable_encoder
4
4
 
5
5
  class BaseCacheConfigurations:
6
6
  @staticmethod
7
- def key_builder(func: Callable, *args, **kwargs) -> str:
7
+ def key_builder(
8
+ func: Callable,
9
+ *args,
10
+ **kwargs
11
+ ) -> str:
8
12
  arg_values = []
9
13
  for arg in args:
10
14
  try:
@@ -4,22 +4,22 @@ from maleo_foundation.types import BaseTypes
4
4
  from maleo_foundation.enums import BaseEnums
5
5
 
6
6
  class RedisCacheNamespaces(BaseModel):
7
- base:str = Field(..., description="Base's redis namespace")
7
+ base: str = Field(..., description="Base's redis namespace")
8
8
 
9
9
  def create(
10
10
  self,
11
- *ext:str,
12
- type:BaseEnums.CacheType,
13
- base_override:BaseTypes.OptionalString = None
11
+ *ext: str,
12
+ type: BaseEnums.CacheType,
13
+ base_override: BaseTypes.OptionalString = None
14
14
  ) -> str:
15
15
  return ":".join([self.base if base_override is None else base_override, type, *ext])
16
16
 
17
17
  class RedisCacheConfigurations(BaseModel):
18
- ttl:Union[int, float] = Field(BaseEnums.CacheTTL.TTL_5MN, description="Default TTL")
19
- namespaces:RedisCacheNamespaces = Field(..., description="Redis cache's namepsaces")
20
- host:str = Field(..., description="Redis instance's host")
21
- port:int = Field(6379, description="Redis instance's port")
22
- db:int = Field(0, description="Redis instance's db")
23
- password:BaseTypes.OptionalString = Field(None, description="AUTH password")
24
- decode_responses:bool = Field(False, description="Whether to decode responses")
25
- health_check_interval:int = Field(30, description="Health check interval")
18
+ ttl: Union[int, float] = Field(BaseEnums.CacheTTL.TTL_5MN, description="Default TTL")
19
+ namespaces: RedisCacheNamespaces = Field(..., description="Redis cache's namepsaces")
20
+ host: str = Field(..., description="Redis instance's host")
21
+ port: int = Field(6379, description="Redis instance's port")
22
+ db: int = Field(0, description="Redis instance's db")
23
+ password: BaseTypes.OptionalString = Field(None, description="AUTH password")
24
+ decode_responses: bool = Field(False, description="Whether to decode responses")
25
+ health_check_interval: int = Field(30, description="Health check interval")
@@ -6,18 +6,18 @@ from maleo_foundation.types import BaseTypes
6
6
  from maleo_foundation.utils.logging import ClientLogger, SimpleConfig
7
7
 
8
8
  class BearerAuth(httpx.Auth):
9
- def __init__(self, token:str) -> None:
9
+ def __init__(self, token: str) -> None:
10
10
  self._auth_header = self._build_auth_header(token)
11
11
 
12
- def auth_flow(self, request:httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
12
+ def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
13
13
  request.headers["Authorization"] = self._auth_header
14
14
  yield request
15
15
 
16
- def _build_auth_header(self, token:str) -> str:
16
+ def _build_auth_header(self, token: str) -> str:
17
17
  return f"Bearer {token}"
18
18
 
19
19
  class ClientHTTPControllerManager:
20
- def __init__(self, url:str) -> None:
20
+ def __init__(self, url: str) -> None:
21
21
  self._client = httpx.AsyncClient()
22
22
  self._url = url
23
23
 
@@ -95,10 +95,10 @@ class ClientServices(BaseModel):
95
95
  class ClientManager:
96
96
  def __init__(
97
97
  self,
98
- key:str,
99
- name:str,
100
- log_config:SimpleConfig,
101
- service_key:BaseTypes.OptionalString=None
98
+ key: str,
99
+ name: str,
100
+ log_config: SimpleConfig,
101
+ service_key: BaseTypes.OptionalString = None
102
102
  ) -> None:
103
103
  self._key = key
104
104
  self._name = name
@@ -9,12 +9,12 @@ from maleo_foundation.utils.logging import SimpleConfig
9
9
  class GoogleClientManager(ClientManager):
10
10
  def __init__(
11
11
  self,
12
- key:str,
13
- name:str,
14
- log_config:SimpleConfig,
15
- service_key:BaseTypes.OptionalString=None,
16
- credentials:Optional[Credentials]=None,
17
- credentials_path:Optional[Union[Path, str]]=None
12
+ key: str,
13
+ name: str,
14
+ log_config: SimpleConfig,
15
+ service_key: BaseTypes.OptionalString = None,
16
+ credentials: Optional[Credentials] = None,
17
+ credentials_path: Optional[Union[Path, str]] = None
18
18
  ) -> None:
19
19
  super().__init__(key, name, log_config, service_key)
20
20
  if (credentials is not None and credentials_path is not None) or (credentials is None and credentials_path is None):
@@ -11,14 +11,21 @@ from .base import GoogleClientManager
11
11
  class GoogleParameterManager(GoogleClientManager):
12
12
  def __init__(
13
13
  self,
14
- log_config:SimpleConfig,
15
- service_key:BaseTypes.OptionalString=None,
16
- credentials:Optional[Credentials]=None,
17
- credentials_path:Optional[Union[Path, str]]=None
14
+ log_config: SimpleConfig,
15
+ service_key: BaseTypes.OptionalString = None,
16
+ credentials: Optional[Credentials] = None,
17
+ credentials_path: Optional[Union[Path, str]] = None
18
18
  ) -> None:
19
19
  key = "google-parameter-manager"
20
20
  name = "GoogleParameterManager"
21
- super().__init__(key, name, log_config, service_key, credentials, credentials_path)
21
+ super().__init__(
22
+ key,
23
+ name,
24
+ log_config,
25
+ service_key,
26
+ credentials,
27
+ credentials_path
28
+ )
22
29
  self._client = parametermanager.ParameterManagerClient(credentials=self._credentials)
23
30
  self._logger.info("Client manager initialized successfully")
24
31
 
@@ -11,14 +11,21 @@ from .base import GoogleClientManager
11
11
  class GoogleSecretManager(GoogleClientManager):
12
12
  def __init__(
13
13
  self,
14
- log_config:SimpleConfig,
15
- service_key:BaseTypes.OptionalString=None,
16
- credentials:Optional[Credentials]=None,
17
- credentials_path:Optional[Union[Path, str]]=None
14
+ log_config: SimpleConfig,
15
+ service_key: BaseTypes.OptionalString = None,
16
+ credentials: Optional[Credentials] = None,
17
+ credentials_path: Optional[Union[Path, str]] = None
18
18
  ) -> None:
19
19
  key = "google-secret-manager"
20
20
  name = "GoogleSecretManager"
21
- super().__init__(key, name, log_config, service_key, credentials, credentials_path)
21
+ super().__init__(
22
+ key,
23
+ name,
24
+ log_config,
25
+ service_key,
26
+ credentials,
27
+ credentials_path
28
+ )
22
29
  self._client = secretmanager.SecretManagerServiceClient(credentials=self._credentials)
23
30
  self._logger.info("Client manager initialized successfully")
24
31
 
@@ -33,7 +40,11 @@ class GoogleSecretManager(GoogleClientManager):
33
40
  self._logger.info("Client manager disposed successfully")
34
41
 
35
42
  @retry.Retry(predicate=retry.if_exception_type(Exception), timeout=5)
36
- def get(self, name:str, version:str = "latest") -> str:
43
+ def get(
44
+ self,
45
+ name: str,
46
+ version: str = "latest"
47
+ ) -> str:
37
48
  #* Check if secret exists
38
49
  secret_name = f"projects/{self._project_id}/secrets/{name}"
39
50
  try:
@@ -69,7 +80,11 @@ class GoogleSecretManager(GoogleClientManager):
69
80
  raise
70
81
 
71
82
  @retry.Retry(predicate=retry.if_exception_type(Exception), timeout=5)
72
- def create(self, name:str, data:str) -> str:
83
+ def create(
84
+ self,
85
+ name: str,
86
+ data: str
87
+ ) -> str:
73
88
  parent = f"projects/{self._project_id}"
74
89
  secret_path = f"{parent}/secrets/{name}"
75
90
  try:
@@ -13,12 +13,12 @@ from .base import GoogleClientManager
13
13
  class GoogleCloudStorage(GoogleClientManager):
14
14
  def __init__(
15
15
  self,
16
- log_config:SimpleConfig,
17
- service_key:BaseTypes.OptionalString=None,
18
- credentials:Optional[Credentials]=None,
19
- credentials_path:Optional[Union[Path, str]]=None,
20
- bucket_name:BaseTypes.OptionalString = None,
21
- redis:Optional[Redis] = None
16
+ log_config: SimpleConfig,
17
+ service_key: BaseTypes.OptionalString = None,
18
+ credentials: Optional[Credentials] = None,
19
+ credentials_path: Optional[Union[Path, str]] = None,
20
+ bucket_name: BaseTypes.OptionalString = None,
21
+ redis: Optional[Redis] = None
22
22
  ) -> None:
23
23
  key = "google-cloud-storage"
24
24
  name = "GoogleCloudStorage"
@@ -53,13 +53,13 @@ class GoogleCloudStorage(GoogleClientManager):
53
53
 
54
54
  async def upload(
55
55
  self,
56
- content:bytes,
57
- location:str,
58
- content_type:Optional[str]=None,
59
- make_public:bool=False,
60
- expiration:BaseEnums=BaseEnums.Expiration.EXP_15MN,
61
- root_location_override:BaseTypes.OptionalString=None,
62
- set_in_redis:bool=True
56
+ content: bytes,
57
+ location: str,
58
+ content_type: Optional[str]=None,
59
+ make_public: bool=False,
60
+ expiration: BaseEnums=BaseEnums.Expiration.EXP_15MN,
61
+ root_location_override: BaseTypes.OptionalString=None,
62
+ set_in_redis: bool=True
63
63
  ) -> str:
64
64
  """
65
65
  Upload a file to Google Cloud Storage.
@@ -101,10 +101,10 @@ class GoogleCloudStorage(GoogleClientManager):
101
101
 
102
102
  async def generate_signed_url(
103
103
  self,
104
- location:str,
105
- expiration:BaseEnums=BaseEnums.Expiration.EXP_15MN,
106
- root_location_override:BaseTypes.OptionalString=None,
107
- use_redis:bool=True
104
+ location: str,
105
+ expiration: BaseEnums=BaseEnums.Expiration.EXP_15MN,
106
+ root_location_override: BaseTypes.OptionalString = None,
107
+ use_redis: bool = True
108
108
  ) -> str:
109
109
  """
110
110
  generate signed URL of a file in the bucket based on its location.
@@ -14,8 +14,8 @@ from maleo_foundation.utils.logging import ClientLogger
14
14
  class MaleoClientHTTPController(ClientHTTPController):
15
15
  def __init__(
16
16
  self,
17
- service_manager:ServiceManager,
18
- manager:ClientHTTPControllerManager
17
+ service_manager: ServiceManager,
18
+ manager: ClientHTTPControllerManager
19
19
  ):
20
20
  super().__init__(manager)
21
21
  self._service_manager = service_manager
@@ -33,9 +33,9 @@ class MaleoClientServiceControllers(ClientServiceControllers):
33
33
  class MaleoClientService(ClientService):
34
34
  def __init__(
35
35
  self,
36
- key:str,
37
- logger:ClientLogger,
38
- service_manager:ServiceManager
36
+ key: str,
37
+ logger: ClientLogger,
38
+ service_manager: ServiceManager
39
39
  ):
40
40
  super().__init__(logger)
41
41
  self._key = key
@@ -52,10 +52,10 @@ class MaleoClientService(ClientService):
52
52
  class MaleoClientManager(ClientManager):
53
53
  def __init__(
54
54
  self,
55
- key:str,
56
- name:str,
57
- url:str,
58
- service_manager:ServiceManager
55
+ key: str,
56
+ name: str,
57
+ url: str,
58
+ service_manager: ServiceManager
59
59
  ):
60
60
  self._url = url
61
61
  self._service_manager = service_manager
@@ -11,14 +11,14 @@ from maleo_foundation.types import BaseTypes
11
11
  from maleo_foundation.utils.logging import ServiceLogger
12
12
 
13
13
  class MetadataManager:
14
- Base:DeclarativeMeta = declarative_base()
15
- metadata:MetaData = Base.metadata
14
+ Base: DeclarativeMeta = declarative_base()
15
+ metadata: MetaData = Base.metadata
16
16
 
17
17
  class SessionManager:
18
18
  def __init__(
19
19
  self,
20
- logger:ServiceLogger,
21
- engine:Engine
20
+ logger: ServiceLogger,
21
+ engine: Engine
22
22
  ):
23
23
  self._logger = logger
24
24
  self._logger.info("Initializing SessionMaker")
@@ -66,11 +66,11 @@ class SessionManager:
66
66
  self._logger = None
67
67
 
68
68
  class DatabaseConfigurations(BaseModel):
69
- username:str = Field("postgres", description="Database user's username")
70
- password:str = Field(..., description="Database user's password")
71
- host:str = Field(..., description="Database's host")
72
- port:int = Field(5432, description="Database's port")
73
- database:str = Field(..., description="Database")
69
+ username: str = Field("postgres", description="Database user's username")
70
+ password: str = Field(..., description="Database user's password")
71
+ host: str = Field(..., description="Database's host")
72
+ port: int = Field(5432, description="Database's port")
73
+ database: str = Field(..., description="Database")
74
74
 
75
75
  @property
76
76
  def url(self) -> str:
@@ -79,9 +79,9 @@ class DatabaseConfigurations(BaseModel):
79
79
  class DatabaseManager:
80
80
  def __init__(
81
81
  self,
82
- metadata:MetaData,
83
- logger:ServiceLogger,
84
- url:BaseTypes.OptionalString = None
82
+ metadata: MetaData,
83
+ logger: ServiceLogger,
84
+ url: BaseTypes.OptionalString = None
85
85
  ):
86
86
  self._metadata = metadata #* Define database metadata
87
87
  self._logger = logger #* Define database logger
@@ -8,33 +8,33 @@ from maleo_foundation.middlewares.base import add_base_middleware
8
8
  from maleo_foundation.middlewares.cors import add_cors_middleware
9
9
  from maleo_foundation.utils.logging import MiddlewareLogger
10
10
 
11
- _ALLOW_METHODS:List[str] = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
12
- _ALLOW_HEADERS:List[str] = ["X-Organization", "X-User", "X-Signature"]
13
- _EXPOSE_HEADERS:List[str] = ["X-Request-Timestamp", "X-Response-Timestamp", "X-Process-Time", "X-Signature"]
11
+ _ALLOW_METHODS: List[str] = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
12
+ _ALLOW_HEADERS: List[str] = ["X-Organization", "X-User", "X-Signature"]
13
+ _EXPOSE_HEADERS: List[str] = ["X-Request-Timestamp", "X-Response-Timestamp", "X-Process-Time", "X-Signature"]
14
14
 
15
15
  class GeneralMiddlewareConfigurations(BaseModel):
16
- allow_origins:List[str] = Field(default_factory=list, description="Allowed origins")
17
- allow_methods:List[str] = Field(_ALLOW_METHODS, description="Allowed methods")
18
- allow_headers:list[str] = Field(_ALLOW_HEADERS, description="Allowed headers")
19
- allow_credentials:bool = Field(True, description="Allowed credentials")
16
+ allow_origins: List[str] = Field(default_factory=list, description="Allowed origins")
17
+ allow_methods: List[str] = Field(_ALLOW_METHODS, description="Allowed methods")
18
+ allow_headers: list[str] = Field(_ALLOW_HEADERS, description="Allowed headers")
19
+ allow_credentials: bool = Field(True, description="Allowed credentials")
20
20
 
21
21
  class CORSMiddlewareConfigurations(BaseModel):
22
- expose_headers:List[str] = Field(_EXPOSE_HEADERS, description="Exposed headers")
22
+ expose_headers: List[str] = Field(_EXPOSE_HEADERS, description="Exposed headers")
23
23
 
24
24
  class BaseMiddlewareConfigurations(BaseModel):
25
- limit:int = Field(10, description="Request limit (per 'window' seconds)")
26
- window:int = Field(1, description="Request limit window (seconds)")
27
- cleanup_interval:int = Field(60, description="Interval for middleware cleanup (seconds)")
28
- ip_timeout:int = Field(300, description="Idle IP's timeout (seconds)")
25
+ limit: int = Field(10, description="Request limit (per 'window' seconds)")
26
+ window: int = Field(1, description="Request limit window (seconds)")
27
+ cleanup_interval: int = Field(60, description="Interval for middleware cleanup (seconds)")
28
+ ip_timeout: int = Field(300, description="Idle IP's timeout (seconds)")
29
29
 
30
30
  class MiddlewareConfigurations(BaseModel):
31
- general:GeneralMiddlewareConfigurations = Field(..., description="Middleware's general configurations")
32
- cors:CORSMiddlewareConfigurations = Field(..., description="CORS middleware's configurations")
33
- base:BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
31
+ general: GeneralMiddlewareConfigurations = Field(..., description="Middleware's general configurations")
32
+ cors: CORSMiddlewareConfigurations = Field(..., description="CORS middleware's configurations")
33
+ base: BaseMiddlewareConfigurations = Field(..., description="Base middleware's configurations")
34
34
 
35
35
  class MiddlewareLoggers(BaseModel):
36
- base:MiddlewareLogger = Field(..., description="Base middleware's logger")
37
- authentication:MiddlewareLogger = Field(..., description="Authentication middleware's logger")
36
+ base: MiddlewareLogger = Field(..., description="Base middleware's logger")
37
+ authentication: MiddlewareLogger = Field(..., description="Authentication middleware's logger")
38
38
 
39
39
  class Config:
40
40
  arbitrary_types_allowed=True
@@ -42,11 +42,11 @@ class MiddlewareLoggers(BaseModel):
42
42
  class MiddlewareManager:
43
43
  def __init__(
44
44
  self,
45
- app:FastAPI,
46
- configurations:MiddlewareConfigurations,
47
- keys:BaseGeneralSchemas.RSAKeys,
48
- loggers:MiddlewareLoggers,
49
- maleo_foundation:MaleoFoundationClientManager
45
+ app: FastAPI,
46
+ configurations: MiddlewareConfigurations,
47
+ keys: BaseGeneralSchemas.RSAKeys,
48
+ loggers: MiddlewareLoggers,
49
+ maleo_foundation: MaleoFoundationClientManager
50
50
  ):
51
51
  self._app = app
52
52
  self._configurations = configurations