Skip to content

Commit c19999e

Browse files
nnobelissschuberth
authored andcommitted
feat(fossid-webapp): Support a new API function
The function `addComponentIdentification` allows to add a component identification to a pending file. Signed-off-by: Nicolas Nobelis <[email protected]>
1 parent 804d959 commit c19999e

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

clients/fossid-webapp/src/main/kotlin/Extensions.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,45 @@ suspend fun FossIdRestService.addLicenseIdentification(
534534
)
535535
}
536536

537+
/**
538+
* Add component identification for component [componentName]/[componentVersion] to file with [path] for the given
539+
* [scanCode]. If [preserveExistingIdentifications] is true, identification is appended, otherwise it replaces existing
540+
* identifications.
541+
*
542+
* The HTTP request is sent with [user] and [apiKey] as credentials.
543+
*/
544+
@Suppress("LongParameterList")
545+
suspend fun FossIdRestService.addComponentIdentification(
546+
user: String,
547+
apiKey: String,
548+
scanCode: String,
549+
path: String,
550+
componentName: String,
551+
componentVersion: String,
552+
isDirectory: Boolean,
553+
preserveExistingIdentifications: Boolean = true
554+
): EntityResponseBody<Nothing> {
555+
val base64Path = base64Encoder.encodeToString(path.toByteArray())
556+
val directoryFlag = if (isDirectory) "1" else "0"
557+
val preserveExistingIdentificationsFlag = if (preserveExistingIdentifications) "1" else "0"
558+
return addComponentIdentification(
559+
PostRequestBody(
560+
"set_identification_component",
561+
FILES_AND_FOLDERS_GROUP,
562+
user,
563+
apiKey,
564+
mapOf(
565+
"scan_code" to scanCode,
566+
"path" to base64Path,
567+
"is_directory" to directoryFlag,
568+
"component_name" to componentName,
569+
"component_version" to componentVersion,
570+
"preserve_existing_identifications" to preserveExistingIdentificationsFlag
571+
)
572+
)
573+
)
574+
}
575+
537576
/**
538577
* Add a [comment] to file with [path] for the given [scanCode].
539578
*

clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ interface FossIdRestService {
289289
@POST("api.php")
290290
suspend fun addLicenseIdentification(@Body body: PostRequestBody): EntityResponseBody<Nothing>
291291

292+
@POST("api.php")
293+
suspend fun addComponentIdentification(@Body body: PostRequestBody): EntityResponseBody<Nothing>
294+
292295
@POST("api.php")
293296
suspend fun addFileComment(@Body body: PostRequestBody): EntityResponseBody<Nothing>
294297

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id" : "c5ddf15c-cbde-485b-aeb3-8af89302375c",
3+
"name" : "apiphp",
4+
"request" : {
5+
"url" : "/api.php",
6+
"method" : "POST",
7+
"bodyPatterns" : [ {
8+
"equalToJson" : "{ \"action\": \"set_identification_component\", \"group\": \"files_and_folders\", \"data\": { \"username\": \"\", \"key\": \"\", \"scan_code\": \"semver4j_20201203_090342\", \"path\": \"c3JjL21haW4vamF2YS9jb20vdmR1cm1vbnQvc2VtdmVyNGovUmFuZ2UuamF2YQ==\", \"is_directory\": \"0\", \"component_name\": \"semver4j\", \"component_version\": \"3.0.0\", \"preserve_existing_identifications\": \"0\" }}",
9+
"ignoreArrayOrder" : true,
10+
"ignoreExtraElements" : true
11+
} ]
12+
},
13+
"response" : {
14+
"status" : 200,
15+
"body" : "{ \"operation\": \"files_and_folders_set_identification_component\", \"status\": \"1\", \"data\": { \"operation\": \"files_set_identification_component\", \"status\": \"1\", \"data\": null, \"message\": \"Success\" }, \"message\": \"Success\"}",
16+
"headers" : {
17+
"Content-Type" : "text/html; charset=UTF-8",
18+
"Date" : "Thu, 05 Dec 2021 11:54:04 GMT",
19+
"Server" : "Apache/2.4.38 (Debian)",
20+
"Vary" : "Accept-Encoding"
21+
}
22+
},
23+
"uuid" : "c5ddf15c-cbde-485b-aeb3-8af89302375c",
24+
"persistent" : true,
25+
"insertionIndex" : 1
26+
}

clients/fossid-webapp/src/test/kotlin/FossIdClientReturnTypeTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ class FossIdClientReturnTypeTest : StringSpec({
294294
}
295295
}
296296

297+
"A component identification can be added to a file" {
298+
service.addComponentIdentification(
299+
"",
300+
"",
301+
SCAN_CODE_1,
302+
"src/main/java/com/vdurmont/semver4j/Range.java",
303+
"semver4j",
304+
"3.0.0",
305+
isDirectory = false,
306+
preserveExistingIdentifications = false
307+
).shouldNotBeNull().run {
308+
checkResponse("add component identification")
309+
}
310+
}
311+
297312
"A comment can be added to a file" {
298313
service.addFileComment(
299314
"",

0 commit comments

Comments
 (0)