Skip to content

Commit 2155566

Browse files
heliocastrosschuberth
authored andcommitted
feat(scanoss): Add extra information to snippets
The SCANOSS server provides endpoints to retrieve the related snippets found, but the API call depends on the file hash which is not currently provided. Add the file hash, URL, and source hash as `additionalData` to address that. Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
1 parent 3f04b30 commit 2155566

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ private fun createSnippetFindings(details: ScanFileDetails, localFilePath: Strin
158158
val vcsInfo = VcsHost.parseUrl(url.takeUnless { it == "none" }.orEmpty())
159159
val provenance = RepositoryProvenance(vcsInfo, ".")
160160

161-
// Purls can be empty if only one entry is provided which is used as the primary purl.
162-
val additionalData = if (purls.isNotEmpty()) {
163-
mapOf("related_purls" to purls.joinToString(",") { it.trim() })
164-
} else {
165-
emptyMap()
161+
val additionalData = buildMap {
162+
put("file_hash", details.fileHash)
163+
put("file_url", details.fileUrl)
164+
put("source_hash", details.sourceHash)
165+
166+
// Purls can be empty if only one entry is provided which is used as the primary purl.
167+
if (purls.isNotEmpty()) put("related_purls", purls.joinToString(",") { it.trim() })
166168
}
167169

168170
// Convert both local and OSS line ranges to source locations.

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ class ScanOssResultParserTest : WordSpec({
128128
"."
129129
),
130130
"pkg:github/vdurmont/semver4j",
131-
SpdxExpression.parse("CC-BY-SA-2.0")
131+
SpdxExpression.parse("CC-BY-SA-2.0"),
132+
mapOf(
133+
"file_hash" to "6ff2427335b985212c9b79dfa795799f",
134+
"file_url" to "https://osskb.org/api/file_contents/6ff2427335b985212c9b79dfa795799f",
135+
"source_hash" to "bd4bff27f540f4f2c9de012acc4b48a3"
136+
)
132137
)
133138
)
134139
)
@@ -157,6 +162,9 @@ class ScanOssResultParserTest : WordSpec({
157162
// Verify related PURLs to be stored as additional data.
158163
snippets.first().additionalData shouldBe
159164
mapOf(
165+
"file_hash" to "581734935cfbe570d280a1265aaa2a6b",
166+
"file_url" to "https://api.scanoss.com/file_contents/581734935cfbe570d280a1265aaa2a6b",
167+
"source_hash" to "45dd1e50621a8a32f88fbe0251a470ab",
160168
"related_purls" to "pkg:github/fake/fake_repository"
161169
)
162170

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ class ScanOssScannerDirectoryTest : StringSpec({
113113
VcsInfo(VcsType.GIT, "https://github.com/scanoss/ort.git", ""), "."
114114
),
115115
"pkg:github/scanoss/ort",
116-
SpdxExpression.parse("Apache-2.0")
116+
SpdxExpression.parse("Apache-2.0"),
117+
mapOf(
118+
"file_hash" to "871fb0c5188c2f620d9b997e225b0095",
119+
"file_url" to "https://osskb.org/api/file_contents/871fb0c5188c2f620d9b997e225b0095",
120+
"source_hash" to "2e91edbe430c4eb195a977d326d6d6c0"
121+
)
117122
)
118123
)
119124
)

0 commit comments

Comments
 (0)