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 authored and sschuberth committed Oct 16, 2024
1 parent 9d0873c commit e5c6e0c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 18 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
3 changes: 2 additions & 1 deletion model/src/test/kotlin/config/OrtConfigurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class OrtConfigurationTest : WordSpec({
"detectLicenseDeclarations" to "true",
"detectCopyrightStatements" to "true",
"timeout" to "60",
"urlMappingExample" to urlMapping
"urlMappingExample" to urlMapping,
"sensitivity" to "10"
)

secrets shouldContainExactly mapOf(
Expand Down
3 changes: 2 additions & 1 deletion plugins/scanners/fossid/src/main/kotlin/FossId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ class FossId internal constructor(

val optionsFromConfig = arrayOf(
"auto_identification_detect_declaration" to "${config.detectLicenseDeclarations.compareTo(false)}",
"auto_identification_detect_copyright" to "${config.detectCopyrightStatements.compareTo(false)}"
"auto_identification_detect_copyright" to "${config.detectCopyrightStatements.compareTo(false)}",
"sensitivity" to "${config.sensitivity}"
)

val scanResult = service.runScan(
Expand Down
21 changes: 20 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,

/** 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 All @@ -174,6 +180,12 @@ data class FossIdConfig(
@JvmStatic
private val DEFAULT_SNIPPETS_LIMIT = 500

/**
* Default scan sensitivity.
*/
@JvmStatic
private val DEFAULT_SENSITIVITY = 10

fun create(options: Options, secrets: Options): FossIdConfig {
require(options.isNotEmpty()) { "No FossID Scanner configuration found." }

Expand All @@ -198,10 +210,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]?.toInt() ?: DEFAULT_SENSITIVITY

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

require(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 +235,8 @@ data class FossIdConfig(
timeout = timeout,
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = options,
snippetsLimit = snippetsLimit
snippetsLimit = snippetsLimit,
sensitivity = sensitivity
)
}
}
Expand Down
20 changes: 18 additions & 2 deletions plugins/scanners/fossid/src/test/kotlin/FossIdConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class FossIdConfigTest : WordSpec({
timeout = 300,
fetchSnippetMatchedLines = true,
options = options,
snippetsLimit = 1000
snippetsLimit = 1000,
sensitivity = 10
)
}

Expand All @@ -101,7 +102,8 @@ class FossIdConfigTest : WordSpec({
timeout = 60,
fetchSnippetMatchedLines = false,
options = options,
snippetsLimit = 500
snippetsLimit = 500,
sensitivity = 10
)
}

Expand Down Expand Up @@ -141,6 +143,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
36 changes: 24 additions & 12 deletions plugins/scanners/fossid/src/test/kotlin/FossIdTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
} returns EntityResponseBody(status = 1)
Expand All @@ -475,7 +476,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -504,7 +506,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
} returns EntityResponseBody(
Expand All @@ -523,7 +526,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -551,7 +555,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
} returns EntityResponseBody(status = 1)
Expand Down Expand Up @@ -642,7 +647,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -690,7 +696,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -738,7 +745,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode2),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -786,7 +794,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode2),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down Expand Up @@ -830,7 +839,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
service.listIgnoreRules(USER, API_KEY, originCode)
Expand Down Expand Up @@ -884,7 +894,8 @@ class FossIdTest : WordSpec({
mapOf(
*FossId.deltaScanRunParameters(originCode),
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
service.listIgnoreRules(USER, API_KEY, originCode)
Expand Down Expand Up @@ -931,7 +942,8 @@ class FossIdTest : WordSpec({
scanCode,
mapOf(
"auto_identification_detect_declaration" to "0",
"auto_identification_detect_copyright" to "0"
"auto_identification_detect_copyright" to "0",
"sensitivity" to "10"
)
)
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/scanners/fossid/src/test/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ internal fun createConfig(
timeout = 60,
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = emptyMap(),
snippetsLimit = snippetsLimit
snippetsLimit = snippetsLimit,
sensitivity = 10
)

val namingProvider = createNamingProviderMock()
Expand Down

0 comments on commit e5c6e0c

Please sign in to comment.