maleo-foundation 0.3.71__py3-none-any.whl → 0.3.74__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.
- maleo_foundation/authentication.py +2 -48
- maleo_foundation/client/manager.py +9 -3
- maleo_foundation/constants.py +2 -0
- maleo_foundation/controller_types.py +25 -0
- maleo_foundation/enums.py +7 -1
- maleo_foundation/managers/client/base.py +37 -5
- maleo_foundation/managers/client/google/base.py +7 -3
- maleo_foundation/managers/client/google/secret.py +12 -3
- maleo_foundation/managers/client/google/storage.py +11 -2
- maleo_foundation/managers/client/google/subscription.py +40 -26
- maleo_foundation/managers/client/maleo.py +3 -5
- maleo_foundation/managers/credential.py +6 -2
- maleo_foundation/managers/middleware.py +8 -8
- maleo_foundation/managers/service.py +33 -17
- maleo_foundation/middlewares/authentication.py +3 -2
- maleo_foundation/middlewares/base.py +312 -197
- maleo_foundation/models/schemas/general.py +1 -127
- maleo_foundation/models/transfers/general/authentication.py +35 -0
- maleo_foundation/{authorization.py → models/transfers/general/authorization.py} +0 -3
- maleo_foundation/models/transfers/general/configurations/__init__.py +2 -0
- maleo_foundation/models/transfers/general/configurations/client/maleo.py +1 -1
- maleo_foundation/models/transfers/general/configurations/middleware.py +6 -7
- maleo_foundation/models/transfers/general/configurations/pubsub/subscription.py +16 -0
- maleo_foundation/models/transfers/general/configurations/service.py +2 -1
- maleo_foundation/models/transfers/general/operation.py +192 -30
- maleo_foundation/models/transfers/general/request.py +13 -19
- maleo_foundation/models/transfers/general/response.py +14 -0
- maleo_foundation/models/transfers/general/service.py +9 -0
- maleo_foundation/models/transfers/general/settings.py +1 -1
- maleo_foundation/models/transfers/general/user_agent.py +34 -0
- maleo_foundation/utils/exceptions/client.py +26 -2
- maleo_foundation/utils/exceptions/service.py +26 -2
- maleo_foundation/utils/extractor.py +49 -19
- maleo_foundation/utils/logging.py +90 -21
- maleo_foundation/utils/parser.py +7 -0
- {maleo_foundation-0.3.71.dist-info → maleo_foundation-0.3.74.dist-info}/METADATA +3 -1
- {maleo_foundation-0.3.71.dist-info → maleo_foundation-0.3.74.dist-info}/RECORD +39 -35
- maleo_foundation/utils/dependencies/__init__.py +0 -6
- maleo_foundation/utils/dependencies/auth.py +0 -17
- maleo_foundation/utils/dependencies/context.py +0 -8
- {maleo_foundation-0.3.71.dist-info → maleo_foundation-0.3.74.dist-info}/WHEEL +0 -0
- {maleo_foundation-0.3.71.dist-info → maleo_foundation-0.3.74.dist-info}/top_level.txt +0 -0
@@ -1,17 +1,6 @@
|
|
1
|
-
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
2
1
|
from starlette.authentication import AuthCredentials, BaseUser
|
3
|
-
from typing import Optional,
|
4
|
-
from maleo_foundation.
|
5
|
-
from maleo_foundation.models.transfers.general.token import (
|
6
|
-
MaleoFoundationTokenGeneralTransfers,
|
7
|
-
)
|
8
|
-
|
9
|
-
|
10
|
-
class Token(BaseModel):
|
11
|
-
type: BaseEnums.TokenType = Field(..., description="Token's type")
|
12
|
-
payload: MaleoFoundationTokenGeneralTransfers.DecodePayload = Field(
|
13
|
-
..., description="Token's payload"
|
14
|
-
)
|
2
|
+
from typing import Optional, Sequence
|
3
|
+
from maleo_foundation.models.transfers.general.authentication import Token
|
15
4
|
|
16
5
|
|
17
6
|
class Credentials(AuthCredentials):
|
@@ -26,11 +15,6 @@ class Credentials(AuthCredentials):
|
|
26
15
|
return self._token
|
27
16
|
|
28
17
|
|
29
|
-
class CredentialsModel(BaseModel):
|
30
|
-
token: Optional[Token] = Field(None, description="Token")
|
31
|
-
scopes: Optional[Sequence[str]] = Field(None, description="Scopes")
|
32
|
-
|
33
|
-
|
34
18
|
class User(BaseUser):
|
35
19
|
def __init__(
|
36
20
|
self, authenticated: bool = False, username: str = "", email: str = ""
|
@@ -50,33 +34,3 @@ class User(BaseUser):
|
|
50
34
|
@property
|
51
35
|
def identity(self) -> str:
|
52
36
|
return self._email
|
53
|
-
|
54
|
-
|
55
|
-
class UserModel(BaseModel):
|
56
|
-
is_authenticated: bool = Field(False, description="Authenticated")
|
57
|
-
display_name: str = Field("", description="Username")
|
58
|
-
identity: str = Field("", description="Email")
|
59
|
-
|
60
|
-
|
61
|
-
class Authentication(BaseModel):
|
62
|
-
model_config = ConfigDict(arbitrary_types_allowed=True)
|
63
|
-
|
64
|
-
credentials: Credentials = Field(
|
65
|
-
..., description="Credentials's information", exclude=True
|
66
|
-
)
|
67
|
-
credentials_model: CredentialsModel = Field(
|
68
|
-
default_factory=CredentialsModel, # type: ignore
|
69
|
-
description="Credential's model",
|
70
|
-
serialization_alias="credentials",
|
71
|
-
)
|
72
|
-
user: User = Field(..., description="User's information", exclude=True)
|
73
|
-
user_model: UserModel = Field(default_factory=UserModel, description="User's model", serialization_alias="user") # type: ignore
|
74
|
-
|
75
|
-
@model_validator(mode="after")
|
76
|
-
def define_models(self) -> Self:
|
77
|
-
self.credentials_model.token = self.credentials.token
|
78
|
-
self.credentials_model.scopes = self.credentials.scopes
|
79
|
-
self.user_model.is_authenticated = self.user.is_authenticated
|
80
|
-
self.user_model.display_name = self.user.display_name
|
81
|
-
self.user_model.identity = self.user.identity
|
82
|
-
return self
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
+
from typing import Optional
|
3
|
+
from maleo_foundation.enums import BaseEnums
|
2
4
|
from maleo_foundation.managers.client.base import ClientManager
|
3
|
-
from maleo_foundation.types import BaseTypes
|
4
5
|
from maleo_foundation.utils.logging import SimpleConfig
|
5
6
|
from maleo_foundation.client.services.encryption import (
|
6
7
|
MaleoFoundationAESEncryptionClientService,
|
@@ -23,11 +24,16 @@ from maleo_foundation.client.services import (
|
|
23
24
|
|
24
25
|
class MaleoFoundationClientManager(ClientManager):
|
25
26
|
def __init__(
|
26
|
-
self,
|
27
|
+
self,
|
28
|
+
log_config: SimpleConfig,
|
29
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
30
|
+
service_key: Optional[BaseEnums.Service] = None,
|
27
31
|
) -> None:
|
28
32
|
key = "maleo-foundation"
|
29
33
|
name = "MaleoFoundation"
|
30
|
-
super().__init__(
|
34
|
+
super().__init__(
|
35
|
+
key, name, log_config, service_environment, service_key, service_environment
|
36
|
+
)
|
31
37
|
self._initialize_services()
|
32
38
|
self._logger.info("Client manager initialized successfully")
|
33
39
|
|
maleo_foundation/constants.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
import re
|
2
|
+
from fastapi.security import HTTPBearer
|
2
3
|
from typing import List
|
3
4
|
from uuid import UUID
|
4
5
|
from maleo_foundation.enums import BaseEnums
|
5
6
|
from maleo_foundation.types import BaseTypes
|
6
7
|
|
8
|
+
TOKEN_SCHEME = HTTPBearer()
|
7
9
|
EMAIL_REGEX: str = r"^[^\s@]+@[^\s@]+\.[^\s@]+$"
|
8
10
|
TOKEN_COOKIE_KEY_NAME = "token"
|
9
11
|
REFRESH_TOKEN_DURATION_DAYS: int = 7
|
@@ -0,0 +1,25 @@
|
|
1
|
+
from google.cloud.pubsub_v1.subscriber.message import Message
|
2
|
+
from typing import Awaitable, Callable, Optional, Union
|
3
|
+
from maleo_foundation.models.transfers.results.service.controllers.rest import (
|
4
|
+
BaseServiceRESTControllerResults,
|
5
|
+
)
|
6
|
+
|
7
|
+
|
8
|
+
class ControllerTypes:
|
9
|
+
# * REST controller types
|
10
|
+
SyncRESTController = Callable[..., BaseServiceRESTControllerResults]
|
11
|
+
OptionalSyncRESTController = Optional[
|
12
|
+
Callable[..., BaseServiceRESTControllerResults]
|
13
|
+
]
|
14
|
+
AsyncRESTController = Callable[..., Awaitable[BaseServiceRESTControllerResults]]
|
15
|
+
OptionalAsyncRESTController = Optional[
|
16
|
+
Callable[..., Awaitable[BaseServiceRESTControllerResults]]
|
17
|
+
]
|
18
|
+
RESTController = Union[SyncRESTController, AsyncRESTController]
|
19
|
+
OptionalRESTController = Optional[RESTController]
|
20
|
+
|
21
|
+
# * Message controller types
|
22
|
+
SyncMessageController = Callable[[str, Message], bool]
|
23
|
+
AsyncMessageController = Callable[[str, Message], Awaitable[bool]]
|
24
|
+
MessageController = Union[SyncMessageController, AsyncMessageController]
|
25
|
+
OptionalMessageController = Optional[MessageController]
|
maleo_foundation/enums.py
CHANGED
@@ -69,10 +69,12 @@ class BaseEnums:
|
|
69
69
|
|
70
70
|
class ExceptionType(StrEnum):
|
71
71
|
TIMEOUT = "timeout"
|
72
|
+
BAD = "bad"
|
72
73
|
UNAUTHORIZED = "unauthorized"
|
73
74
|
FORBIDDEN = "forbidden"
|
74
75
|
NOT_FOUND = "not_found"
|
75
76
|
VALIDATION = "validation"
|
77
|
+
RATE_LIMIT = "rate_limit"
|
76
78
|
INTERNAL = "internal"
|
77
79
|
UNAVAILABLE = "unavailable"
|
78
80
|
|
@@ -91,6 +93,7 @@ class BaseEnums:
|
|
91
93
|
SERVICE = "service"
|
92
94
|
|
93
95
|
class OperationLayer(StrEnum):
|
96
|
+
MIDDLEWARE = "middleware"
|
94
97
|
ROUTER = "router"
|
95
98
|
CONTROLLER = "controller"
|
96
99
|
SERVICE = "service"
|
@@ -122,6 +125,7 @@ class BaseEnums:
|
|
122
125
|
READ = "read"
|
123
126
|
UPDATE = "update"
|
124
127
|
DELETE = "delete"
|
128
|
+
OTHER = "other"
|
125
129
|
|
126
130
|
class CreateType(StrEnum):
|
127
131
|
CREATE = "create"
|
@@ -185,12 +189,14 @@ class BaseEnums:
|
|
185
189
|
APPLICATION = "application"
|
186
190
|
CACHE = "cache"
|
187
191
|
CLIENT = "client"
|
192
|
+
CONTROLLER = "controller"
|
188
193
|
DATABASE = "database"
|
189
194
|
MIDDLEWARE = "middleware"
|
190
195
|
REPOSITORY = "repository"
|
196
|
+
ROUTER = "router"
|
191
197
|
SERVICE = "service"
|
192
198
|
|
193
|
-
class
|
199
|
+
class LogLevel(IntEnum):
|
194
200
|
CRITICAL = logging.CRITICAL
|
195
201
|
FATAL = logging.FATAL
|
196
202
|
ERROR = logging.ERROR
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import httpx
|
2
|
+
import os
|
2
3
|
from contextlib import asynccontextmanager
|
3
4
|
from pydantic import BaseModel, ConfigDict, Field
|
4
|
-
from typing import AsyncGenerator, Generator
|
5
|
-
from maleo_foundation.
|
5
|
+
from typing import AsyncGenerator, Generator, Optional
|
6
|
+
from maleo_foundation.enums import BaseEnums
|
6
7
|
from maleo_foundation.utils.logging import ClientLogger, SimpleConfig
|
7
8
|
|
8
9
|
|
@@ -107,18 +108,43 @@ class ClientManager:
|
|
107
108
|
key: str,
|
108
109
|
name: str,
|
109
110
|
log_config: SimpleConfig,
|
110
|
-
|
111
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
112
|
+
service_key: Optional[BaseEnums.Service] = None,
|
113
|
+
environment: Optional[BaseEnums.EnvironmentType] = None,
|
111
114
|
) -> None:
|
112
115
|
self._key = key
|
113
116
|
self._name = name
|
114
117
|
self._log_config = log_config
|
115
|
-
|
118
|
+
|
119
|
+
# Ensure environment exists
|
120
|
+
actual_service_environment = service_environment or os.getenv("ENVIRONMENT")
|
121
|
+
if actual_service_environment is None:
|
122
|
+
raise ValueError(
|
123
|
+
"ENVIRONMENT environment variable must be set if 'service_environment' is set to None"
|
124
|
+
)
|
125
|
+
else:
|
126
|
+
self._service_environment = BaseEnums.EnvironmentType(
|
127
|
+
actual_service_environment
|
128
|
+
)
|
129
|
+
|
130
|
+
# Ensure service_key exists
|
131
|
+
actual_service_key = service_key or os.getenv("SERVICE_KEY")
|
132
|
+
if actual_service_key is None:
|
133
|
+
raise ValueError(
|
134
|
+
"SERVICE_KEY environment variable must be set if 'service_key' is set to None"
|
135
|
+
)
|
136
|
+
else:
|
137
|
+
self._service_key = BaseEnums.Service(actual_service_key)
|
138
|
+
|
139
|
+
self._environment = environment
|
140
|
+
|
116
141
|
self._initialize_logger()
|
117
|
-
self._logger.info("Initializing client manager")
|
142
|
+
self._logger.info(f"Initializing {self._name} client manager")
|
118
143
|
|
119
144
|
def _initialize_logger(self) -> None:
|
120
145
|
self._logger = ClientLogger(
|
121
146
|
client_key=self._key,
|
147
|
+
environment=self._service_environment,
|
122
148
|
service_key=self._service_key,
|
123
149
|
**self._log_config.model_dump(),
|
124
150
|
)
|
@@ -131,6 +157,12 @@ class ClientManager:
|
|
131
157
|
def name(self) -> str:
|
132
158
|
return self._name
|
133
159
|
|
160
|
+
@property
|
161
|
+
def environment(self) -> BaseEnums.EnvironmentType:
|
162
|
+
if self._environment is None:
|
163
|
+
raise ValueError("Environment has not been initialized.")
|
164
|
+
return self._environment
|
165
|
+
|
134
166
|
@property
|
135
167
|
def logger(self) -> ClientLogger:
|
136
168
|
return self._logger
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from google.oauth2.service_account import Credentials
|
2
2
|
from pathlib import Path
|
3
3
|
from typing import Optional, Union
|
4
|
-
from maleo_foundation.
|
4
|
+
from maleo_foundation.enums import BaseEnums
|
5
5
|
from maleo_foundation.managers.client.base import ClientManager
|
6
6
|
from maleo_foundation.utils.loaders.credential.google import GoogleCredentialsLoader
|
7
7
|
from maleo_foundation.utils.logging import SimpleConfig
|
@@ -13,11 +13,15 @@ class GoogleClientManager(ClientManager):
|
|
13
13
|
key: str,
|
14
14
|
name: str,
|
15
15
|
log_config: SimpleConfig,
|
16
|
-
|
16
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
17
|
+
service_key: Optional[BaseEnums.Service] = None,
|
18
|
+
environment: Optional[BaseEnums.EnvironmentType] = None,
|
17
19
|
credentials: Optional[Credentials] = None,
|
18
20
|
credentials_path: Optional[Union[Path, str]] = None,
|
19
21
|
) -> None:
|
20
|
-
super().__init__(
|
22
|
+
super().__init__(
|
23
|
+
key, name, log_config, service_environment, service_key, environment
|
24
|
+
)
|
21
25
|
if (credentials is not None and credentials_path is not None) or (
|
22
26
|
credentials is None and credentials_path is None
|
23
27
|
):
|
@@ -4,7 +4,7 @@ from google.cloud import secretmanager
|
|
4
4
|
from google.oauth2.service_account import Credentials
|
5
5
|
from pathlib import Path
|
6
6
|
from typing import Optional, Union
|
7
|
-
from maleo_foundation.
|
7
|
+
from maleo_foundation.enums import BaseEnums
|
8
8
|
from maleo_foundation.utils.logging import SimpleConfig
|
9
9
|
from .base import GoogleClientManager
|
10
10
|
|
@@ -13,14 +13,23 @@ class GoogleSecretManager(GoogleClientManager):
|
|
13
13
|
def __init__(
|
14
14
|
self,
|
15
15
|
log_config: SimpleConfig,
|
16
|
-
|
16
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
17
|
+
service_key: Optional[BaseEnums.Service] = None,
|
18
|
+
environment: Optional[BaseEnums.EnvironmentType] = None,
|
17
19
|
credentials: Optional[Credentials] = None,
|
18
20
|
credentials_path: Optional[Union[Path, str]] = None,
|
19
21
|
) -> None:
|
20
22
|
key = "google-secret-manager"
|
21
23
|
name = "GoogleSecretManager"
|
22
24
|
super().__init__(
|
23
|
-
key,
|
25
|
+
key,
|
26
|
+
name,
|
27
|
+
log_config,
|
28
|
+
service_environment,
|
29
|
+
service_key,
|
30
|
+
environment,
|
31
|
+
credentials,
|
32
|
+
credentials_path,
|
24
33
|
)
|
25
34
|
self._client = secretmanager.SecretManagerServiceClient(
|
26
35
|
credentials=self._credentials
|
@@ -15,7 +15,9 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
15
15
|
def __init__(
|
16
16
|
self,
|
17
17
|
log_config: SimpleConfig,
|
18
|
-
|
18
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
19
|
+
service_key: Optional[BaseEnums.Service] = None,
|
20
|
+
environment: Optional[BaseEnums.EnvironmentType] = None,
|
19
21
|
credentials: Optional[Credentials] = None,
|
20
22
|
credentials_path: Optional[Union[Path, str]] = None,
|
21
23
|
bucket_name: BaseTypes.OptionalString = None,
|
@@ -24,7 +26,14 @@ class GoogleCloudStorage(GoogleClientManager):
|
|
24
26
|
key = "google-cloud-storage"
|
25
27
|
name = "GoogleCloudStorage"
|
26
28
|
super().__init__(
|
27
|
-
key,
|
29
|
+
key,
|
30
|
+
name,
|
31
|
+
log_config,
|
32
|
+
service_environment,
|
33
|
+
service_key,
|
34
|
+
environment,
|
35
|
+
credentials,
|
36
|
+
credentials_path,
|
28
37
|
)
|
29
38
|
self._client = Client(credentials=self._credentials)
|
30
39
|
self._bucket_name = bucket_name or os.getenv("GCS_BUCKET_NAME")
|
@@ -5,36 +5,37 @@ from google.cloud.pubsub_v1.subscriber.futures import StreamingPullFuture
|
|
5
5
|
from google.cloud.pubsub_v1.subscriber.message import Message
|
6
6
|
from google.oauth2.service_account import Credentials
|
7
7
|
from pathlib import Path
|
8
|
-
from
|
9
|
-
from
|
8
|
+
from typing import Dict, List, Optional, Union, cast
|
9
|
+
from maleo_foundation.controller_types import ControllerTypes
|
10
|
+
from maleo_foundation.enums import BaseEnums
|
10
11
|
from maleo_foundation.managers.client.google.base import GoogleClientManager
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Controller = Union[SyncController, AsyncController]
|
15
|
-
OptionalController = Optional[Controller]
|
16
|
-
|
17
|
-
|
18
|
-
class SubscriptionConfigurations(BaseModel):
|
19
|
-
subscription_name: str
|
20
|
-
max_messages: int = 10
|
21
|
-
ack_deadline: int = 10
|
22
|
-
controller: OptionalController = None
|
12
|
+
from maleo_foundation.models.transfers.general.configurations.pubsub.subscription import (
|
13
|
+
ExtendedSubscriptionConfigurations,
|
14
|
+
)
|
23
15
|
|
24
16
|
|
25
17
|
class SubscriptionManager(GoogleClientManager):
|
26
18
|
def __init__(
|
27
19
|
self,
|
28
|
-
subscriptions: List[
|
20
|
+
subscriptions: List[ExtendedSubscriptionConfigurations],
|
29
21
|
log_config,
|
30
|
-
|
22
|
+
service_environment: Optional[BaseEnums.EnvironmentType] = None,
|
23
|
+
service_key: Optional[BaseEnums.Service] = None,
|
24
|
+
environment: Optional[BaseEnums.EnvironmentType] = None,
|
31
25
|
credentials: Optional[Credentials] = None,
|
32
26
|
credentials_path: Optional[Union[Path, str]] = None,
|
33
27
|
):
|
34
28
|
key = "google-subscription-manager"
|
35
29
|
name = "GoogleSubscriptionManager"
|
36
30
|
super().__init__(
|
37
|
-
key,
|
31
|
+
key,
|
32
|
+
name,
|
33
|
+
log_config,
|
34
|
+
service_environment,
|
35
|
+
service_key,
|
36
|
+
environment,
|
37
|
+
credentials,
|
38
|
+
credentials_path,
|
38
39
|
)
|
39
40
|
self.subscriber = pubsub_v1.SubscriberClient(credentials=self._credentials)
|
40
41
|
self.subscriptions = subscriptions
|
@@ -42,19 +43,28 @@ class SubscriptionManager(GoogleClientManager):
|
|
42
43
|
self.loop: Optional[asyncio.AbstractEventLoop] = None
|
43
44
|
|
44
45
|
async def _handle_async_controller(
|
45
|
-
self,
|
46
|
+
self,
|
47
|
+
controller: ControllerTypes.AsyncMessageController,
|
48
|
+
subscription_name: str,
|
49
|
+
message: Message,
|
46
50
|
) -> None:
|
47
51
|
success = await controller(subscription_name, message)
|
48
52
|
message.ack() if success else message.nack()
|
49
53
|
|
50
54
|
def _handle_sync_controller(
|
51
|
-
self,
|
55
|
+
self,
|
56
|
+
controller: ControllerTypes.SyncMessageController,
|
57
|
+
subscription_name: str,
|
58
|
+
message: Message,
|
52
59
|
) -> None:
|
53
60
|
success = controller(subscription_name, message)
|
54
61
|
message.ack() if success else message.nack()
|
55
62
|
|
56
63
|
def _message_callback(
|
57
|
-
self,
|
64
|
+
self,
|
65
|
+
controller: ControllerTypes.OptionalMessageController,
|
66
|
+
subscription_name: str,
|
67
|
+
message: Message,
|
58
68
|
):
|
59
69
|
# If controller is not given, conduct default message processing
|
60
70
|
if controller is None:
|
@@ -68,13 +78,17 @@ class SubscriptionManager(GoogleClientManager):
|
|
68
78
|
raise RuntimeError("Event loop not set in SubscriptionManager")
|
69
79
|
asyncio.run_coroutine_threadsafe(
|
70
80
|
self._handle_async_controller(
|
71
|
-
cast(
|
81
|
+
cast(ControllerTypes.AsyncMessageController, controller),
|
82
|
+
subscription_name,
|
83
|
+
message,
|
72
84
|
),
|
73
85
|
self.loop,
|
74
86
|
)
|
75
87
|
else:
|
76
88
|
self._handle_sync_controller(
|
77
|
-
cast(
|
89
|
+
cast(ControllerTypes.SyncMessageController, controller),
|
90
|
+
subscription_name,
|
91
|
+
message,
|
78
92
|
)
|
79
93
|
|
80
94
|
def _default_message_processing(
|
@@ -94,18 +108,18 @@ class SubscriptionManager(GoogleClientManager):
|
|
94
108
|
message.nack()
|
95
109
|
|
96
110
|
async def _start_subscription_listener(
|
97
|
-
self, config:
|
111
|
+
self, config: ExtendedSubscriptionConfigurations
|
98
112
|
) -> None:
|
99
113
|
if self.credentials.project_id is None:
|
100
114
|
raise ValueError("Project ID must be set in credentials")
|
101
115
|
subscription_path = self.subscriber.subscription_path(
|
102
|
-
self.credentials.project_id, config.
|
116
|
+
self.credentials.project_id, config.id
|
103
117
|
)
|
104
118
|
flow_control = pubsub_v1.types.FlowControl(max_messages=config.max_messages)
|
105
119
|
future = self.subscriber.subscribe(
|
106
120
|
subscription_path,
|
107
121
|
callback=lambda message: self._message_callback(
|
108
|
-
config.controller, config.
|
122
|
+
config.controller, config.id, message
|
109
123
|
),
|
110
124
|
flow_control=flow_control,
|
111
125
|
await_callbacks_on_shutdown=True,
|
@@ -117,7 +131,7 @@ class SubscriptionManager(GoogleClientManager):
|
|
117
131
|
if not isinstance(e, asyncio.CancelledError):
|
118
132
|
self._logger.error(
|
119
133
|
"Listener error for subscription '%s': %s",
|
120
|
-
config.
|
134
|
+
config.id,
|
121
135
|
e,
|
122
136
|
exc_info=True,
|
123
137
|
)
|
@@ -74,7 +74,9 @@ class MaleoClientManager(ClientManager):
|
|
74
74
|
key,
|
75
75
|
name,
|
76
76
|
service_manager.log_config,
|
77
|
-
service_manager.
|
77
|
+
service_manager.settings.ENVIRONMENT,
|
78
|
+
service_manager.settings.SERVICE_KEY,
|
79
|
+
environment,
|
78
80
|
)
|
79
81
|
self._environment = environment
|
80
82
|
|
@@ -82,10 +84,6 @@ class MaleoClientManager(ClientManager):
|
|
82
84
|
def service_manager(self) -> ServiceManager:
|
83
85
|
return self._service_manager
|
84
86
|
|
85
|
-
@property
|
86
|
-
def environment(self) -> BaseEnums.EnvironmentType:
|
87
|
-
return self._environment
|
88
|
-
|
89
87
|
def _initialize_controllers(self) -> None:
|
90
88
|
# * Initialize managers
|
91
89
|
http_controller_manager = ClientHTTPControllerManager(url=self._url)
|
@@ -9,9 +9,13 @@ from maleo_foundation.utils.logging import SimpleConfig
|
|
9
9
|
|
10
10
|
|
11
11
|
class CredentialManager:
|
12
|
-
def __init__(
|
13
|
-
self
|
12
|
+
def __init__(
|
13
|
+
self,
|
14
|
+
log_config: SimpleConfig,
|
15
|
+
settings: Settings,
|
16
|
+
):
|
14
17
|
self.log_config = log_config
|
18
|
+
self.settings = settings
|
15
19
|
self._initialize()
|
16
20
|
|
17
21
|
def _load_google_credentials(self) -> None:
|
@@ -4,6 +4,7 @@ from maleo_foundation.models.schemas import BaseGeneralSchemas
|
|
4
4
|
from maleo_foundation.models.transfers.general.configurations.middleware import (
|
5
5
|
MiddlewareConfigurations,
|
6
6
|
)
|
7
|
+
from maleo_foundation.models.transfers.general.settings import Settings
|
7
8
|
from maleo_foundation.middlewares.authentication import add_authentication_middleware
|
8
9
|
from maleo_foundation.middlewares.base import add_base_middleware
|
9
10
|
from maleo_foundation.middlewares.cors import add_cors_middleware
|
@@ -14,12 +15,14 @@ class MiddlewareManager:
|
|
14
15
|
def __init__(
|
15
16
|
self,
|
16
17
|
app: FastAPI,
|
18
|
+
settings: Settings,
|
17
19
|
configurations: MiddlewareConfigurations,
|
18
20
|
keys: BaseGeneralSchemas.RSAKeys,
|
19
21
|
logger: MiddlewareLogger,
|
20
22
|
maleo_foundation: MaleoFoundationClientManager,
|
21
23
|
):
|
22
24
|
self._app = app
|
25
|
+
self._settings = settings
|
23
26
|
self._configurations = configurations
|
24
27
|
self._keys = keys
|
25
28
|
self._logger = logger
|
@@ -33,23 +36,20 @@ class MiddlewareManager:
|
|
33
36
|
def add_cors(self) -> None:
|
34
37
|
add_cors_middleware(
|
35
38
|
app=self._app,
|
36
|
-
allow_origins=self._configurations.
|
37
|
-
allow_methods=self._configurations.
|
38
|
-
allow_headers=self._configurations.
|
39
|
-
allow_credentials=self._configurations.
|
39
|
+
allow_origins=self._configurations.cors.allow_origins,
|
40
|
+
allow_methods=self._configurations.cors.allow_methods,
|
41
|
+
allow_headers=self._configurations.cors.allow_headers,
|
42
|
+
allow_credentials=self._configurations.cors.allow_credentials,
|
40
43
|
expose_headers=self._configurations.cors.expose_headers,
|
41
44
|
)
|
42
45
|
|
43
46
|
def add_base(self):
|
44
47
|
add_base_middleware(
|
45
48
|
app=self._app,
|
49
|
+
settings=self._settings,
|
46
50
|
keys=self._keys,
|
47
51
|
logger=self._logger,
|
48
52
|
maleo_foundation=self._maleo_foundation,
|
49
|
-
allow_origins=self._configurations.general.allow_origins,
|
50
|
-
allow_methods=self._configurations.general.allow_methods,
|
51
|
-
allow_headers=self._configurations.general.allow_headers,
|
52
|
-
allow_credentials=self._configurations.general.allow_credentials,
|
53
53
|
limit=self._configurations.base.limit,
|
54
54
|
window=self._configurations.base.window,
|
55
55
|
cleanup_interval=self._configurations.base.cleanup_interval,
|