-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apollo): add schema registry to the agent using Tapir library. A…
…TL-1334 (#94) * [ATL-2014] build: External registry set to domain name * feat(pollux): implement schema-registry in-memory using Tapir Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
328c6a9
commit b3cf828
Showing
17 changed files
with
434 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=1.7.1 | ||
sbt.version=1.7.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/ZHttpEndpoints.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.iohk.atala.agent.server.http | ||
|
||
import zio.{Task, ZIO, ZLayer, URIO} | ||
import io.iohk.atala.pollux.schema.SchemaRegistryServerEndpoints | ||
import io.iohk.atala.pollux.service.SchemaRegistryService | ||
import sttp.tapir.redoc.bundle.RedocInterpreter | ||
import sttp.tapir.swagger.bundle.SwaggerInterpreter | ||
//import sttp.tapir.ztapir.{RichZServerEndpoint, ZServerEndpoint} | ||
import sttp.tapir.redoc.RedocUIOptions | ||
import sttp.tapir.server.ServerEndpoint | ||
import scala.concurrent.Future | ||
|
||
object ZHttpEndpoints { | ||
def swaggerEndpoints[F[_]](apiEndpoints: List[ServerEndpoint[Any, F]]): List[ServerEndpoint[Any, F]] = | ||
SwaggerInterpreter().fromServerEndpoints[F](apiEndpoints, "Prism Agent", "1.0.0") | ||
|
||
def redocEndpoints[F[_]](apiEndpoints: List[ServerEndpoint[Any, F]]): List[ServerEndpoint[Any, F]] = | ||
RedocInterpreter(redocUIOptions = RedocUIOptions.default.copy(pathPrefix = List("redoc"))) | ||
.fromServerEndpoints[F](apiEndpoints, title = "Prism Agent", version = "1.0.0") | ||
|
||
def withDocumentations[F[_]](apiEndpoints: List[ServerEndpoint[Any, F]]): List[ServerEndpoint[Any, F]] = { | ||
apiEndpoints ++ swaggerEndpoints[F](apiEndpoints) ++ redocEndpoints[F](apiEndpoints) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/ZHttpServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.iohk.atala.agent.server.http | ||
|
||
import cats.implicits.* | ||
import io.iohk.atala.agent.server.http.ZHttpEndpoints | ||
import io.iohk.atala.pollux.schema.SchemaRegistryServerEndpoints | ||
import io.iohk.atala.pollux.service.{SchemaRegistryService, SchemaRegistryServiceInMemory} | ||
import org.http4s.* | ||
import org.http4s.blaze.server.BlazeServerBuilder | ||
import org.http4s.server.Router | ||
import org.slf4j.LoggerFactory | ||
import sttp.model.StatusCode | ||
import sttp.tapir.server.ServerEndpoint | ||
import sttp.tapir.server.http4s.ztapir.ZHttp4sServerInterpreter | ||
import sttp.tapir.server.interceptor.log.DefaultServerLog | ||
import sttp.tapir.ztapir.ZServerEndpoint | ||
import zhttp.http.HttpApp | ||
import zhttp.service.server.ServerChannelFactory | ||
import zhttp.service.{EventLoopGroup, Server} | ||
import zio.interop.catz.* | ||
import zio.* | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
object ZHttp4sBlazeServer { | ||
def start( | ||
endpoints: List[ZServerEndpoint[Any, Any]], | ||
port: Int | ||
): Task[ExitCode] = { | ||
val http4sEndpoints: HttpRoutes[Task] = | ||
ZHttp4sServerInterpreter().from(endpoints).toRoutes | ||
|
||
val serve: Task[Unit] = | ||
ZIO.executor.flatMap(executor => | ||
BlazeServerBuilder[Task] | ||
.withExecutionContext(executor.asExecutionContext) | ||
.bindHttp(port, "0.0.0.0") | ||
.withHttpApp(Router("/" -> http4sEndpoints).orNotFound) | ||
.serve | ||
.compile | ||
.drain | ||
) | ||
|
||
serve.exitCode | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
prism-agent/service/server/src/main/scala/io/iohk/atala/api/http/FailureResponse.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.iohk.atala.api.http | ||
|
||
import sttp.model.StatusCode | ||
import sttp.tapir.EndpointOutput.OneOf | ||
import sttp.tapir.generic.auto.* | ||
import sttp.tapir.json.zio.jsonBody | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder} | ||
|
||
sealed trait FailureResponse | ||
|
||
case class NotFoundResponse(msg: String) extends FailureResponse | ||
|
||
object NotFoundResponse { | ||
given encoder: zio.json.JsonEncoder[NotFoundResponse] = DeriveJsonEncoder.gen[NotFoundResponse] | ||
given decoder: zio.json.JsonDecoder[NotFoundResponse] = DeriveJsonDecoder.gen[NotFoundResponse] | ||
} | ||
|
||
case class BadRequest(msg: String, errors: List[String] = List.empty) extends FailureResponse | ||
|
||
object BadRequest { | ||
given encoder: zio.json.JsonEncoder[BadRequest] = DeriveJsonEncoder.gen[BadRequest] | ||
given decoder: zio.json.JsonDecoder[BadRequest] = DeriveJsonDecoder.gen[BadRequest] | ||
} | ||
|
||
case class InternalServerError(msg: String) extends FailureResponse | ||
|
||
object InternalServerError { | ||
given encoder: zio.json.JsonEncoder[InternalServerError] = DeriveJsonEncoder.gen[InternalServerError] | ||
given decoder: zio.json.JsonDecoder[InternalServerError] = DeriveJsonDecoder.gen[InternalServerError] | ||
} | ||
|
||
//An RFC-7807 compliant data structure for reporting errors to the client | ||
case class ErrorResponse(`type`: String, title: String, status: Int, instance: String, details: Option[String]) | ||
extends FailureResponse | ||
|
||
object ErrorResponse { | ||
given encoder: zio.json.JsonEncoder[ErrorResponse] = DeriveJsonEncoder.gen[ErrorResponse] | ||
given decoder: zio.json.JsonDecoder[ErrorResponse] = DeriveJsonDecoder.gen[ErrorResponse] | ||
} |
66 changes: 66 additions & 0 deletions
66
prism-agent/service/server/src/main/scala/io/iohk/atala/pollux/schema/Models.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.iohk.atala.pollux.schema | ||
|
||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder} | ||
|
||
import java.time.ZonedDateTime | ||
import java.util.UUID | ||
|
||
case class VerifiableCredentialsSchemaInput( | ||
id: Option[UUID], | ||
name: String, | ||
version: String, | ||
description: Option[String], | ||
attributes: List[String], | ||
authored: Option[ZonedDateTime], | ||
tags: List[String] | ||
) | ||
object VerifiableCredentialsSchemaInput { | ||
given encoder: zio.json.JsonEncoder[VerifiableCredentialsSchemaInput] = | ||
DeriveJsonEncoder.gen[VerifiableCredentialsSchemaInput] | ||
given decoder: zio.json.JsonDecoder[VerifiableCredentialsSchemaInput] = | ||
DeriveJsonDecoder.gen[VerifiableCredentialsSchemaInput] | ||
} | ||
|
||
case class VerifiableCredentialsSchema( | ||
id: UUID, | ||
name: String, | ||
version: String, | ||
tags: List[String], | ||
description: Option[String], | ||
attributes: List[String], | ||
author: String, | ||
authored: ZonedDateTime, | ||
proof: Option[Proof] | ||
) | ||
|
||
object VerifiableCredentialsSchema { | ||
def apply(in: VerifiableCredentialsSchemaInput): VerifiableCredentialsSchema = | ||
VerifiableCredentialsSchema( | ||
id = in.id.getOrElse(UUID.randomUUID()), | ||
name = in.name, | ||
version = in.version, | ||
tags = in.tags, | ||
description = in.description, | ||
attributes = in.attributes, | ||
author = "Prism Agent", | ||
authored = in.authored.getOrElse(ZonedDateTime.now()), | ||
proof = None | ||
) | ||
|
||
given encoder: zio.json.JsonEncoder[VerifiableCredentialsSchema] = DeriveJsonEncoder.gen[VerifiableCredentialsSchema] | ||
given decoder: zio.json.JsonDecoder[VerifiableCredentialsSchema] = DeriveJsonDecoder.gen[VerifiableCredentialsSchema] | ||
} | ||
|
||
case class Proof( | ||
`type`: String, | ||
created: ZonedDateTime, | ||
verificationMethod: String, | ||
proofPurpose: String, | ||
proofValue: String, | ||
domain: Option[String] | ||
) | ||
|
||
object Proof { | ||
given encoder: zio.json.JsonEncoder[Proof] = DeriveJsonEncoder.gen[Proof] | ||
given decoder: zio.json.JsonDecoder[Proof] = DeriveJsonDecoder.gen[Proof] | ||
} |
Oops, something went wrong.