Skip to content

Commit

Permalink
Merge branch 'ATL-4215' of iohk.github.com:input-output-hk/atala-pris…
Browse files Browse the repository at this point in the history
…m-building-blocks into ATL-4215
  • Loading branch information
mineme0110 committed May 22, 2023
2 parents 1a568a3 + 660f165 commit 836c5c8
Show file tree
Hide file tree
Showing 69 changed files with 3,996 additions and 5,146 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [1.2.0](https://github.com/input-output-hk/atala-prism-building-blocks/compare/prism-agent-v1.1.0...prism-agent-v1.2.0) (2023-05-17)


### Bug Fixes

* **prism-agent:** refactor crypto abstraction in the walletAPI ([#522](https://github.com/input-output-hk/atala-prism-building-blocks/issues/522)) ([e36c634](https://github.com/input-output-hk/atala-prism-building-blocks/commit/e36c63424ed2e28fc360c6a6a5d557938d4ec01a))


### Features

* migrate issue endpoint to tapir ([#516](https://github.com/input-output-hk/atala-prism-building-blocks/issues/516)) ([9b1558f](https://github.com/input-output-hk/atala-prism-building-blocks/commit/9b1558f50003ba1c79ec2cdd9888f2e99f0534d8))
* **prism-agent:** fix infinite reprocessing of records in error ([#528](https://github.com/input-output-hk/atala-prism-building-blocks/issues/528)) ([904a2dc](https://github.com/input-output-hk/atala-prism-building-blocks/commit/904a2dcb09d2e907e284479c652c5f389fd0dec9))
* **prism-agent:** migrate present-proof endpoints to Tapir ([#525](https://github.com/input-output-hk/atala-prism-building-blocks/issues/525)) ([cb01657](https://github.com/input-output-hk/atala-prism-building-blocks/commit/cb016570b6d0a1b0de98928d6daa1cbf055d26b4))

# [1.1.0](https://github.com/input-output-hk/atala-prism-building-blocks/compare/prism-agent-v1.0.0...prism-agent-v1.1.0) (2023-05-05)


Expand Down
19 changes: 2 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ lazy val V = new {
val jwtCirceVersion = "9.1.2"
val zioPreludeVersion = "1.0.0-RC16"

val akka = "2.6.20"
val akkaHttp = "10.2.9"
val bouncyCastle = "1.70"
}

Expand Down Expand Up @@ -269,11 +267,6 @@ lazy val D_Pollux_VC_JWT = new {

lazy val D_PrismAgent = new {

val akkaTyped = "com.typesafe.akka" %% "akka-actor-typed" % V.akka
val akkaStream = "com.typesafe.akka" %% "akka-stream" % V.akka
val akkaHttp = "com.typesafe.akka" %% "akka-http" % V.akkaHttp
val akkaSprayJson = "com.typesafe.akka" %% "akka-http-spray-json" % V.akkaHttp

// Added here to make prism-crypto works.
// Once migrated to apollo, re-evaluate if this should be removed.
val bouncyBcpkix = "org.bouncycastle" % "bcpkix-jdk15on" % V.bouncyCastle
Expand Down Expand Up @@ -318,8 +311,6 @@ lazy val D_PrismAgent = new {
D.zioHttp,
D.zioMetrics,
)
val akkaHttpDependencies: Seq[ModuleID] =
Seq(akkaTyped, akkaStream, akkaHttp, akkaSprayJson).map(_.cross(CrossVersion.for3Use2_13))
val bouncyDependencies: Seq[ModuleID] = Seq(bouncyBcpkix, bouncyBcprov)
val tapirDependencies: Seq[ModuleID] =
Seq(
Expand All @@ -341,7 +332,7 @@ lazy val D_PrismAgent = new {
baseDependencies ++ bouncyDependencies ++ D.doobieDependencies ++ Seq(D.zioCatsInterop)

lazy val serverDependencies: Seq[ModuleID] =
baseDependencies ++ akkaHttpDependencies ++ tapirDependencies ++ postgresDependencies
baseDependencies ++ tapirDependencies ++ postgresDependencies
}

publish / skip := true
Expand Down Expand Up @@ -666,12 +657,6 @@ lazy val prismAgentServer = project
fork := true,
libraryDependencies ++= D_PrismAgent.serverDependencies,
Compile / mainClass := Some("io.iohk.atala.agent.server.MainApp"),
// OpenAPI settings
Compile / unmanagedResourceDirectories += baseDirectory.value / ".." / "api",
Compile / sourceGenerators += openApiGenerateClasses,
openApiGeneratorSpec := baseDirectory.value / ".." / "api" / "http/prism-agent-openapi-spec.yaml",
openApiGeneratorConfig := baseDirectory.value / "openapi/generator-config/config.yaml",
openApiGeneratorImportMapping := Map.empty,
Docker / maintainer := "[email protected]",
Docker / dockerUsername := Some("input-output-hk"),
Docker / dockerRepository := Some("ghcr.io"),
Expand All @@ -681,7 +666,7 @@ lazy val prismAgentServer = project
buildInfoPackage := "io.iohk.atala.agent.server.buildinfo"
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
.enablePlugins(OpenApiGeneratorPlugin, BuildInfoPlugin)
.enablePlugins(BuildInfoPlugin)
.dependsOn(prismAgentWalletAPI)
.dependsOn(
agent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import io.iohk.atala.connect.core.model.ConnectionRecord.{ProtocolState, Role}
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation

import java.util.UUID
import java.time.Instant
import java.util.UUID

/** @param id
* @param createdAt
Expand Down Expand Up @@ -36,6 +36,7 @@ case class ConnectionRecord(
connectionRequest: Option[ConnectionRequest],
connectionResponse: Option[ConnectionResponse],
metaRetries: Int,
metaNextRetry: Option[Instant],
metaLastFailure: Option[String]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import io.iohk.atala.connect.core.model.ConnectionRecord
trait ConnectionRepository[F[_]] {
def createConnectionRecord(record: ConnectionRecord): F[Int]

def getConnectionRecords(): F[Seq[ConnectionRecord]]
def getConnectionRecords: F[Seq[ConnectionRecord]]

def getConnectionRecordsByStates(states: ConnectionRecord.ProtocolState*): F[Seq[ConnectionRecord]]
def getConnectionRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ConnectionRecord.ProtocolState*
): F[Seq[ConnectionRecord]]

def getConnectionRecord(recordId: UUID): F[Option[ConnectionRecord]]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.iohk.atala.connect.core.repository

import io.iohk.atala.connect.core.model.ConnectionRecord
import io.iohk.atala.connect.core.model.error.ConnectionRepositoryError._
import io.iohk.atala.connect.core.model.ConnectionRecord.ProtocolState
import io.iohk.atala.mercury.protocol.connection.ConnectionRequest
import io.iohk.atala.mercury.protocol.connection.ConnectionResponse
import zio._
import io.iohk.atala.connect.core.model.error.ConnectionRepositoryError.*
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
import zio.*

import java.time.Instant
import java.util.UUID
Expand Down Expand Up @@ -141,16 +140,23 @@ class ConnectionRepositoryInMemory(storeRef: Ref[Map[UUID, ConnectionRecord]]) e
} yield store.values.find(_.thid.contains(thid))
}

override def getConnectionRecords(): Task[Seq[ConnectionRecord]] = {
override def getConnectionRecords: Task[Seq[ConnectionRecord]] = {
for {
store <- storeRef.get
} yield store.values.toSeq
}

override def getConnectionRecordsByStates(states: ConnectionRecord.ProtocolState*): Task[Seq[ConnectionRecord]] = {
override def getConnectionRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ConnectionRecord.ProtocolState*
): Task[Seq[ConnectionRecord]] = {
for {
store <- storeRef.get
} yield store.values.filter(rec => states.contains(rec.protocolState)).toSeq
} yield store.values
.filter(rec => (ignoreWithZeroRetries & rec.metaRetries > 0) & states.contains(rec.protocolState))
.take(limit)
.toSeq
}

override def createConnectionRecord(record: ConnectionRecord): Task[Int] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package io.iohk.atala.connect.core.service

import io.iohk.atala.connect.core.model.ConnectionRecord
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
import zio._
import java.util.UUID
import io.iohk.atala.connect.core.model.error.ConnectionServiceError.RepositoryError
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation
import io.iohk.atala.mercury.protocol.connection.ConnectionRequest
import io.iohk.atala.mercury.protocol.connection.ConnectionResponse
import zio.*

import java.util.UUID

trait ConnectionService {

Expand Down Expand Up @@ -36,6 +37,8 @@ trait ConnectionService {
def getConnectionRecords(): IO[ConnectionServiceError, Seq[ConnectionRecord]]

def getConnectionRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ConnectionRecord.ProtocolState*
): IO[ConnectionServiceError, Seq[ConnectionRecord]]

Expand All @@ -44,6 +47,6 @@ trait ConnectionService {

def deleteConnectionRecord(recordId: UUID): IO[ConnectionServiceError, Int]

def reportProcessingFailure(recordId: UUID, failReason: Option[String]): IO[ConnectionServiceError, Int]
def reportProcessingFailure(recordId: UUID, failReason: Option[String]): IO[ConnectionServiceError, Unit]

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.iohk.atala.connect.core.service

import zio._
import io.iohk.atala.connect.core.repository.ConnectionRepository
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
import io.iohk.atala.connect.core.model.error.ConnectionServiceError._
import io.iohk.atala.connect.core.model.ConnectionRecord
import io.iohk.atala.connect.core.model.ConnectionRecord._
import java.util.UUID
import io.iohk.atala.mercury._
import io.iohk.atala.connect.core.model.ConnectionRecord.*
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
import io.iohk.atala.connect.core.model.error.ConnectionServiceError.*
import io.iohk.atala.connect.core.repository.ConnectionRepository
import io.iohk.atala.mercury.*
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.connection.*
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation
import io.iohk.atala.mercury.protocol.connection._
import java.time.Instant
import java.rmi.UnexpectedException
import io.iohk.atala.shared.utils.Base64Utils
import zio.*

import java.rmi.UnexpectedException
import java.time.Instant
import java.util.UUID

private class ConnectionServiceImpl(
connectionRepository: ConnectionRepository[Task],
Expand All @@ -39,6 +40,7 @@ private class ConnectionServiceImpl(
connectionRequest = None,
connectionResponse = None,
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
)
Expand All @@ -53,18 +55,19 @@ private class ConnectionServiceImpl(

override def getConnectionRecords(): IO[ConnectionServiceError, Seq[ConnectionRecord]] = {
for {
records <- connectionRepository
.getConnectionRecords()
records <- connectionRepository.getConnectionRecords
.mapError(RepositoryError.apply)
} yield records
}

override def getConnectionRecordsByStates(
ignoreWithZeroRetries: Boolean,
limit: Int,
states: ProtocolState*
): IO[ConnectionServiceError, Seq[ConnectionRecord]] = {
for {
records <- connectionRepository
.getConnectionRecordsByStates(states: _*)
.getConnectionRecordsByStates(ignoreWithZeroRetries, limit, states: _*)
.mapError(RepositoryError.apply)
} yield records
}
Expand Down Expand Up @@ -106,6 +109,7 @@ private class ConnectionServiceImpl(
connectionRequest = None,
connectionResponse = None,
metaRetries = maxRetries,
metaNextRetry = Some(Instant.now()),
metaLastFailure = None,
)
)
Expand Down Expand Up @@ -295,10 +299,14 @@ private class ConnectionServiceImpl(
} yield record
}

def reportProcessingFailure(recordId: UUID, failReason: Option[String]): IO[ConnectionServiceError, Int] =
def reportProcessingFailure(recordId: UUID, failReason: Option[String]): IO[ConnectionServiceError, Unit] =
connectionRepository
.updateAfterFail(recordId, failReason)
.mapError(RepositoryError.apply)
.flatMap {
case 1 => ZIO.unit
case n => ZIO.fail(UnexpectedError(s"Invalid number of records updated: $n"))
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package io.iohk.atala.connect.core.repository

import io.iohk.atala.connect.core.model.ConnectionRecord
import io.iohk.atala.connect.core.model.ConnectionRecord._
import io.iohk.atala.connect.core.model.error.ConnectionRepositoryError._
import io.iohk.atala.connect.core.model.ConnectionRecord.*
import io.iohk.atala.connect.core.model.error.ConnectionRepositoryError.*
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.connection.ConnectionRequest
import io.iohk.atala.mercury.protocol.connection.ConnectionResponse
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
import io.iohk.atala.mercury.protocol.invitation.v2.Invitation
import zio.Cause
import zio.Exit
import zio.Task
import zio.ZIO
import zio.test.Assertion._
import zio.test._
import zio.test.*
import zio.test.Assertion.*
import zio.{Cause, Exit, Task, ZIO}

import java.time.Instant
import java.util.UUID
Expand All @@ -23,7 +19,7 @@ object ConnectionRepositorySpecSuite {

private def connectionRecord = ConnectionRecord(
UUID.randomUUID,
Instant.ofEpochSecond(Instant.now.getEpochSecond()),
Instant.ofEpochSecond(Instant.now.getEpochSecond),
None,
None,
None,
Expand All @@ -38,6 +34,7 @@ object ConnectionRepositorySpecSuite {
None,
None,
maxRetries,
Some(Instant.now),
None
)

Expand Down Expand Up @@ -99,7 +96,7 @@ object ConnectionRepositorySpecSuite {
bRecord = connectionRecord
_ <- repo.createConnectionRecord(aRecord)
_ <- repo.createConnectionRecord(bRecord)
records <- repo.getConnectionRecords()
records <- repo.getConnectionRecords
} yield {
assertTrue(records.size == 2) &&
assertTrue(records.contains(aRecord)) &&
Expand Down Expand Up @@ -127,8 +124,14 @@ object ConnectionRepositorySpecSuite {
ProtocolState.ConnectionResponsePending,
1
)
invitationGeneratedRecords <- repo.getConnectionRecordsByStates(ProtocolState.InvitationGenerated)
invitationGeneratedRecords <- repo.getConnectionRecordsByStates(
ignoreWithZeroRetries = true,
limit = 10,
ProtocolState.InvitationGenerated
)
otherRecords <- repo.getConnectionRecordsByStates(
ignoreWithZeroRetries = true,
limit = 10,
ProtocolState.ConnectionRequestReceived,
ProtocolState.ConnectionResponsePending
)
Expand All @@ -149,11 +152,29 @@ object ConnectionRepositorySpecSuite {
_ <- repo.createConnectionRecord(aRecord)
_ <- repo.createConnectionRecord(bRecord)
_ <- repo.createConnectionRecord(cRecord)
records <- repo.getConnectionRecordsByStates()
records <- repo.getConnectionRecordsByStates(ignoreWithZeroRetries = true, limit = 10)
} yield {
assertTrue(records.isEmpty)
}
},
test("getConnectionRecordsByStates returns an a subset of records when limit is specified") {
for {
repo <- ZIO.service[ConnectionRepository[Task]]
aRecord = connectionRecord
bRecord = connectionRecord
cRecord = connectionRecord
_ <- repo.createConnectionRecord(aRecord)
_ <- repo.createConnectionRecord(bRecord)
_ <- repo.createConnectionRecord(cRecord)
records <- repo.getConnectionRecordsByStates(
ignoreWithZeroRetries = true,
limit = 2,
ProtocolState.InvitationGenerated
)
} yield {
assertTrue(records.size == 2)
}
},
test("deleteRecord deletes an existing record") {
for {
repo <- ZIO.service[ConnectionRepository[Task]]
Expand All @@ -162,7 +183,7 @@ object ConnectionRepositorySpecSuite {
_ <- repo.createConnectionRecord(aRecord)
_ <- repo.createConnectionRecord(bRecord)
count <- repo.deleteConnectionRecord(aRecord.id)
records <- repo.getConnectionRecords()
records <- repo.getConnectionRecords
} yield {
assertTrue(count == 1) &&
assertTrue(records.size == 1) &&
Expand All @@ -177,7 +198,7 @@ object ConnectionRepositorySpecSuite {
_ <- repo.createConnectionRecord(aRecord)
_ <- repo.createConnectionRecord(bRecord)
count <- repo.deleteConnectionRecord(UUID.randomUUID)
records <- repo.getConnectionRecords()
records <- repo.getConnectionRecords
} yield {
assertTrue(count == 0) &&
assertTrue(records.size == 2) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE public.connection_records
ADD meta_next_retry TIMESTAMP WITH TIME ZONE;
Loading

0 comments on commit 836c5c8

Please sign in to comment.