From 4d5b611668f83b5c92d7cb8bca7408e0b5f0ba64 Mon Sep 17 00:00:00 2001 From: Oliver Heger Date: Fri, 10 Nov 2023 09:05:32 +0100 Subject: [PATCH] feat(reporter): Read FossID credentials from secrets In FossIdReporter, read the FossID user and API key from the secrets of the `PluginConfiguration` rather than from the plain options. Fixes #7833. Signed-off-by: Oliver Heger --- .../fossid/src/main/kotlin/FossIdReporter.kt | 4 ++-- .../fossid/src/test/kotlin/FossIdReporterTest.kt | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt b/plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt index b94fcd1b79b18..8d598856807c9 100644 --- a/plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt +++ b/plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt @@ -73,10 +73,10 @@ class FossIdReporter : Reporter { val serverUrl = requireNotNull(config.options[SERVER_URL_PROPERTY]) { "No FossID server URL configuration found." } - val apiKey = requireNotNull(config.options[API_KEY_PROPERTY]) { + val apiKey = requireNotNull(config.secrets[API_KEY_PROPERTY]) { "No FossID API Key configuration found." } - val user = requireNotNull(config.options[USER_PROPERTY]) { + val user = requireNotNull(config.secrets[USER_PROPERTY]) { "No FossID User configuration found." } val reportType = config.options[REPORT_TYPE_PROPERTY]?.let { diff --git a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt index bfa48d7a075ea..f8ba30b89f1bf 100644 --- a/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt +++ b/plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt @@ -63,7 +63,9 @@ private const val SERVER_URL_SAMPLE = "https://fossid.example.com/instance/" private const val API_KEY_SAMPLE = "XYZ" private const val USER_KEY_SAMPLE = "user" private val DEFAULT_OPTIONS = mapOf( - FossIdReporter.SERVER_URL_PROPERTY to SERVER_URL_SAMPLE, + FossIdReporter.SERVER_URL_PROPERTY to SERVER_URL_SAMPLE +) +private val DEFAULT_SECRETS = mapOf( FossIdReporter.API_KEY_PROPERTY to API_KEY_SAMPLE, FossIdReporter.USER_PROPERTY to USER_KEY_SAMPLE ) @@ -101,7 +103,7 @@ class FossIdReporterTest : WordSpec({ val input = createReporterInput() reporter.generateReport( input, - DEFAULT_OPTIONS.filterNot { it.key == FossIdReporter.API_KEY_PROPERTY } + secrets = DEFAULT_SECRETS.filterNot { it.key == FossIdReporter.API_KEY_PROPERTY } ) } exception shouldHaveMessage "No FossID API Key configuration found." @@ -113,7 +115,7 @@ class FossIdReporterTest : WordSpec({ val input = createReporterInput() reporter.generateReport( input, - DEFAULT_OPTIONS.filterNot { it.key == FossIdReporter.USER_PROPERTY } + secrets = DEFAULT_SECRETS.filterNot { it.key == FossIdReporter.USER_PROPERTY } ) } exception shouldHaveMessage "No FossID User configuration found." @@ -243,8 +245,11 @@ class FossIdReporterTest : WordSpec({ } }) -private fun FossIdReporter.generateReport(input: ReporterInput, options: Options = DEFAULT_OPTIONS) = - generateReport(input, DIRECTORY_SAMPLE, PluginConfiguration(options)) +private fun FossIdReporter.generateReport( + input: ReporterInput, + options: Options = DEFAULT_OPTIONS, + secrets: Options = DEFAULT_SECRETS +) = generateReport(input, DIRECTORY_SAMPLE, PluginConfiguration(options, secrets)) private fun createReporterMock(): Pair { mockkObject(FossIdRestService)