From f8af44b0ebf6259991e48735ae7f8754d5825924 Mon Sep 17 00:00:00 2001 From: Benjamin Benoist Date: Fri, 15 Oct 2021 16:13:19 +0200 Subject: [PATCH] Bump Iglu client to 1.1.1 (close #507) --- build.sbt | 2 + .../registries/Http4sRegistryLookup.scala | 95 -------------- .../registries/Http4sRegistryLookupSpec.scala | 121 ------------------ project/Dependencies.scala | 3 +- 4 files changed, 4 insertions(+), 217 deletions(-) delete mode 100644 modules/common-fs2/src/main/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookup.scala delete mode 100644 modules/common-fs2/src/test/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookupSpec.scala diff --git a/build.sbt b/build.sbt index eba2287d2..656d51040 100644 --- a/build.sbt +++ b/build.sbt @@ -237,6 +237,8 @@ lazy val commonFs2 = project Dependencies.Libraries.sentry, Dependencies.Libraries.log4cats, Dependencies.Libraries.catsRetry, + Dependencies.Libraries.igluClient, + Dependencies.Libraries.igluClientHttp4s, Dependencies.Libraries.http4sClient, Dependencies.Libraries.http4sCirce, Dependencies.Libraries.pureconfig.withRevision(Dependencies.V.pureconfig013), diff --git a/modules/common-fs2/src/main/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookup.scala b/modules/common-fs2/src/main/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookup.scala deleted file mode 100644 index fc638ed97..000000000 --- a/modules/common-fs2/src/main/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookup.scala +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2021 Snowplow Analytics Ltd. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package com.snowplowanalytics.iglu.client.resolver.registries - -import cats.implicits._ -import cats.data.EitherT -import cats.effect.Sync -import io.circe.Json -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 { - - def apply[F[_]: Sync](client: HttpClient[F]): RegistryLookup[F] = - new RegistryLookup[F] { - def lookup(repositoryRef: Registry, schemaKey: SchemaKey): F[Either[RegistryError, Json]] = - repositoryRef match { - case Registry.Http(_, connection) => httpLookup(client, connection, schemaKey).value - case Registry.Embedded(_, path) => RegistryLookup.embeddedLookup[F](path, schemaKey) - case Registry.InMemory(_, schemas) => Sync[F].pure(RegistryLookup.inMemoryLookup(schemas, schemaKey)) - } - - def list( - registry: Registry, - vendor: String, - name: String, - model: Int - ): F[Either[RegistryError, SchemaList]] = - registry match { - case Registry.Http(_, connection) => httpList(client, connection, vendor, name, model).value - case _ => Sync[F].pure(RegistryError.NotFound.asLeft) - } - } - - def httpLookup[F[_]: Sync]( - client: HttpClient[F], - http: Registry.HttpConnection, - key: SchemaKey - ): EitherT[F, RegistryError, Json] = - for { - 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 - - def httpList[F[_]: Sync]( - client: HttpClient[F], - http: Registry.HttpConnection, - vendor: String, - name: String, - model: Int - ): 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 - - def toPath(cxn: Registry.HttpConnection, key: SchemaKey): Either[RegistryError, Uri] = - Uri - .fromString(s"${cxn.uri.toString.stripSuffix("/")}/schemas/${key.toPath}") - .leftMap(e => RegistryError.ClientFailure(e.message)) - - def toSubpath( - cxn: Registry.HttpConnection, - vendor: String, - name: String, - model: Int - ): Either[RegistryError, Uri] = - Uri - .fromString(s"${cxn.uri.toString.stripSuffix("/")}/schemas/$vendor/$name/jsonschema/$model") - .leftMap(e => RegistryError.ClientFailure(e.message)) - - implicit def schemaListDecoder[F[_]: Sync]: EntityDecoder[F, SchemaList] = jsonOf[F, SchemaList] -} diff --git a/modules/common-fs2/src/test/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookupSpec.scala b/modules/common-fs2/src/test/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookupSpec.scala deleted file mode 100644 index 1e25a252d..000000000 --- a/modules/common-fs2/src/test/scala/com/snowplowanalytics/iglu/client/resolver/registries/Http4sRegistryLookupSpec.scala +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2021 Snowplow Analytics Ltd. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package com.snowplowanalytics.iglu.client.resolver.registries - -import cats.effect.{IO, Resource} -import cats.effect.testing.specs2.CatsIO -import io.circe.Json -import java.net.URI -import org.http4s.client.{Client => HttpClient} -import org.http4s.dsl.Http4sDsl -import org.http4s.implicits._ - -import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaList, SchemaVer} - -import org.specs2.mutable.Specification - -class Http4sRegistryLookupSpec extends Specification with CatsIO { - - "The Http4sRegistryLookup lookup" should { - "lookup a valid schema" in { - - val repositoryRef = - Registry.Http(Registry.Config("name", 1, Nil), Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)) - val schemaKey = SchemaKey("com.myvendor", "myname", "jsonschema", SchemaVer.Full(42, 42, 42)) - - val client = HttpClient[IO] { req => - val dsl = new Http4sDsl[IO] {}; import dsl._ - if (req.uri == uri"http://custom-iglu.com/schemas/com.myvendor/myname/jsonschema/42-42-42") - Resource.eval(Ok("""{"xyz": true}""")) - else - Resource.eval(NotFound("unexpected url")) - } - - Http4sRegistryLookup(client).lookup(repositoryRef, schemaKey).map { result => - result should beRight(Json.obj("xyz" -> Json.True)) - } - } - - "return a registry error for an unknown schema" in { - - val repositoryRef = - Registry.Http(Registry.Config("name", 1, Nil), Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)) - val schemaKey = SchemaKey("com.myvendor", "myname", "jsonschema", SchemaVer.Full(42, 42, 42)) - - val client = HttpClient[IO] { _ => - val dsl = new Http4sDsl[IO] {}; import dsl._ - Resource.eval(NotFound("not found")) - } - - Http4sRegistryLookup(client).lookup(repositoryRef, schemaKey).map { result => - result should beLeft - } - } - - "return a registry error when http client raises exception" in { - - val repositoryRef = - Registry.Http(Registry.Config("name", 1, Nil), Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)) - val schemaKey = SchemaKey("com.myvendor", "myname", "jsonschema", SchemaVer.Full(42, 42, 42)) - - val client = HttpClient[IO] { _ => - Resource.eval(IO.raiseError(new RuntimeException("boom!"))) - } - - Http4sRegistryLookup(client).lookup(repositoryRef, schemaKey).map { result => - result should beLeft - } - } - } - - "The Http4sRegistryLookup list" should { - "list schemas for a valid vendor and name" in { - - val registry = - Registry.Http(Registry.Config("name", 1, Nil), Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)) - - val client = HttpClient[IO] { req => - val dsl = new Http4sDsl[IO] {}; import dsl._ - if (req.uri == uri"http://custom-iglu.com/schemas/com.myvendor/myname/jsonschema/42") - Resource.eval(Ok("""["iglu:com.myvendor/myname/jsonschema/42-0-0", "iglu:com.myvendor/myname/jsonschema/42-0-1"]""")) - else - Resource.eval(NotFound("unexpected url")) - } - - val expected = List( - SchemaKey("com.myvendor", "myname", "jsonschema", SchemaVer.Full(42, 0, 0)), - SchemaKey("com.myvendor", "myname", "jsonschema", SchemaVer.Full(42, 0, 1)) - ) - - Http4sRegistryLookup(client).list(registry, "com.myvendor", "myname", 42).map { result => - result should beRight(SchemaList(expected)) - } - } - - "return a registry error when http client raises exception" in { - - val registry = - Registry.Http(Registry.Config("name", 1, Nil), Registry.HttpConnection(URI.create("http://custom-iglu.com"), None)) - - val client = HttpClient[IO] { _ => - Resource.eval(IO.raiseError(new RuntimeException("boom!"))) - } - - Http4sRegistryLookup(client).list(registry, "com.myvendor", "myname", 42).map { result => - result should beLeft - } - } - - } - -} diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 8b5617bba..b0bf1c7c4 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -57,7 +57,7 @@ object Dependencies { val gatlingJsonpath = "0.6.14" val scalaUri = "1.4.5" val badRows = "2.1.1" - val igluClient = "1.0.2" + val igluClient = "1.1.1" val snowplowRawEvent = "0.1.0" val collectorPayload = "0.0.0" @@ -131,6 +131,7 @@ object Dependencies { val scalaWeather = "com.snowplowanalytics" %% "scala-weather" % V.scalaWeather val badRows = "com.snowplowanalytics" %% "snowplow-badrows" % V.badRows val igluClient = "com.snowplowanalytics" %% "iglu-scala-client" % V.igluClient + val igluClientHttp4s = "com.snowplowanalytics" %% "iglu-scala-client-http4s" % V.igluClient val snowplowRawEvent = "com.snowplowanalytics" % "snowplow-thrift-raw-event" % V.snowplowRawEvent val collectorPayload = "com.snowplowanalytics" % "collector-payload-1" % V.collectorPayload val schemaSniffer = "com.snowplowanalytics" % "schema-sniffer-1" % V.schemaSniffer