diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2019-03-21 09:10:11 +0100 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2019-03-21 09:13:51 +0100 |
commit | d418dd43e7812ea2cdebf188bf5ab51a997df90c (patch) | |
tree | 60c33ac48330cca76bf8379ec5ed6fa48eac3e22 /sources/hv-collector-configuration/src | |
parent | 30afcb56b0c6c4529fdaf68d7b061eee44d68d16 (diff) |
Include basic configuration in Docker image
Makes the collector start out of the box, even without valid CBS
configuration.
Note: the basic configuration will need to be changed later.
Issue-ID: DCAEGEN2-1340
Change-Id: I3c2b502f253677e78a4f4990002e683613b8869e
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'sources/hv-collector-configuration/src')
4 files changed, 72 insertions, 3 deletions
diff --git a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt index 5b547a28..9f8c552b 100644 --- a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt +++ b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModule.kt @@ -37,7 +37,7 @@ class ConfigurationModule { fun hvVesConfigurationUpdates(args: Array<String>): Flux<HvVesConfiguration> = Flux.just(cmd.parse(args)) .throwOnLeft { MissingArgumentException(it.message, it.cause) } - .map { configReader.loadConfig(it.reader()) } + .map { it.reader().use(configReader::loadConfig) } .map { configValidator.validate(it) } .throwOnLeft { ValidationException(it.message) } } diff --git a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidator.kt b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidator.kt index 6c74c33f..83f56924 100644 --- a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidator.kt +++ b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidator.kt @@ -53,7 +53,7 @@ internal class ConfigurationValidator { .let { createCbsConfiguration(it).bind() } val securityConfiguration = partialConfig.security.bind() - .let { createSecurityConfiguration(it).bind() } + .let { createSecurityConfiguration(it) } val collectorConfiguration = partialConfig.collector.bind() .let { createCollectorConfig(it).bind() } @@ -94,7 +94,11 @@ internal class ConfigurationValidator { } private fun createSecurityConfiguration(partial: PartialSecurityConfig) = - partial.keys.map { SecurityConfiguration(Some(it)) } + partial.keys + .fold( + { SecurityConfiguration(None) }, + { SecurityConfiguration(Some(it)) } + ) private fun createCollectorConfig(partial: PartialCollectorConfig) = partial.mapBinding { diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt index 12396d23..beb5df61 100644 --- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt +++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt @@ -20,6 +20,7 @@ package org.onap.dcae.collectors.veshv.config.impl import arrow.core.None +import arrow.core.Option import arrow.core.Some import com.nhaarman.mockitokotlin2.mock import org.assertj.core.api.Assertions.assertThat @@ -134,5 +135,57 @@ internal object ConfigurationValidatorTest : Spek({ ) } } + + describe("validating configuration with security disabled") { + val idleTimeoutSec = 10 + val firstReqDelaySec = 10 + val securityKeys: Option<SecurityKeys> = None + val routing = routing { }.build() + + val config = PartialConfiguration( + Some(PartialServerConfig( + Some(1), + Some(idleTimeoutSec), + Some(2) + )), + Some(PartialCbsConfig( + Some(firstReqDelaySec), + Some(3) + )), + Some(PartialSecurityConfig( + securityKeys + )), + Some(PartialCollectorConfig( + Some(true), + Some(4), + Some(emptyList()), + Some(routing) + )), + Some(LogLevel.INFO) + ) + + it("should create valid configuration") { + val result = cut.validate(config) + result.fold( + { + fail("Configuration should have been created successfully but was $it") + }, + { + assertThat(it.server.idleTimeout) + .isEqualTo(Duration.ofSeconds(idleTimeoutSec.toLong())) + + assertThat(it.security.keys) + .isEqualTo(securityKeys) + + assertThat(it.cbs.firstRequestDelay) + .isEqualTo(Duration.ofSeconds(firstReqDelaySec.toLong())) + + assertThat(it.collector.routing) + .isEqualTo(routing) + } + ) + } + } + } }) diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt index ab99f13c..8267e304 100644 --- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt +++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt @@ -103,6 +103,18 @@ internal object FileConfigurationReaderTest : Spek({ } } + it("parses disabled security configuration") { + val input = """{ + "security": { + } + }""".trimIndent() + val config = cut.loadConfig(StringReader(input)) + + assertThat(config.security.nonEmpty()).isTrue() + val security = config.security.orNull() as PartialSecurityConfig + assertThat(security.keys.nonEmpty()).isFalse() + } + it("parses invalid log level string to empty option") { val input = """{ "logLevel": something |