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 all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""v1.0 credential exchange light weight webhook."""


class LightWeightV10CredentialExchangeWebhook:
"""Class representing a state only credential exchange webhook."""

__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,
**kwargs,
):
"""
Initialize webhook object from V10CredentialExchange.

from a list of accepted attributes.
"""
[
self.__setattr__(key, kwargs.get(key))
for key in self.__acceptable_keys_list
if kwargs.get(key) is not None
]
if kwargs.get("_id") is not None:
self.credential_exchange_id = kwargs.get("_id")
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

from ..messages.credential_proposal import CredentialProposal, CredentialProposalSchema
from ..messages.credential_offer import CredentialOffer, CredentialOfferSchema
from ..messages.credential_exchange_webhook import (
LightWeightV10CredentialExchangeWebhook,
)

from . import UNENCRYPTED_TAGS

Expand Down Expand Up @@ -221,6 +224,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 = LightWeightV10CredentialExchangeWebhook(**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
@@ -0,0 +1,47 @@
"""v2.0 credential exchange light weight webhook."""


class LightWeightV20CredExRecordWebhook:
"""Class representing a state only credential exchange webhook."""

__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,
**kwargs,
):
"""
Initialize webhook object from V20CredExRecord.

from a list of accepted attributes.
"""
[
self.__setattr__(key, kwargs.get(key))
for key in self.__acceptable_keys_list
if kwargs.get(key) is not None
]
if kwargs.get("_id") is not None:
self.cred_ex_id = kwargs.get("_id")
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..messages.cred_offer import V20CredOffer, V20CredOfferSchema
from ..messages.cred_request import V20CredRequest, V20CredRequestSchema
from ..messages.inner.cred_preview import V20CredPreviewSchema
from ..messages.cred_ex_record_webhook import LightWeightV20CredExRecordWebhook

from . import UNENCRYPTED_TAGS

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 = LightWeightV20CredExRecordWebhook(**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