Skip to content

Commit

Permalink
Adding a /version endpoint (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek authored May 28, 2024
1 parent 68094d9 commit 9127807
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ lazy val http4sCommons = project
Dependencies.http4sServer ++
Dependencies.tapirHttp4sServer
)
.dependsOn(
commons % "compile->compile;test->test",
http4sBorer % "compile->compile;test->test"
)

lazy val redisClient = project
.in(file("modules/redis-client"))
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
container = pkgs.mkShellNoCC (queueNameConfig
// {
RS_SOLR_HOST = "rsdev-cnt";
RS_SOLR_URL = "http://rsdev-cnt:8983/solr";
RS_SOLR_URL = "http://rsdev-cnt:8983";
RS_SOLR_CORE = "rsdev-test";
RS_REDIS_HOST = "rsdev-cnt";
RS_REDIS_PORT = "6379";
Expand All @@ -102,7 +102,7 @@
// {
RS_SOLR_HOST = "localhost";
RS_SOLR_PORT = "18983";
RS_SOLR_URL = "http://localhost:18983/solr";
RS_SOLR_URL = "http://localhost:18983";
RS_SOLR_CORE = "rsdev-test";
RS_REDIS_HOST = "localhost";
RS_REDIS_PORT = "16379";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.search.common

import io.bullet.borer.Decoder
import io.bullet.borer.Encoder
import io.bullet.borer.derivation.MapBasedCodecs

final case class CurrentVersion(
name: String,
version: String,
headCommit: String,
describedVersion: String
)

object CurrentVersion:

given Encoder[CurrentVersion] = MapBasedCodecs.deriveEncoder
given Decoder[CurrentVersion] = MapBasedCodecs.deriveDecoder

lazy val get: CurrentVersion = CurrentVersion(
name = "renku-search",
version = io.renku.search.BuildInfo.version,
headCommit = io.renku.search.BuildInfo.gitHeadCommit.getOrElse(""),
describedVersion = io.renku.search.BuildInfo.gitDescribedVersion.getOrElse("")
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@ import cats.syntax.all.*
import org.http4s.HttpRoutes
import sttp.tapir.*
import sttp.tapir.server.http4s.Http4sServerInterpreter
import io.renku.search.common.CurrentVersion
import io.renku.search.http.borer.TapirBorerJson

object OperationRoutes {
object OperationRoutes extends TapirBorerJson {
private def pingEndpoint[F[_]: Async] =
endpoint.get
.in("ping")
.out(stringBody)
.description("Ping")
.serverLogic[F](_ => "pong".asRight[Unit].pure[F])


private given Schema[CurrentVersion] = Schema.derived

private def versionEndpoint[F[_]: Async] =
endpoint.get.in("version")
.out(borerJsonBody[CurrentVersion])
.description("Return version information")
.serverLogicSuccess[F](_ => CurrentVersion.get.pure[F])

def apply[F[_]: Async]: HttpRoutes[F] =
Http4sServerInterpreter[F]().toRoutes(List(pingEndpoint))
Http4sServerInterpreter[F]().toRoutes(List(pingEndpoint, versionEndpoint))
}

0 comments on commit 9127807

Please sign in to comment.