From cd2808cce34de112c3d731402713806a0c5fb15a Mon Sep 17 00:00:00 2001 From: Anton Parkhomenko Date: Fri, 30 Jul 2021 17:58:06 +0300 Subject: [PATCH 1/3] http4s: pass apikey for schema-list method (close #166) --- .../registries/Http4sRegistryLookup.scala | 70 +++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/modules/http4s/src/main/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookup.scala b/modules/http4s/src/main/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookup.scala index d9de66fc..78efa126 100644 --- a/modules/http4s/src/main/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookup.scala +++ b/modules/http4s/src/main/scala/com.snowplowanalytics.iglu/client/resolver/registries/Http4sRegistryLookup.scala @@ -12,16 +12,20 @@ */ package com.snowplowanalytics.iglu.client.resolver.registries +import scala.util.control.NonFatal + import cats.implicits._ import cats.data.EitherT import cats.effect.Sync + import io.circe.Json + +import org.http4s.{EntityDecoder, Header, Headers, Method, Request, Status, Uri} import org.http4s.circe._ import org.http4s.client.{Client => HttpClient} -import org.http4s.{EntityDecoder, Header, Headers, Request, Uri} + import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaList} import com.snowplowanalytics.iglu.core.circe.CirceIgluCodecs._ -import org.http4s.Method.GET object Http4sRegistryLookup { @@ -57,12 +61,10 @@ object Http4sRegistryLookup { uri <- EitherT.fromEither[F](toPath(http, key)) headers = http.apikey.fold[Headers](Headers.empty)(apikey => Headers.of(Header("apikey", apikey))) - request = Request[F](method = GET, uri = uri, headers = headers) - json <- EitherT(Sync[F].attempt(client.expect[Json](request))).leftMap[RegistryError] { e => - val error = s"Unexpected exception fetching: $e" - RegistryError.RepoFailure(error) - } - } yield json + response = + runRequest[F, Json](client, Request[F](method = Method.GET, uri = uri, headers = headers)) + result <- EitherT(response) + } yield result def httpList[F[_]: Sync]( client: HttpClient[F], @@ -73,11 +75,14 @@ object Http4sRegistryLookup { ): EitherT[F, RegistryError, SchemaList] = for { uri <- EitherT.fromEither[F](toSubpath(http, vendor, name, model)) - sl <- EitherT(Sync[F].attempt(client.expect[SchemaList](uri))).leftMap[RegistryError] { e => - val error = s"Unexpected exception listing: $e" - RegistryError.RepoFailure(error) - } - } yield sl + headers = + http.apikey.fold[Headers](Headers.empty)(apikey => Headers.of(Header("apikey", apikey))) + response = runRequest[F, SchemaList]( + client, + Request[F](method = Method.GET, uri = uri, headers = headers) + ) + result <- EitherT(response) + } yield result def toPath(cxn: Registry.HttpConnection, key: SchemaKey): Either[RegistryError, Uri] = Uri @@ -94,5 +99,44 @@ object Http4sRegistryLookup { .fromString(s"${cxn.uri.toString.stripSuffix("/")}/schemas/$vendor/$name/jsonschema/$model") .leftMap(e => RegistryError.ClientFailure(e.message)) + def runRequest[F[_]: Sync, A: EntityDecoder[F, *]]( + client: HttpClient[F], + req: Request[F] + ): F[Either[RegistryError, A]] = { + val responseResult = client.run(req).use[F, Either[RegistryError, A]] { + case Status.Successful(response) => + response + .as[A] + .map(_.asRight[RegistryError]) + .handleError { + case NonFatal(exception) => + RegistryError.ClientFailure(s"Could not decode server response. $exception").asLeft[A] + } + case Status.ClientError(response) if response.status.code == 404 => + (RegistryError.NotFound: RegistryError).asLeft[A].pure[F] + case Status.ServerError(response) => + response.bodyText.compile.string.map { body => + val error = s"Unexpected server response: $body" + RegistryError.RepoFailure(error).asLeft + } + case Status.ClientError(response) => + response.bodyText.compile.string.map { body => + val error = s"Unexpected server response: $body" + RegistryError.ClientFailure(error).asLeft + } + case response => + response.bodyText.compile.string.map { body => + val error = s"Unexpected response: $body" + RegistryError.ClientFailure(error).asLeft + } + } + + responseResult.recover { + case NonFatal(exception) => + val error = Option(exception.getMessage).getOrElse(exception.toString) + RegistryError.ClientFailure(error).asLeft + } + } + implicit def schemaListDecoder[F[_]: Sync]: EntityDecoder[F, SchemaList] = jsonOf[F, SchemaList] } From 11008de8e4f8377682b2e7af65bf929e1f7d35f5 Mon Sep 17 00:00:00 2001 From: Anton Parkhomenko Date: Thu, 5 Aug 2021 17:27:04 +0300 Subject: [PATCH 2/3] Fix ScalaDoc publishing (close #168) --- .github/workflows/ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8617666b..aedebcc6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,3 +46,22 @@ jobs: PGP_SECRET: ${{ secrets.SONA_PGP_SECRET }} SONATYPE_USERNAME: ${{ secrets.SONA_USER }} SONATYPE_PASSWORD: ${{ secrets.SONA_PASS }} + - name: Publish ScalaDoc + run: | + project_version=$(sbt version -Dsbt.log.noformat=true | perl -ne 'print "$1\n" if /info.*(\d+\.\d+\.\d+[^\r\n]*)/' | tail -n 1 | tr -d '\n') + if [[ "${{ github.ref }}" = "refs/tags/${project_version}" ]] + then + sbt "project core" makeSite + echo Publishing Scaladoc + git fetch + git checkout gh-pages + cp -r modules/core/target/site/* . + git config user.name "GitHub Actions" + git config user.email "<>" + git add $project_version + git commit -m "Added Scaladoc for $project_version" + git push origin gh-pages + else + echo "${{ github.ref }} does not match project version $project_version => not publishing" + exit 1 + fi From 1c1f0ab93471cb85605c8fc40645e9b64e1c14bb Mon Sep 17 00:00:00 2001 From: Anton Parkhomenko Date: Fri, 30 Jul 2021 18:18:52 +0300 Subject: [PATCH 3/3] Prepare for 1.1.1 release --- CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 86d1b567..00ec27b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Version 1.1.1 (2021-08-05) +-------------------------- +Fix ScalaDoc publishing (#168) +http4s: pass apikey for schema-list methods (#166) + Version 1.1.0 (2021-07-09) -------------------------- Run scalafmtCheckAll in github action (#163)