Skip to content

Commit

Permalink
feat(fossid): Make FossID sensitivity configurable
Browse files Browse the repository at this point in the history
Add the option for the user to specify the sensitivity for a FossID scan
to reduce the number of pending identifications.

Signed-off-by: Julian Olderdissen <julian.olderdissen@bosch.com>
  • Loading branch information
Juli0q committed Oct 7, 2024
1 parent 58e3c6f commit 42438cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions model/src/main/resources/reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ ort:

urlMappingExample: "https://my-repo.example.org(?<repoPath>.*) -> ssh://my-mapped-repo.example.org${repoPath}"

sensitivity: 10

secrets:
user: user
apiKey: XYZ
Expand Down
6 changes: 4 additions & 2 deletions plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,12 @@ class FossId internal constructor(
if (response.data?.status in SCAN_STATE_FOR_TRIGGER) {
logger.info { "Triggering scan as it has not yet been started." }

val optionsFromConfig = arrayOf(
val optionsFromConfig = mutableListOf(
"auto_identification_detect_declaration" to "${config.detectLicenseDeclarations.compareTo(false)}",
"auto_identification_detect_copyright" to "${config.detectCopyrightStatements.compareTo(false)}"
)
).apply {
config.sensitivity?.let { add("sensitivity" to "$it") }
}.toTypedArray()

val scanResult = service.runScan(
config.user, config.apiKey, scanCode, mapOf(*runOptions, *optionsFromConfig)
Expand Down
15 changes: 14 additions & 1 deletion plugins/scanners/fossid/src/main/kotlin/FossIdConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ data class FossIdConfig(
/** A limit on the amount of snippets to fetch. **/
val snippetsLimit: Int,

/** The sensitivity of the scan. */
val sensitivity: Int? = null,

/** Stores the map with FossID-specific configuration options. */
private val options: Map<String, String>
) {
Expand Down Expand Up @@ -157,6 +160,9 @@ data class FossIdConfig(
/** Name of the configuration property defining the limit on the amount of snippets to fetch. */
private const val PROP_SNIPPETS_LIMIT = "snippetsLimit"

/** Name of the configuration property defining the sensitivity of the scan. */
private const val PROP_SENSITIVITY = "sensitivity"

/**
* The scanner options beginning with this prefix will be used to parameterize project and scan names.
*/
Expand Down Expand Up @@ -198,10 +204,16 @@ data class FossIdConfig(
val fetchSnippetMatchedLines = options[PROP_FETCH_SNIPPET_MATCHED_LINES]?.toBoolean() == true
val snippetsLimit = options[PROP_SNIPPETS_LIMIT]?.toInt() ?: DEFAULT_SNIPPETS_LIMIT

val sensitivity = options[PROP_SENSITIVITY]?.toIntOrNull()

require(deltaScanLimit > 0) {
"deltaScanLimit must be > 0, current value is $deltaScanLimit."
}

require(sensitivity == null || sensitivity in 0..20) {
"Sensitivity must be between 0 and 20, current value is $sensitivity."
}

logger.info { "waitForResult parameter is set to '$waitForResult'" }

return FossIdConfig(
Expand All @@ -217,7 +229,8 @@ data class FossIdConfig(
timeout = timeout,
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = options,
snippetsLimit = snippetsLimit
snippetsLimit = snippetsLimit,
sensitivity = sensitivity
)
}
}
Expand Down
14 changes: 14 additions & 0 deletions plugins/scanners/fossid/src/test/kotlin/FossIdConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ class FossIdConfigTest : WordSpec({

shouldThrow<IllegalArgumentException> { FossIdConfig.create(options, secrets) }
}

"throw if the sensitivity is invalid" {
val options = mapOf(
"serverUrl" to SERVER_URL,
"sensitivity" to "21"
)

val secrets = mapOf(
"user" to USER,
"apiKey" to API_KEY
)

shouldThrow<IllegalArgumentException> { FossIdConfig.create(options, secrets) }
}
}

"createNamingProvider" should {
Expand Down

0 comments on commit 42438cc

Please sign in to comment.