Skip to content

Commit c17b452

Browse files
committed
fix(scanoss): Make the API key an optional secret again
Before 40fa386 the API key effectively was optional as a missing key was turned into an empty string via val apiKey = secrets[API_KEY_PROPERTY].orEmpty() Restore that behavior by using the empty string as a default value. Also, the API key actually was a secret instead of a regular option, which is corrected now, too. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 3359f31 commit c17b452

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ScanOss(
5454
private val service = ScanApi.builder()
5555
// As there is only a single endpoint, the SCANOSS API client expects the path to be part of the API URL.
5656
.url(config.apiUrl.removeSuffix("/") + "/scan/direct")
57-
.apiKey(config.apiKey)
57+
.apiKey(config.apiKey.value)
5858
.build()
5959

6060
override val version: String by lazy {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
package org.ossreviewtoolkit.plugins.scanners.scanoss
2121

2222
import org.ossreviewtoolkit.plugins.api.OrtPluginOption
23+
import org.ossreviewtoolkit.plugins.api.Secret
2324

2425
data class ScanOssConfig(
2526
/** The URL of the ScanOSS server. */
2627
@OrtPluginOption(defaultValue = "https://api.osskb.org/")
2728
val apiUrl: String,
2829

29-
/** The API key required to authenticate with the ScanOSS server. */
30-
val apiKey: String,
30+
/** The API key used to authenticate with the ScanOSS server. */
31+
@OrtPluginOption(defaultValue = "")
32+
val apiKey: Secret,
3133

3234
/**
3335
* A regular expression to match the scanner name when looking up scan results in the storage.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.SnippetFinding
4242
import org.ossreviewtoolkit.model.TextLocation
4343
import org.ossreviewtoolkit.model.VcsInfo
4444
import org.ossreviewtoolkit.model.VcsType
45+
import org.ossreviewtoolkit.plugins.api.Secret
4546
import org.ossreviewtoolkit.scanner.ScanContext
4647
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
4748

@@ -61,7 +62,7 @@ class ScanOssScannerDirectoryTest : StringSpec({
6162

6263
beforeSpec {
6364
server.start()
64-
scanner = spyk(ScanOssFactory.create(apiUrl = "http://localhost:${server.port()}", apiKey = ""))
65+
scanner = spyk(ScanOssFactory.create(apiUrl = "http://localhost:${server.port()}", apiKey = Secret("")))
6566
}
6667

6768
afterSpec {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import java.util.UUID
3636
import org.ossreviewtoolkit.model.LicenseFinding
3737
import org.ossreviewtoolkit.model.PackageType
3838
import org.ossreviewtoolkit.model.TextLocation
39+
import org.ossreviewtoolkit.plugins.api.Secret
3940
import org.ossreviewtoolkit.scanner.ScanContext
4041

4142
private val TEST_FILE_TO_SCAN = File("src/test/assets/filesToScan/ScannerFactory.kt")
@@ -54,7 +55,7 @@ class ScanOssScannerFileTest : StringSpec({
5455

5556
beforeSpec {
5657
server.start()
57-
scanner = spyk(ScanOssFactory.create(apiUrl = "http://localhost:${server.port()}", apiKey = ""))
58+
scanner = spyk(ScanOssFactory.create(apiUrl = "http://localhost:${server.port()}", apiKey = Secret("")))
5859
}
5960

6061
afterSpec {

0 commit comments

Comments
 (0)