/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/nccloud/common/0.0.1/http4s_0_15 */ package de.nccloud.common.v0.server import org.http4s.dsl._ import de.nccloud.common.v0.models.json._ private[server] object Matchers { implicit lazy val queryParamDecodeBigDecimal: org.http4s.QueryParamDecoder[BigDecimal] = org.http4s.QueryParamDecoder.fromUnsafeCast[BigDecimal](p => BigDecimal(p.value))("BigDecimal") implicit lazy val queryParamDecodeInstant: org.http4s.QueryParamDecoder[_root_.java.time.Instant] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.Instant](p => _root_.java.time.OffsetDateTime.parse(p.value).toInstant)("_root_.java.time.Instant") implicit lazy val queryParamDecodeLocalDate: org.http4s.QueryParamDecoder[_root_.java.time.LocalDate] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.LocalDate](p => _root_.java.time.LocalDate.parse(p.value))("_root_.java.time.LocalDate") implicit lazy val queryParamDecodeUUID: org.http4s.QueryParamDecoder[_root_.java.util.UUID] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.util.UUID](p => _root_.java.util.UUID.fromString(p.value))("_root_.java.util.UUID") object ApiVersion { val ApiVersionMajor = { "X-Apidoc-Version-Major".ci } def apply(req: org.http4s.Message): Boolean = req.headers.get(ApiVersionMajor) match { case Some(v) if v.value == "0" => true case _ => false } } } trait HealthCheckRoutes { import Matchers._ implicit def circeJsonDecoder[A](implicit decoder: _root_.io.circe.Decoder[A]) = org.http4s.circe.jsonOf[A] implicit def circeJsonEncoder[A](implicit encoder: _root_.io.circe.Encoder[A]) = org.http4s.circe.jsonEncoderOf[A] sealed trait GetHealthcheckResponse object GetHealthcheckResponse { case class HTTP200(value: de.nccloud.common.v0.models.HealthCheck, headers: Seq[org.http4s.Header] = Nil) extends GetHealthcheckResponse case class UndocumentedResponse(response: scalaz.concurrent.Task[org.http4s.Response]) extends GetHealthcheckResponse } def getHealthcheck( _req: org.http4s.Request ): scalaz.concurrent.Task[GetHealthcheckResponse] sealed trait GetProbeAndReadyResponse object GetProbeAndReadyResponse { case class HTTP200(headers: Seq[org.http4s.Header] = Nil) extends GetProbeAndReadyResponse case class HTTP400(headers: Seq[org.http4s.Header] = Nil) extends GetProbeAndReadyResponse case class UndocumentedResponse(response: scalaz.concurrent.Task[org.http4s.Response]) extends GetProbeAndReadyResponse } def getProbeAndReady( _req: org.http4s.Request ): scalaz.concurrent.Task[GetProbeAndReadyResponse] sealed trait GetProbeAndLiveResponse object GetProbeAndLiveResponse { case class HTTP200(headers: Seq[org.http4s.Header] = Nil) extends GetProbeAndLiveResponse case class UndocumentedResponse(response: scalaz.concurrent.Task[org.http4s.Response]) extends GetProbeAndLiveResponse } def getProbeAndLive( _req: org.http4s.Request ): scalaz.concurrent.Task[GetProbeAndLiveResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ GET -> Root / "_internal_" / "healthcheck" if apiVersionMatch(_req) => getHealthcheck(_req).flatMap { case GetHealthcheckResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case GetHealthcheckResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "_internal_" / "healthcheck" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ GET -> Root / "_internal_" / "probe" / "ready" if apiVersionMatch(_req) => getProbeAndReady(_req).flatMap { case GetProbeAndReadyResponse.HTTP200(headers) => Ok().putHeaders(headers: _*) case GetProbeAndReadyResponse.HTTP400(headers) => BadRequest().putHeaders(headers: _*) case GetProbeAndReadyResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "_internal_" / "probe" / "ready" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ GET -> Root / "_internal_" / "probe" / "live" if apiVersionMatch(_req) => getProbeAndLive(_req).flatMap { case GetProbeAndLiveResponse.HTTP200(headers) => Ok().putHeaders(headers: _*) case GetProbeAndLiveResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "_internal_" / "probe" / "live" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } } trait ServiceInfoRoutes { import Matchers._ implicit def circeJsonDecoder[A](implicit decoder: _root_.io.circe.Decoder[A]) = org.http4s.circe.jsonOf[A] implicit def circeJsonEncoder[A](implicit encoder: _root_.io.circe.Encoder[A]) = org.http4s.circe.jsonEncoderOf[A] sealed trait GetServiceResponse object GetServiceResponse { case class HTTP200(value: de.nccloud.common.v0.models.ServiceInfo, headers: Seq[org.http4s.Header] = Nil) extends GetServiceResponse case class UndocumentedResponse(response: scalaz.concurrent.Task[org.http4s.Response]) extends GetServiceResponse } def getService( _req: org.http4s.Request ): scalaz.concurrent.Task[GetServiceResponse] def apiVersionMatch(req: org.http4s.Message): Boolean = ApiVersion(req) def service() = org.http4s.HttpService { case _req @ GET -> Root / "_internal_" / "service" if apiVersionMatch(_req) => getService(_req).flatMap { case GetServiceResponse.HTTP200(value, headers) => Ok(value).putHeaders(headers: _*) case GetServiceResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "_internal_" / "service" if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }