From 5b8daf4db3a37b561d99dc8d42d58c0c24198ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Poniedzia=C5=82ek?= Date: Thu, 15 Feb 2024 15:13:03 +0100 Subject: [PATCH] Add license check --- .../Run.scala | 17 +++++++++++++++-- src/test/resources/collector-micro.conf | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/collector-micro.conf diff --git a/src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala b/src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala index 1483dd2..bdf45d2 100644 --- a/src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala +++ b/src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala @@ -11,7 +11,7 @@ package com.snowplowanalytics.snowplow.micro import cats.data.EitherT -import cats.effect.{ExitCode, IO, Resource} +import cats.effect.{ExitCode, IO, Resource, Sync} import cats.implicits._ import com.monovore.decline.Opts import com.snowplowanalytics.iglu.client.resolver.registries.JavaNetRegistryLookup @@ -41,6 +41,7 @@ object Run { Configuration.load().map { configuration => handleAppErrors { configuration + .flatTap(config => checkLicense(config.collector.license.accept)) .semiflatMap { validMicroConfig => buildEnvironment(validMicroConfig) .use(_ => IO.never) @@ -135,7 +136,19 @@ object Run { logger.info(s"Downloading $uri...") *> IO(uri.toURL #> new File(location) !!) } } - + + private def checkLicense(acceptLicense: Boolean): EitherT[IO, String, Unit] = + EitherT.liftF { + if (acceptLicense) + IO.unit + else + IO.raiseError( + new IllegalStateException( + "Please accept the terms of the Snowplow Limited Use License Agreement to proceed. See https://docs.snowplow.io/docs/pipeline-components-and-applications/stream-collector/configure/#license for more information on the license and how to configure this." + ) + ) + } + private def handleAppErrors(appOutput: EitherT[IO, String, ExitCode]): IO[ExitCode] = { appOutput .leftSemiflatMap { error => diff --git a/src/test/resources/collector-micro.conf b/src/test/resources/collector-micro.conf new file mode 100644 index 0000000..d01c438 --- /dev/null +++ b/src/test/resources/collector-micro.conf @@ -0,0 +1,5 @@ +collector { + license { + accept = true + } +} \ No newline at end of file