Skip to content

Commit

Permalink
feat: Handle Error Notify webhooks ATL-6934 (#1279)
Browse files Browse the repository at this point in the history
Signed-off-by: FabioPinheiro <fabiomgpinheiro@gmail.com>
Signed-off-by: Fabio Pinheiro <fabiomgpinheiro@gmail.com>
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Co-authored-by: Yurii Shynbuiev - IOHK <yurii.shynbuiev@iohk.io>
  • Loading branch information
FabioPinheiro and yshyn-iohk authored Aug 26, 2024
1 parent b19f514 commit 7c31a9d
Show file tree
Hide file tree
Showing 26 changed files with 577 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ object ConnectBackgroundJobs extends BackgroundJobsHelper {
_,
metaRetries,
_,
_
_,
_,
) if metaRetries > 0 =>
val inviteeProcessFlow = for {
walletAccessContext <- buildWalletAccessContextLayer(request.from)
Expand Down Expand Up @@ -147,7 +148,8 @@ object ConnectBackgroundJobs extends BackgroundJobsHelper {
Some(response),
metaRetries,
_,
_
_,
_,
) if metaRetries > 0 =>
val inviterProcessFlow = for {
walletAccessContext <- buildWalletAccessContextLayer(response.from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
PresentationRecord.ProtocolState.PresentationReceived
)
.mapError(err => Throwable(s"Error occurred while getting Presentation records: $err"))
_ <- ZIO.logInfo(s"Processing ${records.size} Presentation records")
_ <- ZIO
.foreachPar(records)(performPresentProofExchange)
.withParallelism(config.pollux.presentationBgJobProcessingParallelism)
Expand Down Expand Up @@ -97,17 +98,41 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
for {
_ <- ZIO.logDebug(s"Running action with records => $record")
_ <- record match {
case PresentationRecord(_, _, _, _, _, _, _, _, InvitationGenerated, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(
_,
_,
_,
_,
_,
_,
_,
_,
InvitationGenerated,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
ZIO.unit
case PresentationRecord(_, _, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(_, _, _, _, _, _, _, _, InvitationExpired, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalPending, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalReceived, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, ProposalRejected, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(
id,
Expand All @@ -131,6 +156,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.fail(InvalidState("PresentationRecord 'RequestPending' with no Record"))
Expand All @@ -156,6 +182,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
Verifier.handleRequestPending(id, requestPresentation)
Expand All @@ -181,6 +208,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.logDebug("PresentationRecord: RequestSent") *> ZIO.unit
Expand All @@ -206,6 +234,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: RequestReceived") *> ZIO.unit
Expand All @@ -231,12 +260,37 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: RequestRejected") *> ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, _, ProblemReportPending, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(
id,
_,
_,
_,
_,
_,
_,
_,
ProblemReportPending,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
ZIO.fail(NotImplemented)
case PresentationRecord(id, _, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, ProblemReportSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.fail(NotImplemented)
case PresentationRecord(
id,
Expand All @@ -260,6 +314,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.fail(NotImplemented)
Expand All @@ -285,6 +340,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.fail(InvalidState("PresentationRecord 'RequestPending' with no Record"))
Expand All @@ -311,6 +367,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
Prover.PresentationPending.handle(
Expand Down Expand Up @@ -343,6 +400,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.fail(InvalidState("PresentationRecord in 'PresentationGenerated' with no Presentation"))
Expand All @@ -369,12 +427,13 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Prover
ZIO.logDebug("PresentationRecord: PresentationGenerated") *> ZIO.unit
Prover.handlePresentationGenerated(id, presentation)

case PresentationRecord(id, _, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(id, _, _, _, _, _, _, _, PresentationSent, _, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
ZIO.logDebug("PresentationRecord: PresentationSent") *> ZIO.unit
case PresentationRecord(
id,
Expand All @@ -398,6 +457,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.fail(InvalidState("PresentationRecord in 'PresentationReceived' with no Presentation"))
Expand All @@ -423,6 +483,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.fail(InvalidState("PresentationRecord in 'PresentationReceived' with no Presentation Request"))
Expand All @@ -448,6 +509,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) => // Verifier
ZIO.logDebug("PresentationRecord: PresentationReceived") *> ZIO.unit
Expand Down Expand Up @@ -475,14 +537,87 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerificationFailed") *> ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, _, PresentationAccepted, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(
id,
_,
_,
_,
_,
_,
_,
_,
PresentationAccepted,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerifiedAccepted") *> ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, _, PresentationVerified, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(
id,
_,
_,
_,
_,
_,
_,
_,
PresentationVerified,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationVerified") *> ZIO.unit
case PresentationRecord(id, _, _, _, _, _, _, _, PresentationRejected, _, _, _, _, _, _, _, _, _, _, _, _, _) =>
case PresentationRecord(
id,
_,
_,
_,
_,
_,
_,
_,
PresentationRejected,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
ZIO.logDebug("PresentationRecord: PresentationRejected") *> ZIO.unit
case _ =>
ZIO.logWarning(s"Unhandled PresentationRecord state: ${record.protocolState}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation
import org.hyperledger.identus.pollux.core.model.{CredentialFormat, DidCommID, IssueCredentialRecord}
import org.hyperledger.identus.pollux.core.model.IssueCredentialRecord.{ProtocolState, Role}
import org.hyperledger.identus.pollux.core.service.MockCredentialService
import org.hyperledger.identus.shared.models.WalletId
import sttp.client3.{basicRequest, DeserializationException, UriContext}
import sttp.client3.ziojson.*
import sttp.model.StatusCode
Expand Down Expand Up @@ -114,7 +115,8 @@ object IssueControllerImplSpec extends ZIOSpecDefault with IssueControllerTestTo
Some(connectionResponse),
5,
None,
None
None,
WalletId.fromUUID(UUID.randomUUID)
)
val acceptCredentialOfferRequest = AcceptCredentialOfferRequest(
Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import org.hyperledger.identus.connect.core.model.ConnectionRecord.{ProtocolStat
import org.hyperledger.identus.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
import org.hyperledger.identus.mercury.protocol.invitation.v2.Invitation
import org.hyperledger.identus.shared.models.Failure
import org.hyperledger.identus.shared.models.WalletAccessContext
import org.hyperledger.identus.shared.models.WalletId
import zio.ZIO

import java.time.temporal.ChronoUnit
import java.time.Instant
Expand Down Expand Up @@ -43,7 +46,8 @@ case class ConnectionRecord(
connectionResponse: Option[ConnectionResponse],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[Failure]
metaLastFailure: Option[Failure],
walletId: WalletId,
) {
def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): ConnectionRecord = copy(
createdAt = createdAt.truncatedTo(unit),
Expand All @@ -52,6 +56,51 @@ case class ConnectionRecord(
)
}

/** Like [[ConnectionRecordBefore]] but without the walletId */
case class ConnectionRecordBeforeStored(
id: UUID,
createdAt: Instant,
updatedAt: Option[Instant],
thid: String,
label: Option[String],
goalCode: Option[String],
goal: Option[String],
role: Role,
protocolState: ProtocolState,
invitation: Invitation,
connectionRequest: Option[ConnectionRequest],
connectionResponse: Option[ConnectionResponse],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[Failure],
) {

def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS) = copy(
createdAt = createdAt.truncatedTo(unit),
updatedAt = updatedAt.map(_.truncatedTo(unit)),
metaNextRetry = metaNextRetry.map(_.truncatedTo(unit))
)

def withWalletId(walletId: WalletId): ConnectionRecord = ConnectionRecord(
id = id,
createdAt = createdAt,
updatedAt = updatedAt,
thid = thid,
label = label,
goalCode = goalCode,
goal = goal,
role = role,
protocolState = protocolState,
invitation = invitation,
connectionRequest = connectionRequest,
connectionResponse = connectionResponse,
metaRetries = metaRetries,
metaNextRetry = metaNextRetry,
metaLastFailure = metaLastFailure,
walletId = walletId
)
}

object ConnectionRecord {
enum Role:
case Inviter extends Role
Expand Down
Loading

0 comments on commit 7c31a9d

Please sign in to comment.