Skip to content

Commit d2ec18e

Browse files
authored
Merge branch 'main' into delete-tail-files
2 parents bca3cfd + 16d7455 commit d2ec18e

5 files changed

Lines changed: 160 additions & 0 deletions

File tree

aries_cloudagent/config/argparse.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,12 @@ def add_arguments(self, parser: ArgumentParser):
13091309
env_var="ACAPY_MAX_MESSAGE_SIZE",
13101310
help="Set the maximum size in bytes for inbound agent messages.",
13111311
)
1312+
parser.add_argument(
1313+
"--light-weight-webhook",
1314+
action="store_true",
1315+
env_var="ACAPY_LIGHT_WEIGHT_WEBHOOK",
1316+
help="omitted client's info from issue-credential related webhook",
1317+
)
13121318
parser.add_argument(
13131319
"--enable-undelivered-queue",
13141320
action="store_true",
@@ -1372,6 +1378,8 @@ def get_settings(self, args: Namespace):
13721378
settings["image_url"] = args.image_url
13731379
if args.max_message_size:
13741380
settings["transport.max_message_size"] = args.max_message_size
1381+
if args.light_weight_webhook:
1382+
settings["transport.light_weight_webhook"] = True
13751383
if args.max_outbound_retry:
13761384
settings["transport.max_outbound_retry"] = args.max_outbound_retry
13771385
if args.ws_heartbeat_interval:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""v1.0 credential exchange light weight webhook."""
2+
3+
4+
class LightWeightV10CredentialExchangeWebhook:
5+
"""Class representing a state only credential exchange webhook."""
6+
7+
__acceptable_keys_list = [
8+
"connection_id",
9+
"credential_exchange_id",
10+
"cred_ex_id",
11+
"cred_def_id",
12+
"role",
13+
"initiator",
14+
"revoc_reg_id",
15+
"revocation_id",
16+
"auto_offer",
17+
"auto_issue",
18+
"auto_remove",
19+
"error_msg",
20+
"thread_id",
21+
"parent_thread_id",
22+
"state",
23+
"credential_definition_id",
24+
"schema_id",
25+
"credential_id",
26+
"trace",
27+
"public_did",
28+
"cred_id_stored",
29+
"conn_id",
30+
]
31+
32+
def __init__(
33+
self,
34+
**kwargs,
35+
):
36+
"""
37+
Initialize webhook object from V10CredentialExchange.
38+
39+
from a list of accepted attributes.
40+
"""
41+
[
42+
self.__setattr__(key, kwargs.get(key))
43+
for key in self.__acceptable_keys_list
44+
if kwargs.get(key) is not None
45+
]
46+
if kwargs.get("_id") is not None:
47+
self.credential_exchange_id = kwargs.get("_id")

aries_cloudagent/protocols/issue_credential/v1_0/models/credential_exchange.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
from ..messages.credential_proposal import CredentialProposal, CredentialProposalSchema
1919
from ..messages.credential_offer import CredentialOffer, CredentialOfferSchema
20+
from ..messages.credential_exchange_webhook import (
21+
LightWeightV10CredentialExchangeWebhook,
22+
)
2023

2124
from . import UNENCRYPTED_TAGS
2225

@@ -221,6 +224,33 @@ async def save_error_state(
221224
except StorageError:
222225
LOGGER.exception("Error saving credential exchange error state")
223226

227+
# Override
228+
async def emit_event(self, session: ProfileSession, payload: Any = None):
229+
"""
230+
Emit an event.
231+
232+
Args:
233+
session: The profile session to use
234+
payload: The event payload
235+
"""
236+
237+
if not self.RECORD_TOPIC:
238+
return
239+
240+
if self.state:
241+
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}"
242+
else:
243+
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}"
244+
245+
if not payload:
246+
payload = self.serialize()
247+
248+
if session.profile.settings.get("transport.light_weight_webhook"):
249+
payload = LightWeightV10CredentialExchangeWebhook(**self.__dict__)
250+
payload = payload.__dict__
251+
252+
await session.profile.notify(topic, payload)
253+
224254
@property
225255
def record_value(self) -> dict:
226256
"""Accessor for the JSON record value generated for this invitation."""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""v2.0 credential exchange light weight webhook."""
2+
3+
4+
class LightWeightV20CredExRecordWebhook:
5+
"""Class representing a state only credential exchange webhook."""
6+
7+
__acceptable_keys_list = [
8+
"connection_id",
9+
"credential_exchange_id",
10+
"cred_ex_id",
11+
"cred_def_id",
12+
"role",
13+
"initiator",
14+
"revoc_reg_id",
15+
"revocation_id",
16+
"auto_offer",
17+
"auto_issue",
18+
"auto_remove",
19+
"error_msg",
20+
"thread_id",
21+
"parent_thread_id",
22+
"state",
23+
"credential_definition_id",
24+
"schema_id",
25+
"credential_id",
26+
"trace",
27+
"public_did",
28+
"cred_id_stored",
29+
"conn_id",
30+
]
31+
32+
def __init__(
33+
self,
34+
**kwargs,
35+
):
36+
"""
37+
Initialize webhook object from V20CredExRecord.
38+
39+
from a list of accepted attributes.
40+
"""
41+
[
42+
self.__setattr__(key, kwargs.get(key))
43+
for key in self.__acceptable_keys_list
44+
if kwargs.get(key) is not None
45+
]
46+
if kwargs.get("_id") is not None:
47+
self.cred_ex_id = kwargs.get("_id")

aries_cloudagent/protocols/issue_credential/v2_0/models/cred_ex_record.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..messages.cred_offer import V20CredOffer, V20CredOfferSchema
1818
from ..messages.cred_request import V20CredRequest, V20CredRequestSchema
1919
from ..messages.inner.cred_preview import V20CredPreviewSchema
20+
from ..messages.cred_ex_record_webhook import LightWeightV20CredExRecordWebhook
2021

2122
from . import UNENCRYPTED_TAGS
2223

@@ -181,6 +182,33 @@ async def save_error_state(
181182
except StorageError as err:
182183
LOGGER.exception(err)
183184

185+
# Override
186+
async def emit_event(self, session: ProfileSession, payload: Any = None):
187+
"""
188+
Emit an event.
189+
190+
Args:
191+
session: The profile session to use
192+
payload: The event payload
193+
"""
194+
195+
if not self.RECORD_TOPIC:
196+
return
197+
198+
if self.state:
199+
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}::{self.state}"
200+
else:
201+
topic = f"{self.EVENT_NAMESPACE}::{self.RECORD_TOPIC}"
202+
203+
if not payload:
204+
payload = self.serialize()
205+
206+
if session.profile.settings.get("transport.light_weight_webhook"):
207+
payload = LightWeightV20CredExRecordWebhook(**self.__dict__)
208+
payload = payload.__dict__
209+
210+
await session.profile.notify(topic, payload)
211+
184212
@property
185213
def record_value(self) -> Mapping:
186214
"""Accessor for the JSON record value generated for this credential exchange."""

0 commit comments

Comments
 (0)