Skip to content

Commit

Permalink
feat(fossid-webapp): Support two new API functions
Browse files Browse the repository at this point in the history
This commit adds support for the functions `mark_as_identified` and
`unmark_as_identified`.

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.io>
  • Loading branch information
nnobelis authored and sschuberth committed Aug 30, 2023
1 parent d0063eb commit 9d022a4
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
50 changes: 50 additions & 0 deletions clients/fossid-webapp/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,56 @@ suspend fun FossIdRestService.generateReport(
}
}

/**
* Mark the given file with [path] as identified for the given [scanCode].
*
* The HTTP request is sent with [user] and [apiKey] as credentials.
*/
suspend fun FossIdRestService.markAsIdentified(
user: String,
apiKey: String,
scanCode: String,
path: String,
isDirectory: Boolean
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
return markAsIdentified(
PostRequestBody(
"mark_as_identified",
FILES_AND_FOLDERS_GROUP,
user,
apiKey,
mapOf("scan_code" to scanCode, "path" to base64Path, "is_directory" to directoryFlag)
)
)
}

/**
* Unmark the given file with [path] as identified for the given [scanCode].
*
* The HTTP request is sent with [user] and [apiKey] as credentials.
*/
suspend fun FossIdRestService.unmarkAsIdentified(
user: String,
apiKey: String,
scanCode: String,
path: String,
isDirectory: Boolean
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
return unmarkAsIdentified(
PostRequestBody(
"unmark_as_identified",
FILES_AND_FOLDERS_GROUP,
user,
apiKey,
mapOf("scan_code" to scanCode, "path" to base64Path, "is_directory" to directoryFlag)
)
)
}

/**
* If this string starts with [prefix], return the string without the prefix, otherwise return [missingPrefixValue].
*/
Expand Down
6 changes: 6 additions & 0 deletions clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ interface FossIdRestService {
@POST("api.php")
suspend fun generateReport(@Body body: PostRequestBody): Response<ResponseBody>

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

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

@GET("index.php?form=login")
suspend fun getLoginPage(): ResponseBody
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "86626b21-c67d-44d8-9861-f06283e717f3",
"name" : "apiphp",
"request" : {
"url" : "/api.php",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{ \"action\" : \"mark_as_identified\", \"group\" : \"files_and_folders\", \"data\" : { \"username\":\"\", \"key\":\"\", \"scan_code\" : \"semver4j_20201203_090342\", \"path\" : \"c3JjL21haW4vamF2YS9jb20vdmR1cm1vbnQvc2VtdmVyNGovUmFuZ2UuamF2YQ==\", \"is_directory\": \"0\" }}",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 200,
"body" : "{ \"operation\": \"files_and_folders_mark_as_identified\", \"status\": \"1\", \"data\": { \"operation\": \"files_mark_as_identified\", \"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" : "86626b21-c67d-44d8-9861-f06283e717f3",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "86626b21-c67d-44d8-9861-f06283e717f3",
"name" : "apiphp",
"request" : {
"url" : "/api.php",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{ \"action\" : \"unmark_as_identified\", \"group\" : \"files_and_folders\", \"data\" : { \"username\":\"\", \"key\":\"\", \"scan_code\" : \"semver4j_20201203_090342\", \"path\" : \"c3JjL21haW4vamF2YS9jb20vdmR1cm1vbnQvc2VtdmVyNGovUmFuZ2UuamF2YQ==\", \"is_directory\": \"0\" }}",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 200,
"body" : "{ \"operation\": \"files_and_folders_unmark_as_identified\", \"status\": \"1\", \"data\": { \"operation\": \"files_unmark_as_identified\", \"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" : "86626b21-c67d-44d8-9861-f06283e717f3",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ import org.ossreviewtoolkit.clients.fossid.listPendingFiles
import org.ossreviewtoolkit.clients.fossid.listScanResults
import org.ossreviewtoolkit.clients.fossid.listScansForProject
import org.ossreviewtoolkit.clients.fossid.listSnippets
import org.ossreviewtoolkit.clients.fossid.markAsIdentified
import org.ossreviewtoolkit.clients.fossid.model.Scan
import org.ossreviewtoolkit.clients.fossid.model.identification.identifiedFiles.IdentifiedFile
import org.ossreviewtoolkit.clients.fossid.model.identification.ignored.IgnoredFile
import org.ossreviewtoolkit.clients.fossid.model.identification.markedAsIdentified.MarkedAsIdentifiedFile
import org.ossreviewtoolkit.clients.fossid.model.result.FossIdScanResult
import org.ossreviewtoolkit.clients.fossid.model.result.Snippet
import org.ossreviewtoolkit.clients.fossid.unmarkAsIdentified

private const val PROJECT_CODE_1 = "semver4j"
private const val PROJECT_CODE_2 = "semver4j_2"
Expand Down Expand Up @@ -264,4 +266,28 @@ class FossIdClientReturnTypeTest : StringSpec({
error shouldBe "Classes.TableRepository.row_not_found"
}
}

"A file can be marked as identified" {
service.markAsIdentified(
"",
"",
SCAN_CODE_1,
"src/main/java/com/vdurmont/semver4j/Range.java",
false
).shouldNotBeNull().run {
checkResponse("mark file as identified")
}
}

"A file can be unmarked as identified" {
service.unmarkAsIdentified(
"",
"",
SCAN_CODE_1,
"src/main/java/com/vdurmont/semver4j/Range.java",
false
).shouldNotBeNull().run {
checkResponse("unmark file as identified")
}
}
})

0 comments on commit 9d022a4

Please sign in to comment.