-
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.
Implement get cve for packages endpoint and get rid of parsing db (#13)
Parsing the db entities into business domain objects does not seem to bring any upside in our use-case.
- Loading branch information
Showing
22 changed files
with
298 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
meta { | ||
name: Get CVE by Id | ||
type: http | ||
seq: 2 | ||
} | ||
|
||
get { | ||
url: http://localhost:8080/v1/cves/CVE-2024-1547 | ||
body: none | ||
auth: none | ||
} |
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 @@ | ||
meta { | ||
name: Get CVEs by Distro Codename Packages | ||
type: http | ||
seq: 4 | ||
} | ||
|
||
get { | ||
url: http://localhost:8080/v1/cves/debian_linux/bookworm/packages/vim,firefox-esr | ||
body: none | ||
auth: none | ||
} |
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 @@ | ||
meta { | ||
name: Get CVEs by Distro Codename | ||
type: http | ||
seq: 3 | ||
} | ||
|
||
get { | ||
url: http://localhost:8080/v1/cves/debian_linux/bookworm | ||
body: none | ||
auth: none | ||
} |
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 @@ | ||
meta { | ||
name: Get CVEs by Distro Version Packages | ||
type: http | ||
seq: 5 | ||
} | ||
|
||
get { | ||
url: http://localhost:8080/v1/cves/debian_linux/version/12/packages/vim,firefox-esr | ||
body: none | ||
auth: none | ||
} |
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 @@ | ||
Get https://www.usebruno.com to use those api example requests to play with the api. |
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,9 @@ | ||
{ | ||
"version": "1", | ||
"name": "glvd", | ||
"type": "collection", | ||
"ignore": [ | ||
"node_modules", | ||
".git" | ||
] | ||
} |
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
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 |
---|---|---|
|
@@ -65,4 +65,4 @@ public int hashCode() { | |
return result; | ||
} | ||
|
||
} | ||
} |
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,27 +1,85 @@ | ||
package io.gardenlinux.glvd.db; | ||
|
||
import io.gardenlinux.glvd.dto.Cve; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface CveRepository extends JpaRepository<CveEntity, String> { | ||
|
||
@Query(value = """ | ||
SELECT | ||
all_cve.* | ||
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 | ||
deb_cve.deb_source AS source_package, | ||
all_cve.cve_id AS cve_id, | ||
all_cve."data" ->> 'published' AS cve_published_date | ||
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_product = :product AND | ||
dist_cpe.deb_codename = :codename AND | ||
deb_cve.debsec_vulnerable = TRUE | ||
ORDER BY | ||
all_cve.cve_id | ||
""", nativeQuery = true) | ||
List<String> cvesForDistribution(@Param("product") String product, @Param("codename") String codename); | ||
|
||
@Query(value = """ | ||
SELECT | ||
deb_cve.deb_source AS source_package, | ||
all_cve.cve_id AS cve_id, | ||
all_cve."data" ->> 'published' AS cve_published_date | ||
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_product = :product AND | ||
dist_cpe.cpe_version = :version AND | ||
deb_cve.debsec_vulnerable = TRUE | ||
ORDER BY | ||
all_cve.cve_id | ||
""", nativeQuery = true) | ||
List<CveEntity> cvesForDistribution(String vendor, String product, String codename); | ||
List<String> cvesForDistributionVersion(@Param("product") String product, @Param("version") String version); | ||
|
||
@Query(value = """ | ||
SELECT | ||
deb_cve.deb_source AS source_package, | ||
all_cve.cve_id AS cve_id, | ||
all_cve."data" ->> 'published' AS cve_published_date | ||
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_product = :product AND | ||
dist_cpe.deb_codename = :codename AND | ||
deb_cve.deb_source = ANY(:packages ::TEXT[]) AND | ||
deb_cve.debsec_vulnerable = TRUE | ||
ORDER BY | ||
all_cve.cve_id | ||
""", nativeQuery = true) | ||
List<String> cvesForPackageList(@Param("product") String product, @Param("codename") String codename, @Param("packages") String packages); | ||
|
||
@Query(value = """ | ||
SELECT | ||
deb_cve.deb_source AS source_package, | ||
all_cve.cve_id AS cve_id, | ||
all_cve."data" ->> 'published' AS cve_published_date | ||
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_product = :product AND | ||
dist_cpe.cpe_version = :version AND | ||
deb_cve.deb_source = ANY(:packages ::TEXT[]) AND | ||
deb_cve.debsec_vulnerable = TRUE | ||
ORDER BY | ||
all_cve.cve_id | ||
""", nativeQuery = true) | ||
List<String> cvesForPackageListVersion(@Param("product") String product, @Param("version") String version, @Param("packages") String packages); | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/io/gardenlinux/glvd/db/SourcePackageCve.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,64 @@ | ||
package io.gardenlinux.glvd.db; | ||
|
||
import jakarta.annotation.Nonnull; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
public class SourcePackageCve { | ||
|
||
@Id | ||
@Column(name = "cve_id", nullable = false) | ||
private String id; | ||
|
||
@Column(name = "cve_published_date", nullable = false) | ||
@Nonnull | ||
private String cvePublishedDate; | ||
|
||
@Column(name = "source_package", nullable = false) | ||
@Nonnull | ||
private String sourcePackage; | ||
|
||
public SourcePackageCve() { | ||
} | ||
|
||
public SourcePackageCve(String id, @Nonnull String cvePublishedDate, @Nonnull String sourcePackage) { | ||
this.id = id; | ||
this.cvePublishedDate = cvePublishedDate; | ||
this.sourcePackage = sourcePackage; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Nonnull | ||
public String getCvePublishedDate() { | ||
return cvePublishedDate; | ||
} | ||
|
||
@Nonnull | ||
public String getSourcePackage() { | ||
return sourcePackage; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
SourcePackageCve that = (SourcePackageCve) o; | ||
return Objects.equals(id, that.id) && cvePublishedDate.equals(that.cvePublishedDate) && sourcePackage.equals(that.sourcePackage); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hashCode(id); | ||
result = 31 * result + cvePublishedDate.hashCode(); | ||
result = 31 * result + sourcePackage.hashCode(); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.