Skip to content

Commit

Permalink
Make ssl default port 9543 + better config loading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Feb 16, 2024
1 parent f6d47b0 commit e1a09a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main/resources/collector-micro.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ collector {
}
interface = "0.0.0.0"
port = 9090
ssl {
port = 9543
}

streams {
good = "good"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ object Configuration {
}
}

def loadCollectorConfig(path: Option[Path]): EitherT[IO, String, CollectorConfig[SinkConfig]] = {
private def loadCollectorConfig(path: Option[Path]): EitherT[IO, String, CollectorConfig[SinkConfig]] = {
val resolveOrder = (config: TypesafeConfig) =>
namespaced(ConfigFactory.load(namespaced(config.withFallback(namespaced(ConfigFactory.parseResources("collector-micro.conf"))))))

loadConfig[CollectorConfig[SinkConfig]](path, resolveOrder)
.map(adjustSslConfig)
}

def loadIgluResources(path: Option[Path]): EitherT[IO, String, IgluResources] = {
private def loadIgluResources(path: Option[Path]): EitherT[IO, String, IgluResources] = {
val resolveOrder = (config: TypesafeConfig) =>
config.withFallback(ConfigFactory.parseResources("default-iglu-resolver.conf"))

loadConfig[ResolverConfig](path, resolveOrder)
.flatMap(buildIgluResources)
}

def loadEnrichmentConfig(igluClient: IgluCirceClient[IO]): EitherT[IO, String, List[EnrichmentConf]] = {
private def loadEnrichmentConfig(igluClient: IgluCirceClient[IO]): EitherT[IO, String, List[EnrichmentConf]] = {
Option(getClass.getResource("/enrichments")) match {
case Some(definedEnrichments) =>
val path = Paths.get(definedEnrichments.toURI)
Expand Down Expand Up @@ -135,11 +135,12 @@ object Configuration {
}

private def buildJSConfig(script: FS2Path): IO[EnrichmentConf.JavascriptScriptConf] = {
val schemaKey = SchemaKey("com.snowplowanalytics.snowplow", "javascript_script_config", "jsonschema", SchemaVer.Full(1, 0, 0))
Files[IO]
.readUtf8Lines(script)
.compile
.toList
.map(lines => EnrichmentConf.JavascriptScriptConf(null, lines.mkString("\n")))
.map(lines => EnrichmentConf.JavascriptScriptConf(schemaKey, lines.mkString("\n")))
}

private def listAvailableEnrichments(enrichmentsDirectory: Path, fileType: String) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@
*/
package com.snowplowanalytics.snowplow.micro

import cats.effect.IO
import cats.effect.testing.specs2.CatsEffect
import com.monovore.decline.Command
import com.snowplowanalytics.snowplow.micro.Configuration.MicroConfig
import org.specs2.mutable.Specification

class ConfigHelperSpec extends Specification with CatsEffect {
"ConfigHelper" >> {
"will produce a valid parsed collector config if `--collector-config` is not present" >> {
Configuration.loadCollectorConfig(None).value.map {
case Right(_) => ok
case Left(_) => ko
}
"Configuration loader should work when" >> {
"no custom args are provided and only defaults are used" >> {
load(args = List.empty)
.map { result =>
result must beRight[MicroConfig].like {
case config =>
config.collector.port must beEqualTo(9090)
config.collector.ssl.enable must beFalse
config.collector.ssl.port must beEqualTo(9543)

config.enrichmentsConfig.isEmpty must beTrue
config.iglu.resolver.repos.map(_.config.name) must containTheSameElementsAs(List("Iglu Central", "Iglu Central - Mirror 01"))

config.outputEnrichedTsv must beFalse
}
}
}
}

private def load(args: List[String]): IO[Either[String, MicroConfig]] = {
Command("test-app", "test")(Configuration.load()).parse(args).right.get.value
}
}

0 comments on commit e1a09a1

Please sign in to comment.