Skip to content

Commit

Permalink
Add license check
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Feb 15, 2024
1 parent bdc56cd commit 5b8daf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/scala/com.snowplowanalytics.snowplow.micro/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 =>
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/collector-micro.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
collector {
license {
accept = true
}
}

0 comments on commit 5b8daf4

Please sign in to comment.