Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startup flag --light-weight-webhook to trim down outbound webhook payload #1941

Merged
merged 16 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,12 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_MAX_MESSAGE_SIZE",
help="Set the maximum size in bytes for inbound agent messages.",
)
parser.add_argument(
"--light-weight-webhook",
action="store_true",
env_var="ACAPY_LIGHT_WEIGHT_WEBHOOK",
help="omitted client's info from issue-credential related webhook",
)
parser.add_argument(
"--enable-undelivered-queue",
action="store_true",
Expand Down Expand Up @@ -1372,6 +1378,8 @@ def get_settings(self, args: Namespace):
settings["image_url"] = args.image_url
if args.max_message_size:
settings["transport.max_message_size"] = args.max_message_size
if args.light_weight_webhook:
settings["transport.light_weight_webhook"] = True
if args.max_outbound_retry:
settings["transport.max_outbound_retry"] = args.max_outbound_retry
if args.ws_heartbeat_interval:
Expand Down
40 changes: 40 additions & 0 deletions aries_cloudagent/messaging/models/light_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class LightWeightWebhook:
__acceptable_keys_list = [
"connection_id",
"credential_exchange_id",
"cred_ex_id",
"cred_def_id",
"role",
"initiator",
"revoc_reg_id",
"revocation_id",
"auto_offer",
"auto_issue",
"auto_remove",
"error_msg",
"thread_id",
"parent_thread_id",
"state",
"credential_definition_id",
"schema_id",
"credential_id",
"trace",
"public_did",
"cred_id_stored",
"conn_id",
]

def __init__(
self,
version, # 2 = V20CredExRecord ; 1 = V10CredentialExchange
**kwargs,
):
[
self.__setattr__(key, kwargs.get(key))
for key in self.__acceptable_keys_list
if kwargs.get(key) is not None
]
if version == 2:
self.cred_ex_id = kwargs.get("_id")
else:
self.credential_exchange_id = kwargs.get("_id")
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .....indy.models.cred_precis import IndyCredInfo, IndyCredInfoSchema
from .....indy.models.cred_request import IndyCredRequest, IndyCredRequestSchema
from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema
from .....messaging.models.light_webhook import LightWeightWebhook
from .....messaging.valid import INDY_CRED_DEF_ID, INDY_SCHEMA_ID, UUIDFour
from .....storage.base import StorageError

Expand Down Expand Up @@ -221,6 +222,33 @@ async def save_error_state(
except StorageError:
LOGGER.exception("Error saving credential exchange error state")

# Override
async def emit_event(self, session: ProfileSession, payload: Any = None):
"""
Emit an event.

Args:
session: The profile session to use
payload: The event payload
"""

if not self.RECORD_TOPIC:
return

if self.state:
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}"
else:
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}"

if not payload:
payload = self.serialize()

if session.profile.settings.get("transport.light_weight_webhook"):
payload = LightWeightWebhook(1, **self.__dict__)
payload = payload.__dict__

await session.profile.notify(topic, payload)

@property
def record_value(self) -> dict:
"""Accessor for the JSON record value generated for this invitation."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .....core.profile import ProfileSession
from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema
from .....messaging.models.light_webhook import LightWeightWebhook
from .....messaging.valid import UUIDFour
from .....storage.base import StorageError

Expand Down Expand Up @@ -181,6 +182,33 @@ async def save_error_state(
except StorageError as err:
LOGGER.exception(err)

# Override
async def emit_event(self, session: ProfileSession, payload: Any = None):
"""
Emit an event.

Args:
session: The profile session to use
payload: The event payload
"""

if not self.RECORD_TOPIC:
return

if self.state:
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}"
else:
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}"

if not payload:
payload = self.serialize()

if session.profile.settings.get("transport.light_weight_webhook"):
payload = LightWeightWebhook(2, **self.__dict__)
payload = payload.__dict__

await session.profile.notify(topic, payload)

@property
def record_value(self) -> Mapping:
"""Accessor for the JSON record value generated for this credential exchange."""
Expand Down