Skip to content

Commit 80a3c25

Browse files
committed
feat(scanoss)!: Use secret options map
Read the API key from the secrets map instead of the options map in `ScanOssConfig`. This also fixes the issue that the API key was serialized to the ORT result as the `filterSecretOptions` function was not implemented by `ScanOss`. Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent e97c429 commit 80a3c25

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

plugins/scanners/scanoss/src/main/kotlin/ScanOss.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ScanOss internal constructor(
6060
ScanOss(type, config, matcherConfig)
6161

6262
override fun parseConfig(options: Options, secrets: Options) =
63-
ScanOssConfig.create(options).also { logger.info { "The $type API URL is ${it.apiUrl}." } }
63+
ScanOssConfig.create(options, secrets).also { logger.info { "The $type API URL is ${it.apiUrl}." } }
6464
}
6565

6666
private val service = ScanOssService.create(config.apiUrl)

plugins/scanners/scanoss/src/main/kotlin/ScanOssConfig.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import org.ossreviewtoolkit.utils.common.Options
2525

2626
/**
2727
* A data class that holds the configuration options supported by the [ScanOss] scanner. An instance of this class is
28-
* created from the options contained in a [ScannerConfiguration] object under the key _ScanOss_. It offers the
28+
* created from the [scanner config][ScannerConfiguration.config] object under the key _ScanOss_. It offers the
2929
* following configuration options:
30+
*
31+
* **"options.apiUrl":** The URL of the ScanOSS server.
32+
* **"secrets.apiKey":** The API key to authenticate with the ScanOSS server.
3033
*/
3134
data class ScanOssConfig(
3235
/** URL of the ScanOSS server. */
@@ -42,9 +45,9 @@ data class ScanOssConfig(
4245
/** Name of the configuration property for the API key. */
4346
const val API_KEY_PROPERTY = "apiKey"
4447

45-
fun create(options: Options): ScanOssConfig {
48+
fun create(options: Options, secrets: Options): ScanOssConfig {
4649
val apiUrl = options[API_URL_PROPERTY] ?: ScanOssService.DEFAULT_API_URL
47-
val apiKey = options[API_KEY_PROPERTY].orEmpty()
50+
val apiKey = secrets[API_KEY_PROPERTY].orEmpty()
4851

4952
return ScanOssConfig(apiUrl, apiKey)
5053
}

plugins/scanners/scanoss/src/test/kotlin/ScanOssConfigTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ import org.ossreviewtoolkit.clients.scanoss.ScanOssService
2828

2929
class ScanOssConfigTest : StringSpec({
3030
"Default values are used" {
31-
with(ScanOssConfig.create(emptyMap())) {
31+
with(ScanOssConfig.create(emptyMap(), emptyMap())) {
3232
apiUrl shouldBe ScanOssService.DEFAULT_API_URL
3333
apiKey should beEmpty()
3434
}
3535
}
3636

3737
"Default values can be overridden" {
38-
val options = mapOf(
39-
ScanOssConfig.API_URL_PROPERTY to "url",
40-
ScanOssConfig.API_KEY_PROPERTY to "key"
41-
)
38+
val options = mapOf(ScanOssConfig.API_URL_PROPERTY to "url")
39+
val secrets = mapOf(ScanOssConfig.API_KEY_PROPERTY to "key")
4240

43-
with(ScanOssConfig.create(options)) {
41+
with(ScanOssConfig.create(options, secrets)) {
4442
apiUrl shouldBe "url"
4543
apiKey shouldBe "key"
4644
}

0 commit comments

Comments
 (0)