Skip to content

Commit

Permalink
refactor(fossid)!: Define URL mappings in a single option
Browse files Browse the repository at this point in the history
Replace the custom options to define URL mappings with a single
comma-separated option `urlMappings`. This will simplify the migration
to the new plugin API.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Jan 15, 2025
1 parent 716e3b8 commit 3ea4ec5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion model/src/main/resources/reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ort:

timeout: 60

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

sensitivity: 10

Expand Down
2 changes: 1 addition & 1 deletion model/src/test/kotlin/config/OrtConfigurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class OrtConfigurationTest : WordSpec({
"detectLicenseDeclarations" to "true",
"detectCopyrightStatements" to "true",
"timeout" to "60",
"urlMappingExample" to urlMapping,
"urlMappings" to urlMapping,
"sensitivity" to "10"
)

Expand Down
13 changes: 11 additions & 2 deletions plugins/scanners/fossid/src/main/kotlin/FossIdConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ data class FossIdConfig(
/** The sensitivity of the scan. */
val sensitivity: Int,

/** A comma-separated list of URL mappings. */
val urlMappings: String?,

/** Stores the map with FossID-specific configuration options. */
private val options: Map<String, String>
) {
Expand Down Expand Up @@ -162,6 +165,9 @@ data class FossIdConfig(
/** Name of the configuration property defining the sensitivity of the scan. */
private const val PROP_SENSITIVITY = "sensitivity"

/** Name of the configuration property defining the URL mappings. */
private const val PROP_URL_MAPPINGS = "urlMappings"

/**
* Default timeout in minutes for communication with FossID.
*/
Expand Down Expand Up @@ -208,6 +214,8 @@ data class FossIdConfig(

val sensitivity = options[PROP_SENSITIVITY]?.toInt() ?: DEFAULT_SENSITIVITY

val urlMappings = options[PROP_URL_MAPPINGS]

require(deltaScanLimit > 0) {
"deltaScanLimit must be > 0, current value is $deltaScanLimit."
}
Expand All @@ -233,7 +241,8 @@ data class FossIdConfig(
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = options,
snippetsLimit = snippetsLimit,
sensitivity = sensitivity
sensitivity = sensitivity,
urlMappings = urlMappings,
)
}
}
Expand All @@ -252,5 +261,5 @@ data class FossIdConfig(
/**
* Create a [FossIdUrlProvider] helper object based on the configuration stored in this object.
*/
fun createUrlProvider() = FossIdUrlProvider.create(options)
fun createUrlProvider() = FossIdUrlProvider.create(urlMappings?.split(',').orEmpty())
}
7 changes: 0 additions & 7 deletions plugins/scanners/fossid/src/main/kotlin/FossIdUrlProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ class FossIdUrlProvider private constructor(
return FossIdUrlProvider(mappings)
}

/**
* Create a new instance of [FossIdUrlProvider] and configure the URL mappings from the given configuration
* [options].
*/
fun create(options: Map<String, String>): FossIdUrlProvider =
create(options.filter { it.key.startsWith(PREFIX_URL_MAPPING) }.values)

/**
* Try to fetch credentials for [repoUrl] from the current [Authenticator]. Return *null* if no matching host
* is found.
Expand Down
11 changes: 7 additions & 4 deletions plugins/scanners/fossid/src/test/kotlin/FossIdConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class FossIdConfigTest : WordSpec({
"detectCopyrightStatements" to "true",
"timeout" to "300",
"fetchSnippetMatchedLines" to "true",
"snippetsLimit" to "1000"
"snippetsLimit" to "1000",
"urlMappings" to "https://example.org(?<repoPath>.*) -> ssh://example.org\${repoPath}"
)

val secrets = mapOf(
Expand All @@ -77,7 +78,8 @@ class FossIdConfigTest : WordSpec({
fetchSnippetMatchedLines = true,
options = options,
snippetsLimit = 1000,
sensitivity = 10
sensitivity = 10,
urlMappings = "https://example.org(?<repoPath>.*) -> ssh://example.org\${repoPath}"
)
}

Expand Down Expand Up @@ -106,7 +108,8 @@ class FossIdConfigTest : WordSpec({
fetchSnippetMatchedLines = false,
options = options,
snippetsLimit = 500,
sensitivity = 10
sensitivity = 10,
urlMappings = null
)
}

Expand Down Expand Up @@ -188,7 +191,7 @@ class FossIdConfigTest : WordSpec({
val url = "https://changeit.example.org/foo"
val options = mapOf(
"serverUrl" to SERVER_URL,
"urlMappingChangeHost" to "$url -> $SERVER_URL"
"urlMappings" to "$url -> $SERVER_URL"
)

val secrets = mapOf(
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 @@ -140,7 +140,8 @@ internal fun createConfig(
fetchSnippetMatchedLines = fetchSnippetMatchedLines,
options = emptyMap(),
snippetsLimit = snippetsLimit,
sensitivity = 10
sensitivity = 10,
urlMappings = null
)

val namingProvider = createNamingProviderMock()
Expand Down

0 comments on commit 3ea4ec5

Please sign in to comment.