Skip to content

Commit

Permalink
feat(reporter): Read FossID credentials from secrets
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
oheger-bosch committed Nov 10, 2023
1 parent a455329 commit 4d5b611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions plugins/reporters/fossid/src/main/kotlin/FossIdReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions plugins/reporters/fossid/src/test/kotlin/FossIdReporterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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."
Expand All @@ -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."
Expand Down Expand Up @@ -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<FossIdRestService, FossIdReporter> {
mockkObject(FossIdRestService)
Expand Down

0 comments on commit 4d5b611

Please sign in to comment.