Skip to content

Commit

Permalink
Protocols issue_crendential with override emit_event to use LightWeig…
Browse files Browse the repository at this point in the history
…htWebhook

Signed-off-by: Victor Lee <[email protected]>
  • Loading branch information
victorlee0505 committed Feb 8, 2023
1 parent 02b44d1 commit d122d35
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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

0 comments on commit d122d35

Please sign in to comment.