Skip to content

Commit 041b2f3

Browse files
committed
feat(scanoss): Add extra information to snippets
SCANOSS server provides endpoints to retrieve the related snippet found, but API call depends on the file hash, which is not provided on current status. Added file hash, file_url and source_hash into additionalData instalation. Co-authored-by: Agustin Isasmendi <agustin.isasmendi@scanoss.com> Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
1 parent d5e60f8 commit 041b2f3

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +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
162-
// and already taken by primaryPurl
163-
val additionalData = if (purls.isNotEmpty()) {
164-
mapOf("related_purls" to purls.joinToString(", ") { it.trim() })
165-
} else {
166-
emptyMap()
161+
val additionalData = buildMap {
162+
put("file_hash", details.fileHash)
163+
put("file_url", details.fileUrl)
164+
put("source_hash", details.sourceHash)
165+
// Purls can be empty if only one entry is provided
166+
// and already taken by primaryPurl
167+
if (purls.isNotEmpty()) put("related_purls", purls.joinToString(",") { it.trim() })
167168
}
168169

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

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

Lines changed: 10 additions & 2 deletions
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
)
@@ -154,9 +159,12 @@ class ScanOssResultParserTest : WordSpec({
154159
snippets should haveSize(1)
155160
snippets.first().purl shouldBe "pkg:github/kdrag0n/proton_bluecross"
156161

157-
// Verify remaining PURLs are stored in additionalData.
162+
// Verify if related PURLs are stored in additionalData as CSV.
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)