Skip to content

Commit

Permalink
feat(fossid-webapp): Support a new API function
Browse files Browse the repository at this point in the history
The function `addComponentIdentification` allows to add a component
identification to a pending file.

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis authored and sschuberth committed Oct 11, 2023
1 parent 804d959 commit c19999e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
39 changes: 39 additions & 0 deletions clients/fossid-webapp/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,45 @@ suspend fun FossIdRestService.addLicenseIdentification(
)
}

/**
* Add component identification for component [componentName]/[componentVersion] to file with [path] for the given
* [scanCode]. If [preserveExistingIdentifications] is true, identification is appended, otherwise it replaces existing
* identifications.
*
* The HTTP request is sent with [user] and [apiKey] as credentials.
*/
@Suppress("LongParameterList")
suspend fun FossIdRestService.addComponentIdentification(
user: String,
apiKey: String,
scanCode: String,
path: String,
componentName: String,
componentVersion: String,
isDirectory: Boolean,
preserveExistingIdentifications: Boolean = true
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
val preserveExistingIdentificationsFlag = if (preserveExistingIdentifications) "1" else "0"
return addComponentIdentification(
PostRequestBody(
"set_identification_component",
FILES_AND_FOLDERS_GROUP,
user,
apiKey,
mapOf(
"scan_code" to scanCode,
"path" to base64Path,
"is_directory" to directoryFlag,
"component_name" to componentName,
"component_version" to componentVersion,
"preserve_existing_identifications" to preserveExistingIdentificationsFlag
)
)
)
}

/**
* Add a [comment] to file with [path] for the given [scanCode].
*
Expand Down
3 changes: 3 additions & 0 deletions clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ interface FossIdRestService {
@POST("api.php")
suspend fun addLicenseIdentification(@Body body: PostRequestBody): EntityResponseBody<Nothing>

@POST("api.php")
suspend fun addComponentIdentification(@Body body: PostRequestBody): EntityResponseBody<Nothing>

@POST("api.php")
suspend fun addFileComment(@Body body: PostRequestBody): EntityResponseBody<Nothing>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "c5ddf15c-cbde-485b-aeb3-8af89302375c",
"name" : "apiphp",
"request" : {
"url" : "/api.php",
"method" : "POST",
"bodyPatterns" : [ {
"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\" }}",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 200,
"body" : "{ \"operation\": \"files_and_folders_set_identification_component\", \"status\": \"1\", \"data\": { \"operation\": \"files_set_identification_component\", \"status\": \"1\", \"data\": null, \"message\": \"Success\" }, \"message\": \"Success\"}",
"headers" : {
"Content-Type" : "text/html; charset=UTF-8",
"Date" : "Thu, 05 Dec 2021 11:54:04 GMT",
"Server" : "Apache/2.4.38 (Debian)",
"Vary" : "Accept-Encoding"
}
},
"uuid" : "c5ddf15c-cbde-485b-aeb3-8af89302375c",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ class FossIdClientReturnTypeTest : StringSpec({
}
}

"A component identification can be added to a file" {
service.addComponentIdentification(
"",
"",
SCAN_CODE_1,
"src/main/java/com/vdurmont/semver4j/Range.java",
"semver4j",
"3.0.0",
isDirectory = false,
preserveExistingIdentifications = false
).shouldNotBeNull().run {
checkResponse("add component identification")
}
}

"A comment can be added to a file" {
service.addFileComment(
"",
Expand Down

0 comments on commit c19999e

Please sign in to comment.