Skip to content

Commit

Permalink
Add mandatory SLULA license acceptance flag (close #405)
Browse files Browse the repository at this point in the history
Since introducing a new license we need to explicitly check if the user
has accepted the terms. Therefore a new flag is added.
By default it is set to false but can be overrided by either:
- setting `license.accept = true` in the config file
- setting `env ACCEPT_LIMITED_USE_LICENSE=true`
- appending `-Dlicense.accept=true`
  • Loading branch information
peel committed Jan 4, 2024
1 parent 7652bda commit 2821a76
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 'collector' contains configuration options for the main Scala collector.
collector {
license { accept = true }
# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = "9292"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 'collector' contains configuration options for the main Scala collector.
collector {
license { accept = true }
# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = "10292"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ssc-collector-config/config.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = 0.0.0.0
port = 12345

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
license {
accept = false
accept = ${?ACCEPT_LIMITED_USE_LICENSE}
}

paths {}

p3p {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ case class Config[+SinkConfig](
networking: Config.Networking,
enableDefaultRedirect: Boolean,
redirectDomains: Set[String],
preTerminationPeriod: FiniteDuration
preTerminationPeriod: FiniteDuration,
license: Config.License
)

object Config {
Expand Down Expand Up @@ -152,7 +153,22 @@ object Config {
idleTimeout: FiniteDuration
)

case class FlexBoolean(value: Boolean)
object FlexBoolean {
implicit def toBoolean(b: FlexBoolean): Boolean = b.value
}
object License {
def apply(accept: Boolean): License = License(FlexBoolean(accept))
}
case class License(
accept: FlexBoolean
)

implicit def decoder[SinkConfig: Decoder]: Decoder[Config[SinkConfig]] = {
implicit val flexBooleanDecoder: Decoder[FlexBoolean] = {
val truthy = Set("true", "yes", "on", "1")
Decoder.decodeBoolean.map(s => FlexBoolean(s)).or(Decoder.decodeString.map(s => FlexBoolean(truthy(s))))
}
implicit val p3p = deriveDecoder[P3P]
implicit val crossDomain = deriveDecoder[CrossDomain]
implicit val sameSite: Decoder[SameSite] = Decoder.instance { cur =>
Expand All @@ -177,6 +193,7 @@ object Config {
implicit val ssl = deriveDecoder[SSL]
implicit val telemetry = deriveDecoder[Telemetry]
implicit val networking = deriveDecoder[Networking]
implicit val license = deriveDecoder[License]
implicit val sinkConfig = newDecoder[SinkConfig].or(legacyDecoder[SinkConfig])
implicit val streams = deriveDecoder[Streams[SinkConfig]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,24 @@ object Run {
telemetryInfo: TelemetryInfo[F, SinkConfig],
path: Option[Path]
): F[ExitCode] = {
val licenseNotAccepted = ExitCode(2)
val eitherT = for {
config <- ConfigParser.fromPath[F, SinkConfig](path)
_ <- EitherT.cond[F](config.license.accept.value == true, ExitCode.Success, licenseNotAccepted)
_ <- EitherT.right[ExitCode](fromConfig(appInfo, mkSinks, telemetryInfo, config))
} yield ExitCode.Success

eitherT.merge.handleErrorWith { e =>
Logger[F].error(e)("Exiting") >>
prettyLogException(e).as(ExitCode.Error)
}
eitherT
.merge
.ensure(
new RuntimeException(
"License not accepted. Configure license acceptance to continue. See docs for more details."
)
)(_ != licenseNotAccepted)
.handleErrorWith { e =>
Logger[F].error(e)("Exiting") >>
prettyLogException(e).as(ExitCode.Error)
}
}

private def fromConfig[F[_]: Async: Tracking, SinkConfig](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ConfigParserSpec extends Specification with CatsEffect {
.copy[SinkConfig](
paths = Map.empty[String, String],
streams = expectedStreams,
ssl = TestUtils.testConfig.ssl.copy(enable = true)
ssl = TestUtils.testConfig.ssl.copy(enable = true),
license = Config.License(false)
)

ConfigParser.fromPath[IO, SinkConfig](Some(path)).value.map(_ should beRight(expected))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ object TestUtils {
moduleVersion = None,
instanceId = None,
autoGeneratedId = None
)
),
license = License(accept = true)
)
}
5 changes: 5 additions & 0 deletions examples/config.kafka.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
4 changes: 4 additions & 0 deletions examples/config.kafka.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
collector {
license {
accept = true
}

interface = "0.0.0.0"
port = 8080

Expand Down
5 changes: 5 additions & 0 deletions examples/config.kinesis.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
4 changes: 4 additions & 0 deletions examples/config.kinesis.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
collector {
license {
accept = true
}

interface = "0.0.0.0"
port = 8080

Expand Down
5 changes: 5 additions & 0 deletions examples/config.nsq.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
7 changes: 5 additions & 2 deletions examples/config.nsq.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
collector {
license {
accept = true
}
interface = "0.0.0.0"
port = 8080

streams {
good {
name = "good"
host = "nsqHost"
}
}

bad {
name = "bad"
host = "nsqHost"
Expand Down
5 changes: 5 additions & 0 deletions examples/config.pubsub.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
4 changes: 4 additions & 0 deletions examples/config.pubsub.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
collector {
license {
accept = true
}

interface = "0.0.0.0"
port = 8080

Expand Down
5 changes: 5 additions & 0 deletions examples/config.sqs.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
3 changes: 3 additions & 0 deletions examples/config.sqs.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
collector {
license {
accept = true
}
interface = "0.0.0.0"
port = 8080

Expand Down
5 changes: 5 additions & 0 deletions examples/config.stdout.extended.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

# 'collector' contains configuration options for the main Scala collector.
collector {
# Full license text available in LICENSE.md
license {
accept = true
}

# The collector runs as a web service specified on the following interface and port.
interface = "0.0.0.0"
port = 8080
Expand Down
3 changes: 3 additions & 0 deletions examples/config.stdout.minimal.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
collector {
license {
accept = true
}
interface = "0.0.0.0"
port = 8080

Expand Down
1 change: 1 addition & 0 deletions kafka/src/it/resources/collector.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ object KafkaConfigSpec {
networking = Config.Networking(
maxConnections = 1024,
idleTimeout = 610.seconds
)
),
license = Config.License(accept = true)
)
}
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector-cookie-anonymous.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector-cookie-domain.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector-cookie-fallback.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector-cookie-no-domain.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector-custom-paths.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
1 change: 1 addition & 0 deletions kinesis/src/it/resources/collector.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ object KinesisConfigSpec {
moduleVersion = None,
instanceId = None,
autoGeneratedId = None
)
),
license = Config.License(accept = true)
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ object NsqConfigSpec {
networking = Config.Networking(
maxConnections = 1024,
idleTimeout = 610.seconds
)
),
license = Config.License(accept = true)
)
}
1 change: 1 addition & 0 deletions pubsub/src/it/resources/collector.hocon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
collector {
license { accept = true }
interface = "0.0.0.0"
port = ${PORT}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ object ConfigSpec {
moduleVersion = None,
instanceId = None,
autoGeneratedId = None
)
),
license = Config.License(accept = true)
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ object SqsConfigSpec {
moduleVersion = None,
instanceId = None,
autoGeneratedId = None
)
),
license = Config.License(accept = true)
)

}

0 comments on commit 2821a76

Please sign in to comment.