Skip to content

Commit

Permalink
Simplify HTTP API (#35)
Browse files Browse the repository at this point in the history
Previously the api assumed you might query other linux systems than Garden Linux.
  • Loading branch information
fwilhe authored Sep 12, 2024
1 parent cb366f6 commit cba4d99
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api-examples/Get CVEs by Gardenlinux Version Packages.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/cves/gardenlinux/1592.0/packages/vim,bash,python3,curl
url: {{schema_hostname_port}}/v1/cves/1592.0/packages/vim,bash,python3,curl
body: none
auth: none
}
2 changes: 1 addition & 1 deletion api-examples/Get CVEs by Gardenlinux Version.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/cves/gardenlinux/1592.0?sortBy=cveId
url: {{schema_hostname_port}}/v1/cves/1592.0?sortBy=cveId
body: none
auth: none
}
Expand Down
2 changes: 1 addition & 1 deletion api-examples/Get Packages by Vulnerability.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/packages/distro/gardenlinux/1443.0/CVE-2023-50387
url: {{schema_hostname_port}}/v1/distro/1443.0/CVE-2023-50387
body: none
auth: none
}
2 changes: 1 addition & 1 deletion api-examples/Get Vulnerabilities by Package by Version.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/packages/vim/2:9.1.0496-1+b1
url: {{schema_hostname_port}}/v1/packages/vim/2:9.1.0496-1+b1
body: none
auth: none
}
2 changes: 1 addition & 1 deletion api-examples/Get Vulnerabilities by Package.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/packages/vim
url: {{schema_hostname_port}}/v1/packages/vim
body: none
auth: none
}
2 changes: 1 addition & 1 deletion api-examples/List Packages in Distro.bru
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ meta {
}

get {
url: http://{{hostname}}:{{port}}/v1/packages/distro/gardenlinux/1592.0?sortBy=sourcePackageName&sortOrder=ASC
url: {{schema_hostname_port}}/v1/distro/gardenlinux/1592.0?sortBy=sourcePackageName&sortOrder=ASC
body: none
auth: none
}
Expand Down
3 changes: 3 additions & 0 deletions api-examples/environments/gardener.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
schema_hostname_port: https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com
}
3 changes: 1 addition & 2 deletions api-examples/environments/local.bru
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vars {
hostname: localhost
port: 8080
schema_hostname_port: http://localhost:8080
}
24 changes: 12 additions & 12 deletions src/main/java/io/gardenlinux/glvd/GlvdController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GlvdController(@Nonnull GlvdService glvdService) {
this.glvdService = glvdService;
}

@GetMapping("/cves/{distro}/{gardenlinuxVersion}")
@GetMapping("/cves/{gardenlinuxVersion}")
ResponseEntity<List<SourcePackageCve>> getCveDistro(
@PathVariable final String gardenlinuxVersion,
@RequestParam(defaultValue = "cveId") final String sortBy,
Expand All @@ -29,22 +29,13 @@ ResponseEntity<List<SourcePackageCve>> getCveDistro(
return ResponseEntity.ok().body(glvdService.getCveForDistribution(gardenlinuxVersion, sortBy, sortOrder));
}

@GetMapping("/cves/{distro}/{gardenlinuxVersion}/packages/{packageList}")
@GetMapping("/cves/{gardenlinuxVersion}/packages/{packageList}")
ResponseEntity<List<SourcePackageCve>> getCvePackages(
@PathVariable final String gardenlinuxVersion, @PathVariable final String packageList) {
var cveForPackages = glvdService.getCveForPackages(gardenlinuxVersion, packageList);
return ResponseEntity.ok().body(cveForPackages);
}

@GetMapping("/packages/distro/{distro}/{gardenlinuxVersion}")
ResponseEntity<List<SourcePackage>> packagesForDistro(
@PathVariable final String gardenlinuxVersion,
@RequestParam(defaultValue = "sourcePackageName") final String sortBy,
@RequestParam(defaultValue = "ASC") final String sortOrder
) {
return ResponseEntity.ok(glvdService.getPackagesForDistro(gardenlinuxVersion, sortBy, sortOrder));
}

@GetMapping("/packages/{sourcePackage}")
ResponseEntity<List<SourcePackageCve>> packageWithVulnerabilities(
@PathVariable final String sourcePackage,
Expand All @@ -63,7 +54,16 @@ ResponseEntity<List<SourcePackageCve>> packageWithVulnerabilitiesByVersion(
return ResponseEntity.ok(glvdService.getPackageWithVulnerabilitiesByVersion(sourcePackage, sourcePackageVersion, sortBy));
}

@GetMapping("/packages/distro/{distro}/{gardenlinuxVersion}/{cveId}")
@GetMapping("/distro/{gardenlinuxVersion}")
ResponseEntity<List<SourcePackage>> packagesForDistro(
@PathVariable final String gardenlinuxVersion,
@RequestParam(defaultValue = "sourcePackageName") final String sortBy,
@RequestParam(defaultValue = "ASC") final String sortOrder
) {
return ResponseEntity.ok(glvdService.getPackagesForDistro(gardenlinuxVersion, sortBy, sortOrder));
}

@GetMapping("/distro/{gardenlinuxVersion}/{cveId}")
ResponseEntity<List<SourcePackageCve>> packagesByVulnerability(
@PathVariable final String gardenlinuxVersion,
@PathVariable final String cveId,
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/gardenlinux/glvd/GlvdControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void shouldReturnCvesForGardenlinux() {
.filter(document("getCveForDistro",
preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()),
preprocessResponse(prettyPrint())))
.when().port(this.port).get("/v1/cves/gardenlinux/1592.0?sortBy=cveId&sortOrder=DESC")
.when().port(this.port).get("/v1/cves/1592.0?sortBy=cveId&sortOrder=DESC")
.then().statusCode(HttpStatus.SC_OK);
}

Expand All @@ -89,7 +89,7 @@ public void shouldReturnCvesForListOfPackages() {
.filter(document("getCveForPackages",
preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()),
preprocessResponse(prettyPrint())))
.when().port(this.port).get("/v1/cves/gardenlinux/1592.0/packages/crun,vim")
.when().port(this.port).get("/v1/cves/1592.0/packages/crun,vim")
.then().statusCode(HttpStatus.SC_OK);
}

Expand All @@ -99,7 +99,7 @@ public void shouldGetPackagesForDistro() {
.filter(document("getPackages",
preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()),
preprocessResponse(prettyPrint())))
.when().port(this.port).get("/v1/packages/distro/gardenlinux/1592.0")
.when().port(this.port).get("/v1/distro/1592.0")
.then().statusCode(200);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public void shouldGetPackagesByVulnerability() {
.filter(document("getPackagesByVulnerability",
preprocessRequest(modifyUris().scheme("https").host("glvd.gardenlinux.io").removePort()),
preprocessResponse(prettyPrint())))
.when().port(this.port).get("/v1/packages/distro/gardenlinux/1592.0/CVE-2023-50387")
.when().port(this.port).get("/v1/distro/1592.0/CVE-2023-50387")
.then().statusCode(200).body("[0].cveId", equalTo("CVE-2023-50387"));
}

Expand Down

0 comments on commit cba4d99

Please sign in to comment.