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

Update webhook message to terse form by default, added startup flag --debug-webhooks for full form #2145

Merged
merged 10 commits into from
Mar 6, 2023
16 changes: 8 additions & 8 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ def add_arguments(self, parser: ArgumentParser):
"Default: false."
),
)
parser.add_argument(
"--debug-webhooks",
action="store_true",
env_var="ACAPY_DEBUG_WEBHOOKS",
help=("Emit protocol state object as webhook. " "Default: false."),
)
parser.add_argument(
"--invite",
action="store_true",
Expand Down Expand Up @@ -424,6 +430,8 @@ def get_settings(self, args: Namespace) -> dict:
settings["debug.credentials"] = True
if args.debug_presentations:
settings["debug.presentations"] = True
if args.debug_webhooks:
settings["debug.webhooks"] = True
if args.debug_seed:
settings["debug.seed"] = args.debug_seed
if args.invite:
Expand Down Expand Up @@ -1309,12 +1317,6 @@ 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 @@ -1378,8 +1380,6 @@ 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
@@ -1,7 +1,7 @@
"""v1.0 credential exchange light weight webhook."""
"""v1.0 credential exchange webhook."""


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

__acceptable_keys_list = [
Expand All @@ -27,6 +27,8 @@ class LightWeightV10CredentialExchangeWebhook:
"public_did",
"cred_id_stored",
"conn_id",
"created_at",
"updated_at",
]

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ..messages.credential_proposal import CredentialProposal, CredentialProposalSchema
from ..messages.credential_offer import CredentialOffer, CredentialOfferSchema
from ..messages.credential_exchange_webhook import (
LightWeightV10CredentialExchangeWebhook,
V10CredentialExchangeWebhook,
)

from . import UNENCRYPTED_TAGS
Expand Down Expand Up @@ -242,11 +242,11 @@ async def emit_event(self, session: ProfileSession, payload: Any = None):
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__)
if session.profile.settings.get("debug.webhooks"):
if not payload:
payload = self.serialize()
else:
payload = V10CredentialExchangeWebhook(**self.__dict__)
payload = payload.__dict__

await session.profile.notify(topic, payload)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""v2.0 credential exchange light weight webhook."""
"""v2.0 credential exchange webhook."""


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

__acceptable_keys_list = [
Expand All @@ -27,6 +27,8 @@ class LightWeightV20CredExRecordWebhook:
"public_did",
"cred_id_stored",
"conn_id",
"created_at",
"updated_at",
]

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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 ..messages.cred_ex_record_webhook import V20CredExRecordWebhook

from . import UNENCRYPTED_TAGS

Expand Down Expand Up @@ -202,11 +202,11 @@ async def emit_event(self, session: ProfileSession, payload: Any = None):
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__)
if session.profile.settings.get("debug.webhooks"):
if not payload:
payload = self.serialize()
else:
payload = V20CredExRecordWebhook(**self.__dict__)
payload = payload.__dict__

await session.profile.notify(topic, payload)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""v1.0 presentation exchange information webhook."""


class V10PresentationExchangeWebhook:
"""Class representing a state only presentation exchange webhook."""

__acceptable_keys_list = [
"connection_id",
"presentation_exchange_id",
"role",
"initiator",
"auto_present",
"auto_verify",
"error_msg",
"state",
"thread_id",
"trace",
"verified",
"verified_msgs",
"created_at",
"updated_at",
]

def __init__(
self,
**kwargs,
):
"""
Initialize webhook object from V10PresentationExchange.

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.presentation_exchange_id = kwargs.get("_id")
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PresentationRequest,
PresentationRequestSchema,
)
from ..messages.presentation_webhook import V10PresentationExchangeWebhook

from . import UNENCRYPTED_TAGS

Expand Down Expand Up @@ -195,6 +196,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 session.profile.settings.get("debug.webhooks"):
if not payload:
payload = self.serialize()
else:
payload = V10PresentationExchangeWebhook(**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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""v2.0 Presentation exchange record webhook."""


class V20PresExRecordWebhook:
"""Class representing a state only Presentation exchange record webhook."""

__acceptable_keys_list = [
"connection_id",
"pres_ex_id",
"role",
"initiator",
"auto_present",
"auto_verify",
"error_msg",
"thread_id",
"state",
"trace",
"verified",
"verified_msgs",
"created_at",
"updated_at",
]

def __init__(
self,
**kwargs,
):
"""
Initialize webhook object from V20PresExRecord.

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.pres_ex_id = kwargs.get("_id")
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..messages.pres_format import V20PresFormat
from ..messages.pres_proposal import V20PresProposal, V20PresProposalSchema
from ..messages.pres_request import V20PresRequest, V20PresRequestSchema
from ..messages.pres_webhook import V20PresExRecordWebhook

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 session.profile.settings.get("debug.webhooks"):
if not payload:
payload = self.serialize()
else:
payload = V20PresExRecordWebhook(**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