-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into container-image
- Loading branch information
Showing
18 changed files
with
395 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
= Garden Linux Vulnerability Database Rest API | ||
Garden Linux Authors; | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
|
||
== API Endpoints | ||
|
||
This document describes the HTTP API endpoints of Garden Linux Vulnerability Database. | ||
|
||
CAUTION: This document and the API are work in progress and subject to change at any time. | ||
|
||
=== Check running app | ||
|
||
For verifying that the app is running and has a connection to the database, you may query the `readiness` endpoint: | ||
|
||
include::{snippets}/readiness/curl-request.adoc[] | ||
|
||
The expected response looks like this: | ||
|
||
include::{snippets}/readiness/http-response.adoc[] | ||
|
||
=== Get a CVE by id | ||
|
||
To query a single CVE by its id, you maye use the `cves` endpoint: | ||
|
||
include::{snippets}/getCve/curl-request.adoc[] | ||
|
||
The expected response looks like this: | ||
|
||
include::{snippets}/getCve/http-response.adoc[] | ||
|
||
=== Get a list of CVEs by distro | ||
|
||
To query all CVEs for a given distribution, you may use this endpoint: | ||
|
||
include::{snippets}/getCveForDistro/curl-request.adoc[] | ||
|
||
The expected response looks like this: | ||
|
||
include::{snippets}/getCveForDistro/http-response.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import io.gardenlinux.glvd.dto.Readiness; | ||
import io.gardenlinux.glvd.exceptions.DbNotConnectedException; | ||
import jakarta.annotation.Nonnull; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class AppController { | ||
|
||
@Nonnull | ||
private final GlvdService glvdService; | ||
|
||
public AppController(@Nonnull GlvdService glvdService) { | ||
this.glvdService = glvdService; | ||
} | ||
|
||
@GetMapping("/readiness") | ||
public Readiness readiness() throws DbNotConnectedException { | ||
return glvdService.getReadiness(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
package io.gardenlinux.glvd; | ||
|
||
import io.gardenlinux.glvd.db.CveRepository; | ||
import io.gardenlinux.glvd.db.HealthCheckRepository; | ||
import io.gardenlinux.glvd.dto.Cve; | ||
import io.gardenlinux.glvd.dto.Readiness; | ||
import io.gardenlinux.glvd.exceptions.DbNotConnectedException; | ||
import io.gardenlinux.glvd.exceptions.NotFoundException; | ||
import jakarta.annotation.Nonnull; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class GlvdService { | ||
|
||
@Nonnull | ||
private final CveRepository cveRepository; | ||
|
||
public GlvdService(@Nonnull CveRepository cveRepository) { | ||
@Nonnull | ||
private final HealthCheckRepository healthCheckRepository; | ||
|
||
public GlvdService(@Nonnull CveRepository cveRepository, @Nonnull HealthCheckRepository healthCheckRepository) { | ||
this.cveRepository = cveRepository; | ||
this.healthCheckRepository = healthCheckRepository; | ||
} | ||
|
||
public Cve getCve(String cveId) { | ||
var cve = cveRepository.findById(cveId); | ||
return cve.orElseThrow(); | ||
public Readiness getReadiness() throws DbNotConnectedException { | ||
try { | ||
var connection = healthCheckRepository.checkDbConnection(); | ||
return new Readiness(connection); | ||
} catch (Exception e) { | ||
throw new DbNotConnectedException(e); | ||
} | ||
} | ||
|
||
public Cve getCve(String cveId) throws NotFoundException { | ||
var cveEntity = cveRepository.findById(cveId).orElseThrow(NotFoundException::new); | ||
// Todo: more specific transformation from db type 'cve' to response type 'cve' | ||
return new Cve(cveEntity.getId(), cveEntity.getLastModified(), cveEntity.getData()); | ||
|
||
} | ||
|
||
public List<String> getCveForDistribution(String vendor, String product, String codename) { | ||
return cveRepository.cvesForDistribution(vendor, product, codename); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.gardenlinux.glvd.db; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
public interface CveRepository extends JpaRepository<CveEntity, String> { | ||
|
||
@Query(value = """ | ||
SELECT | ||
all_cve.data AS cveEntity | ||
FROM | ||
all_cve | ||
INNER JOIN deb_cve USING (cve_id) | ||
INNER JOIN dist_cpe ON (deb_cve.dist_id = dist_cpe.id) | ||
WHERE | ||
dist_cpe.cpe_vendor = ?1 AND | ||
dist_cpe.cpe_product = ?2 and | ||
dist_cpe.deb_codename = ?3 | ||
ORDER BY | ||
all_cve.cve_id | ||
""", nativeQuery = true) | ||
List<String> cvesForDistribution(String vendor, String product, String codename); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/gardenlinux/glvd/db/HealthCheckEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.gardenlinux.glvd.db; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class HealthCheckEntity { | ||
|
||
@Id | ||
private String id; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/gardenlinux/glvd/db/HealthCheckRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.gardenlinux.glvd.db; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface HealthCheckRepository extends JpaRepository<HealthCheckEntity, String> { | ||
|
||
@Query(value = "SELECT TRUE", nativeQuery = true) | ||
String checkDbConnection(); | ||
|
||
} |
Oops, something went wrong.