Skip to content

Commit 523249e

Browse files
committed
refactored light weight webhook object for v1 & v2 cred exchange
Signed-off-by: Victor Lee <victorlee0505@gmail.com>
1 parent d1c68fc commit 523249e

4 files changed

Lines changed: 61 additions & 9 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""v1.0 credential exchange light weight webhook"""
2+
3+
class LightWeightV10CredentialExchangeWebhook:
4+
"""Class representing a state only credential exchange webhook."""
5+
6+
__acceptable_keys_list = [
7+
"connection_id",
8+
"credential_exchange_id",
9+
"cred_ex_id",
10+
"cred_def_id",
11+
"role",
12+
"initiator",
13+
"revoc_reg_id",
14+
"revocation_id",
15+
"auto_offer",
16+
"auto_issue",
17+
"auto_remove",
18+
"error_msg",
19+
"thread_id",
20+
"parent_thread_id",
21+
"state",
22+
"credential_definition_id",
23+
"schema_id",
24+
"credential_id",
25+
"trace",
26+
"public_did",
27+
"cred_id_stored",
28+
"conn_id",
29+
]
30+
31+
def __init__(
32+
self,
33+
**kwargs,
34+
):
35+
"""
36+
Initialize webhook object from V10CredentialExchange
37+
from a list of accepted attributes.
38+
"""
39+
[
40+
self.__setattr__(key, kwargs.get(key))
41+
for key in self.__acceptable_keys_list
42+
if kwargs.get(key) is not None
43+
]
44+
if kwargs.get("_id") is not None:
45+
self.credential_exchange_id = kwargs.get("_id")

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
from .....indy.models.cred_precis import IndyCredInfo, IndyCredInfoSchema
1313
from .....indy.models.cred_request import IndyCredRequest, IndyCredRequestSchema
1414
from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema
15-
from .....messaging.models.light_webhook import LightWeightWebhook
1615
from .....messaging.valid import INDY_CRED_DEF_ID, INDY_SCHEMA_ID, UUIDFour
1716
from .....storage.base import StorageError
1817

1918
from ..messages.credential_proposal import CredentialProposal, CredentialProposalSchema
2019
from ..messages.credential_offer import CredentialOffer, CredentialOfferSchema
20+
from ..messages.credential_exchange_webhook import (
21+
LightWeightV10CredentialExchangeWebhook,
22+
)
2123

2224
from . import UNENCRYPTED_TAGS
2325

@@ -244,7 +246,7 @@ async def emit_event(self, session: ProfileSession, payload: Any = None):
244246
payload = self.serialize()
245247

246248
if session.profile.settings.get("transport.light_weight_webhook"):
247-
payload = LightWeightWebhook(1, **self.__dict__)
249+
payload = LightWeightV10CredentialExchangeWebhook(**self.__dict__)
248250
payload = payload.__dict__
249251

250252
await session.profile.notify(topic, payload)

aries_cloudagent/messaging/models/light_webhook.py renamed to aries_cloudagent/protocols/issue_credential/v2_0/messages/cred_ex_record_webhook.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
class LightWeightWebhook:
1+
"""v2.0 credential exchange light weight webhook"""
2+
3+
class LightWeightV20CredExRecordWebhook:
4+
"""Class representing a state only credential exchange webhook."""
5+
26
__acceptable_keys_list = [
37
"connection_id",
48
"credential_exchange_id",
@@ -26,15 +30,16 @@ class LightWeightWebhook:
2630

2731
def __init__(
2832
self,
29-
version, # 2 = V20CredExRecord ; 1 = V10CredentialExchange
3033
**kwargs,
3134
):
35+
"""
36+
Initialize webhook object from V20CredExRecord
37+
from a list of accepted attributes.
38+
"""
3239
[
3340
self.__setattr__(key, kwargs.get(key))
3441
for key in self.__acceptable_keys_list
3542
if kwargs.get(key) is not None
3643
]
37-
if version == 2:
44+
if kwargs.get("_id") is not None:
3845
self.cred_ex_id = kwargs.get("_id")
39-
else:
40-
self.credential_exchange_id = kwargs.get("_id")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from .....core.profile import ProfileSession
1010
from .....messaging.models.base_record import BaseExchangeRecord, BaseExchangeSchema
11-
from .....messaging.models.light_webhook import LightWeightWebhook
1211
from .....messaging.valid import UUIDFour
1312
from .....storage.base import StorageError
1413

@@ -18,6 +17,7 @@
1817
from ..messages.cred_offer import V20CredOffer, V20CredOfferSchema
1918
from ..messages.cred_request import V20CredRequest, V20CredRequestSchema
2019
from ..messages.inner.cred_preview import V20CredPreviewSchema
20+
from ..messages.cred_ex_record_webhook import LightWeightV20CredExRecordWebhook
2121

2222
from . import UNENCRYPTED_TAGS
2323

@@ -204,7 +204,7 @@ async def emit_event(self, session: ProfileSession, payload: Any = None):
204204
payload = self.serialize()
205205

206206
if session.profile.settings.get("transport.light_weight_webhook"):
207-
payload = LightWeightWebhook(2, **self.__dict__)
207+
payload = LightWeightV20CredExRecordWebhook(**self.__dict__)
208208
payload = payload.__dict__
209209

210210
await session.profile.notify(topic, payload)

0 commit comments

Comments
 (0)