Skip to content

Commit

Permalink
Add api endpoint to query cve details with contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilhe committed Jan 9, 2025
1 parent 0e549b9 commit 114dad6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ include::{snippets}/getPackagesByVulnerability/curl-request.adoc[]
The expected response looks like this:

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

=== Get CVE Details with Contexts

Give information on a CVE by CVE ID

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

The expected response looks like this:

include::{snippets}/getCveDetailsWithContexts/http-response.adoc[]
9 changes: 9 additions & 0 deletions src/main/java/io/gardenlinux/glvd/GlvdController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.gardenlinux.glvd;

import io.gardenlinux.glvd.db.CveDetailsWithContext;
import io.gardenlinux.glvd.db.SourcePackage;
import io.gardenlinux.glvd.db.SourcePackageCve;
import jakarta.annotation.Nonnull;
Expand Down Expand Up @@ -120,4 +121,12 @@ ResponseEntity<List<SourcePackageCve>> packagesByVulnerability(
);
}

@GetMapping("/cveDetails/{cveId}")
ResponseEntity<CveDetailsWithContext> cveDetails(@PathVariable final String cveId) {
var cveDetails = glvdService.getCveDetails(cveId);
var cveContexts = glvdService.getCveContexts(cveId);

return ResponseEntity.ok(new CveDetailsWithContext(cveDetails, cveContexts));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.gardenlinux.glvd.db;

import java.util.List;

public record CveDetailsWithContext(CveDetails details, List<CveContext> contexts) {
}
10 changes: 10 additions & 0 deletions src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ public void shouldGetPackagesByVulnerability() {
.then().statusCode(200);
}

@Test
public void shouldGetCveDetailsWithContexts() {
given(this.spec).accept("application/json")
.filter(document("getCveDetailsWithContexts",
preprocessRequest(modifyUris().scheme("https").host("glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com").removePort()),
preprocessResponse(prettyPrint())))
.when().port(this.port).get("/v1/cveDetails/CVE-2023-50387")
.then().statusCode(200);
}

}

0 comments on commit 114dad6

Please sign in to comment.