Skip to content

Commit eee0f7b

Browse files
authored
ETCM-480 Add buildinfo endpoint (#860)
1 parent 07ce3f6 commit eee0f7b

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

build.sbt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ enablePlugins(JDKPackagerPlugin, JavaAppPackaging, SolidityPlugin)
22

33
import scala.sys.process.Process
44
import NativePackagerHelper._
5+
import com.typesafe.sbt.SbtGit.GitKeys._
56

67
// Necessary for the nix build, please do not remove.
78
val nixBuild = sys.props.isDefinedAt("nix")
@@ -148,8 +149,20 @@ lazy val node = {
148149
.enablePlugins(BuildInfoPlugin)
149150
.dependsOn(bytes, crypto, rlp)
150151
.settings(
151-
buildInfoKeys := Seq[BuildInfoKey](name, version, git.gitHeadCommit),
152-
buildInfoPackage := "io.iohk.ethereum.utils"
152+
buildInfoKeys := BuildInfoKey.ofN(
153+
name,
154+
version,
155+
scalaVersion,
156+
sbtVersion,
157+
gitHeadCommit,
158+
gitCurrentBranch,
159+
gitCurrentTags,
160+
gitDescribedVersion,
161+
gitUncommittedChanges,
162+
libraryDependencies in Compile
163+
),
164+
buildInfoPackage := "io.iohk.ethereum.utils",
165+
buildInfoOptions in Compile += BuildInfoOption.ToMap
153166
)
154167
.settings(commonSettings("mantis"): _*)
155168
.settings(

src/main/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServer.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.iohk.ethereum.jsonrpc.server.http
22

33
import java.security.SecureRandom
4-
54
import akka.actor.ActorSystem
65
import akka.http.scaladsl.model._
76
import akka.http.scaladsl.server.Directives._
@@ -18,12 +17,12 @@ import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers
1817
import io.iohk.ethereum.jsonrpc.server.controllers.JsonRpcBaseController
1918
import io.iohk.ethereum.jsonrpc.server.http.JsonRpcHttpServer.JsonRpcHttpServerConfig
2019
import io.iohk.ethereum.security.SSLError
21-
import io.iohk.ethereum.utils.{ConfigUtils, Logger}
20+
import io.iohk.ethereum.utils.{BuildInfo, ConfigUtils, Logger}
2221
import javax.net.ssl.SSLContext
2322
import monix.eval.Task
2423
import monix.execution.Scheduler.Implicits.global
24+
import org.json4s.native.Serialization
2525
import org.json4s.{DefaultFormats, JInt, native}
26-
2726
import scala.concurrent.duration.{FiniteDuration, _}
2827

2928
trait JsonRpcHttpServer extends Json4sSupport with RateLimit with Logger {
@@ -55,6 +54,8 @@ trait JsonRpcHttpServer extends Json4sSupport with RateLimit with Logger {
5554
val route: Route = cors(corsSettings) {
5655
(path("healthcheck") & pathEndOrSingleSlash & get) {
5756
handleHealthcheck()
57+
} ~ (path("buildinfo") & pathEndOrSingleSlash & get) {
58+
handleBuildInfo()
5859
} ~ (pathEndOrSingleSlash & post) {
5960
(extractClientIP & entity(as[JsonRpcRequest])) { (clientAddress, request) =>
6061
handleRequest(clientAddress, request)
@@ -106,8 +107,14 @@ trait JsonRpcHttpServer extends Json4sSupport with RateLimit with Logger {
106107
complete(httpResponseF.runToFuture)
107108
}
108109

109-
private def handleRequest(request: JsonRpcRequest) = {
110-
complete(jsonRpcController.handleRequest(request).runToFuture)
110+
private def handleBuildInfo(): StandardRoute = {
111+
val buildInfo = Serialization.writePretty(BuildInfo.toMap)(DefaultFormats)
112+
complete(
113+
HttpResponse(
114+
status = StatusCodes.OK,
115+
entity = HttpEntity(ContentTypes.`application/json`, buildInfo)
116+
)
117+
)
111118
}
112119

113120
private def handleBatchRequest(requests: Seq[JsonRpcRequest]) = {

src/test/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServerSpec.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import ch.megard.akka.http.cors.scaladsl.model.HttpOriginMatcher
1313
import io.iohk.ethereum.jsonrpc.server.http.JsonRpcHttpServer.{JsonRpcHttpServerConfig, RateLimitConfig}
1414
import io.iohk.ethereum.jsonrpc.{JsonRpcController, JsonRpcHealthChecker, JsonRpcResponse}
1515
import monix.eval.Task
16-
import org.json4s.JsonAST.{JInt, JString}
16+
import org.json4s.JsonAST.{JInt, JNothing, JString}
1717
import org.scalamock.scalatest.MockFactory
1818
import org.scalatest.flatspec.AnyFlatSpec
1919
import org.scalatest.matchers.should.Matchers
2020
import akka.http.scaladsl.model.headers._
2121
import io.iohk.ethereum.healthcheck.{HealthcheckResponse, HealthcheckResult}
22-
import io.iohk.ethereum.utils.Logger
22+
import io.iohk.ethereum.utils.{BuildInfo, Logger}
2323
import io.iohk.ethereum.jsonrpc.server.controllers.JsonRpcBaseController
24+
import org.json4s.{DefaultFormats, Extraction}
25+
import org.json4s.native.JsonMethods
2426
import scala.concurrent.duration.FiniteDuration
2527

2628
class JsonRpcHttpServerSpec extends AnyFlatSpec with Matchers with ScalatestRouteTest {
@@ -45,6 +47,22 @@ class JsonRpcHttpServerSpec extends AnyFlatSpec with Matchers with ScalatestRout
4547
}
4648
}
4749

50+
it should "respond to buildinfo" in new TestSetup {
51+
val buildInfoRequest = HttpRequest(HttpMethods.GET, uri = "/buildinfo")
52+
53+
buildInfoRequest ~> Route.seal(mockJsonRpcHttpServer.route) ~> check {
54+
status shouldEqual StatusCodes.OK
55+
56+
val expected = Extraction.decompose(BuildInfo.toMap)(DefaultFormats)
57+
val jsonResponse = JsonMethods.parse(responseAs[String])
58+
val diff = expected.diff(jsonResponse)
59+
60+
diff.added shouldEqual JNothing
61+
diff.changed shouldEqual JNothing
62+
diff.deleted shouldEqual JNothing
63+
}
64+
}
65+
4866
it should "pass valid json request to controller" in new TestSetup {
4967
(mockJsonRpcController.handleRequest _)
5068
.expects(*)

src/universal/conf/faucet.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ mantis {
144144
apis = "faucet"
145145
}
146146
}
147-
}
147+
}

0 commit comments

Comments
 (0)