Skip to content

Commit

Permalink
feat: add MediatorBuildInfo & /did and /version endpoints (#120)
Browse files Browse the repository at this point in the history
Add MediatorBuildInfo & /did and /version endpoints

Signed-off-by: Fabio Pinheiro <[email protected]>
Signed-off-by: mineme0110 <[email protected]>
  • Loading branch information
FabioPinheiro authored and mineme0110 committed May 1, 2024
1 parent 350d69a commit a5a78fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
)

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions webapp/src/main/scala/io/iohk/atala/mediator/MediatorInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'"))
),
)

}

0 comments on commit a5a78fa

Please sign in to comment.