Skip to content

Commit

Permalink
Put package list
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilhe committed Sep 13, 2024
1 parent 8407caa commit c6cbf42
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api-examples/Get CVEs by Gardenlinux Version Packages PUT.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
meta {
name: Get CVEs by Gardenlinux Version Packages PUT
type: http
seq: 8
}

put {
url: {{schema_hostname_port}}/v1/cves/1592.0/packages
body: json
auth: none
}

body:json {
["vim","bash","python3","curl"]
}
11 changes: 11 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ The expected response looks like this:

include::{snippets}/getCveForPackages/http-response.adoc[]

=== Get a list of CVEs for packages by distro via PUT

This endpoint will give you all the CVE for a list of packages in a specified distro.
Package names are provided in the request body in json-encoded form.

include::{snippets}/getCveForPackagesPut/curl-request.adoc[]

The expected response looks like this:

include::{snippets}/getCveForPackagesPut/http-response.adoc[]

=== Get List of Packages

Just gives you a list of packages in a given distribution.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/gardenlinux/glvd/GlvdController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ ResponseEntity<List<SourcePackageCve>> getCvePackages(
return ResponseEntity.ok().body(cveForPackages);
}

@PutMapping("/cves/{gardenlinuxVersion}/packages")
ResponseEntity<List<SourcePackageCve>> getCvePackagesxx(
@PathVariable final String gardenlinuxVersion,
@RequestBody final PackageList packages,
@RequestParam(defaultValue = "cveId") final String sortBy,
@RequestParam(defaultValue = "ASC") final String sortOrder,
@RequestParam(required = false) final String pageNumber,
@RequestParam(required = false) final String pageSize
) {
var packageList = packages.toString();
var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList, new SortAndPageOptions(sortBy, sortOrder, pageNumber, pageSize));
return ResponseEntity.ok().body(cveForPackages);
}

@GetMapping("/packages/{sourcePackage}")
ResponseEntity<List<SourcePackageCve>> packageWithVulnerabilities(
@PathVariable final String sourcePackage,
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/io/gardenlinux/glvd/PackageList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.gardenlinux.glvd;

import java.util.List;

public class PackageList {

private List<String> packageNames;

public PackageList() {
}

public PackageList(List<String> packageNames) {
this.packageNames = packageNames;
}

public List<String> getPackageNames() {
return packageNames;
}

@Override
public String toString() {
return String.join(",", packageNames);
}
}
22 changes: 22 additions & 0 deletions src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ public void shouldReturnCvesForListOfPackages() {
.then().statusCode(HttpStatus.SC_OK);
}

@Test
public void shouldReturnCvesForPutListOfPackages() {
var packageList = """
{
"packageNames": [
"vim",
"bash",
"python3",
"curl"
]
}""";

given(this.spec).accept("application/json")
.filter(document("getCveForPackagesPut",
preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()),
preprocessResponse(prettyPrint())))
.contentType("application/json")
.body(packageList)
.when().port(this.port).put("/v1/cves/1592.0/packages?pageNumber=4&pageSize=2")
.then().statusCode(HttpStatus.SC_OK);
}

@Test
public void shouldGetPackagesForDistro() {
given(this.spec).accept("application/json")
Expand Down

0 comments on commit c6cbf42

Please sign in to comment.