From a5a78fa1824c2b801224a0759f397e635f189f6e Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Mon, 18 Sep 2023 09:56:44 +0100 Subject: [PATCH] feat: add MediatorBuildInfo & /did and /version endpoints (#120) Add MediatorBuildInfo & /did and /version endpoints Signed-off-by: Fabio Pinheiro Signed-off-by: mineme0110 --- build.sbt | 5 +++-- .../io/iohk/atala/mediator/app/MediatorAgent.scala | 9 ++++++--- .../scala/io/iohk/atala/mediator/MediatorInfo.scala | 13 +++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/build.sbt b/build.sbt index 77fa6b88..0a4f2951 100644 --- a/build.sbt +++ b/build.sbt @@ -169,13 +169,13 @@ lazy val scalaJSBundlerConfigure: Project => Project = lazy val buildInfoConfigure: Project => Project = _.enablePlugins(BuildInfoPlugin) .settings( buildInfoPackage := "io.iohk.atala.mediator", - // buildInfoObject := "BuildInfo", + buildInfoObject := "MediatorBuildInfo", buildInfoKeys := Seq[BuildInfoKey]( name, version, scalaVersion, sbtVersion, - BuildInfoKey.action("buildTime") { System.currentTimeMillis }, // re-computed each time at compile + // BuildInfoKey.action("buildTime") { System.currentTimeMillis }, // re-computed each time at compile ), ) @@ -194,6 +194,7 @@ lazy val httpUtils = crossProject(JSPlatform, JVMPlatform) // project lazy val mediator = project .in(file("mediator")) + .configure(buildInfoConfigure) .settings(publish / skip := true) .settings( // FIX TODO (maybe the next version of the library will hide this compilation error) diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala index 3b38b278..77c324bf 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala @@ -191,11 +191,15 @@ object MediatorAgent { def didCommApp = { Http.collectZIO[Request] { case req @ Method.GET -> Root / "headers" => - println(req.headers.size) val data = req.headers.toSeq.map(e => (e.headerName, e.renderedValue)) ZIO.succeed(Response.text("HEADERS:\n" + data.mkString("\n") + "\nRemoteAddress:" + req.remoteAddress)).debug case req @ Method.GET -> Root / "health" => ZIO.succeed(Response.ok) - + case Method.GET -> Root / "version" => ZIO.succeed(Response.text(MediatorBuildInfo.version)) + case Method.GET -> Root / "did" => + for { + agent <- ZIO.service[MediatorAgent] + ret <- ZIO.succeed(Response.text(agent.id.string)) + } yield (ret) case Method.GET -> Root / "invitation" => for { agent <- ZIO.service[MediatorAgent] @@ -208,7 +212,6 @@ object MediatorAgent { ) _ <- ZIO.log("New mediate invitation MsgID: " + invitation.id.value) ret <- ZIO.succeed(Response.json(invitation.toPlaintextMessage.toJson)) - } yield (ret) case Method.GET -> Root / "invitationOOB" => for { diff --git a/webapp/src/main/scala/io/iohk/atala/mediator/MediatorInfo.scala b/webapp/src/main/scala/io/iohk/atala/mediator/MediatorInfo.scala index 7fea6385..9bf77dd9 100644 --- a/webapp/src/main/scala/io/iohk/atala/mediator/MediatorInfo.scala +++ b/webapp/src/main/scala/io/iohk/atala/mediator/MediatorInfo.scala @@ -30,16 +30,25 @@ object MediatorInfo { def apply(): HtmlElement = // rootElement div( h1("Invite for the DID Comm Mediator:"), + div( + h3("Mediator identity (DID):"), + code(invitation.from.value), + ), h3("Plaintext out of band invitation:"), p(a(href := qrCodeData, target := "_blank", code(qrCodeData))), // FIXME make it a link to the mobile app pre(code(invitation.toPlaintextMessage.toJsonPretty)), - pre( + p( "To facilitate the integration with other systems you can get the plain text invitation and the out-of-band invitation on the following endpoints:", - " '/invitation' and '/invitationOOB'" + " '/invitation' and '/invitationOOB'.", + "You can also get the DID of the mediator in '/did' or the build version (of the backend) in '/version'." ), divQRCode, h3("Signed out of band invitation:"), code("TODO"), + footerTag( + textAlign.center, + p("Mediator Version: ", code("'" + MediatorBuildInfo.version + "'")) + ), ) }