Skip to content

Commit 34c9805

Browse files
committed
transport.outbound.manager: remove redundant obj from webhook
Signed-off-by: Victor Lee <victorlee0505@gmail.com>
1 parent 85a24ac commit 34c9805

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

aries_cloudagent/transport/outbound/manager.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from typing import Callable, Type, Union
99
from urllib.parse import urlparse
10+
from collections import MutableMapping
11+
from contextlib import suppress
1012

1113
from ...connections.models.connection_target import ConnectionTarget
1214
from ...core.profile import Profile
@@ -25,6 +27,8 @@
2527
)
2628
from .message import OutboundMessage
2729

30+
from .constants import ( REMOVE_KEY )
31+
2832
LOGGER = logging.getLogger(__name__)
2933
MODULE_BASE_PATH = "aries_cloudagent.transport.outbound"
3034

@@ -87,10 +91,13 @@ def __init__(self, profile: Profile, handle_not_delivered: Callable = None):
8791
self.running_transports = {}
8892
self.task_queue = TaskQueue(max_active=200)
8993
self._process_task: asyncio.Task = None
94+
self.light_webhook = False
9095
if self.root_profile.settings.get("transport.max_outbound_retry"):
9196
self.MAX_RETRY_COUNT = self.root_profile.settings[
9297
"transport.max_outbound_retry"
9398
]
99+
if self.root_profile.settings.get("transport.light_weight_webhook"):
100+
self.light_webhook = True
94101

95102
async def setup(self):
96103
"""Perform setup operations."""
@@ -309,6 +316,14 @@ async def encode_outbound_message(
309316

310317
return outbound_message
311318

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+
312327
def enqueue_webhook(
313328
self,
314329
topic: str,
@@ -343,6 +358,10 @@ def enqueue_webhook(
343358
queued.payload = json.dumps(payload)
344359
queued.state = QueuedOutboundMessage.STATE_PENDING
345360
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)
346365
self.outbound_new.append(queued)
347366
self.process_queued()
348367

0 commit comments

Comments
 (0)