|
7 | 7 |
|
8 | 8 | from typing import Callable, Type, Union |
9 | 9 | from urllib.parse import urlparse |
| 10 | +from collections import MutableMapping |
| 11 | +from contextlib import suppress |
10 | 12 |
|
11 | 13 | from ...connections.models.connection_target import ConnectionTarget |
12 | 14 | from ...core.profile import Profile |
|
25 | 27 | ) |
26 | 28 | from .message import OutboundMessage |
27 | 29 |
|
| 30 | +from .constants import ( REMOVE_KEY ) |
| 31 | + |
28 | 32 | LOGGER = logging.getLogger(__name__) |
29 | 33 | MODULE_BASE_PATH = "aries_cloudagent.transport.outbound" |
30 | 34 |
|
@@ -87,10 +91,13 @@ def __init__(self, profile: Profile, handle_not_delivered: Callable = None): |
87 | 91 | self.running_transports = {} |
88 | 92 | self.task_queue = TaskQueue(max_active=200) |
89 | 93 | self._process_task: asyncio.Task = None |
| 94 | + self.light_webhook = False |
90 | 95 | if self.root_profile.settings.get("transport.max_outbound_retry"): |
91 | 96 | self.MAX_RETRY_COUNT = self.root_profile.settings[ |
92 | 97 | "transport.max_outbound_retry" |
93 | 98 | ] |
| 99 | + if self.root_profile.settings.get("transport.light_weight_webhook"): |
| 100 | + self.light_webhook = True |
94 | 101 |
|
95 | 102 | async def setup(self): |
96 | 103 | """Perform setup operations.""" |
@@ -309,6 +316,14 @@ async def encode_outbound_message( |
309 | 316 |
|
310 | 317 | return outbound_message |
311 | 318 |
|
| 319 | + def delete_keys_from_dict(self, dictionary, keys): |
| 320 | + for key in keys: |
| 321 | + with suppress(KeyError): |
| 322 | + del dictionary[key] |
| 323 | + for value in dictionary.values(): |
| 324 | + if isinstance(value, MutableMapping): |
| 325 | + self.delete_keys_from_dict(value, keys) |
| 326 | + |
312 | 327 | def enqueue_webhook( |
313 | 328 | self, |
314 | 329 | topic: str, |
@@ -343,6 +358,10 @@ def enqueue_webhook( |
343 | 358 | queued.payload = json.dumps(payload) |
344 | 359 | queued.state = QueuedOutboundMessage.STATE_PENDING |
345 | 360 | queued.retries = 4 if max_attempts is None else max_attempts - 1 |
| 361 | + |
| 362 | + if self.light_webhook: |
| 363 | + self.delete_keys_from_dict(payload, REMOVE_KEY) |
| 364 | + queued.payload = json.dumps(payload) |
346 | 365 | self.outbound_new.append(queued) |
347 | 366 | self.process_queued() |
348 | 367 |
|
|
0 commit comments