Skip to content

Commit 2654563

Browse files
committed
feat: add the "reserved" field for vulnerabilities
Closes #964
1 parent 030790f commit 2654563

File tree

19 files changed

+132
-2
lines changed

19 files changed

+132
-2
lines changed

entity/src/advisory_vulnerability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct Model {
1313
pub title: Option<String>,
1414
pub summary: Option<String>,
1515
pub description: Option<String>,
16+
pub reserved_date: Option<OffsetDateTime>,
1617
pub discovery_date: Option<OffsetDateTime>,
1718
pub release_date: Option<OffsetDateTime>,
1819
pub cwes: Option<Vec<String>>,

entity/src/vulnerability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Model {
1010
#[sea_orm(primary_key)]
1111
pub id: String,
1212
pub title: Option<String>,
13+
pub reserved: Option<OffsetDateTime>,
1314
pub published: Option<OffsetDateTime>,
1415
pub modified: Option<OffsetDateTime>,
1516
pub withdrawn: Option<OffsetDateTime>,

migration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mod m0000660_purl_id_indexes;
8686
mod m0000670_version_cmp;
8787
mod m0000680_fix_update_deprecated_advisory;
8888
mod m0000690_alter_sbom_details;
89+
mod m0000700_advisory_add_reserved;
8990

9091
pub struct Migrator;
9192

@@ -179,6 +180,7 @@ impl MigratorTrait for Migrator {
179180
Box::new(m0000670_version_cmp::Migration),
180181
Box::new(m0000680_fix_update_deprecated_advisory::Migration),
181182
Box::new(m0000690_alter_sbom_details::Migration),
183+
Box::new(m0000700_advisory_add_reserved::Migration),
182184
]
183185
}
184186
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
manager
10+
.alter_table(
11+
Table::alter()
12+
.table(Vulnerability::Table)
13+
.add_column(
14+
ColumnDef::new(Vulnerability::Reserved)
15+
.timestamp_with_time_zone()
16+
.to_owned(),
17+
)
18+
.to_owned(),
19+
)
20+
.await?;
21+
22+
manager
23+
.alter_table(
24+
Table::alter()
25+
.table(AdvisoryVulnerability::Table)
26+
.add_column(
27+
ColumnDef::new(AdvisoryVulnerability::ReservedDate)
28+
.timestamp_with_time_zone()
29+
.to_owned(),
30+
)
31+
.to_owned(),
32+
)
33+
.await?;
34+
35+
Ok(())
36+
}
37+
38+
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
39+
manager
40+
.alter_table(
41+
Table::alter()
42+
.table(AdvisoryVulnerability::Table)
43+
.drop_column(AdvisoryVulnerability::ReservedDate)
44+
.to_owned(),
45+
)
46+
.await?;
47+
48+
manager
49+
.alter_table(
50+
Table::alter()
51+
.table(Vulnerability::Table)
52+
.drop_column(Vulnerability::Reserved)
53+
.to_owned(),
54+
)
55+
.await?;
56+
57+
Ok(())
58+
}
59+
}
60+
61+
#[derive(DeriveIden)]
62+
enum Vulnerability {
63+
Table,
64+
Reserved,
65+
}
66+
67+
#[derive(DeriveIden)]
68+
enum AdvisoryVulnerability {
69+
Table,
70+
ReservedDate,
71+
}

modules/fundamental/src/purl/model/details/purl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl PurlAdvisory {
137137
let vulnerability = vuln.unwrap_or(vulnerability::Model {
138138
id: status.vulnerability_id.clone(),
139139
title: None,
140+
reserved: None,
140141
published: None,
141142
modified: None,
142143
withdrawn: None,

modules/fundamental/src/vulnerability/endpoints/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ async fn one_vulnerability(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
172172
VulnerabilityInformation {
173173
title: Some("Something wicked this way comes".to_string()),
174174
published: Some(OffsetDateTime::now_utc()),
175+
reserved: None,
175176
modified: None,
176177
withdrawn: None,
177178
cwes: None,
@@ -268,6 +269,7 @@ async fn delete_vulnerability(ctx: &TrustifyContext) -> Result<(), anyhow::Error
268269
"CVE-123",
269270
VulnerabilityInformation {
270271
title: Some("Something wicked this way comes".to_string()),
272+
reserved: None,
271273
published: Some(OffsetDateTime::now_utc()),
272274
modified: None,
273275
withdrawn: None,

modules/fundamental/src/vulnerability/model/details/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ impl VulnerabilityDetails {
6464
identifier: vulnerability.id.clone(),
6565
title: None,
6666
description: None,
67+
reserved: None,
6768
published: None,
6869
modified: None,
6970
withdrawn: None,

modules/fundamental/src/vulnerability/model/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub struct VulnerabilityHead {
3131
#[schema(required)]
3232
pub description: Option<String>,
3333

34+
/// The date (in RFC3339 format) of when the vulnerability identifier was reserved, if any.
35+
#[schema(required)]
36+
#[serde(with = "time::serde::rfc3339::option")]
37+
pub reserved: Option<OffsetDateTime>,
38+
3439
/// The date (in RFC3339 format) of when the vulnerability was published, if any.
3540
#[schema(required)]
3641
#[serde(with = "time::serde::rfc3339::option")]
@@ -92,6 +97,7 @@ impl VulnerabilityHead {
9297
identifier: entity.id.clone(),
9398
title: entity.title.clone(),
9499
description,
100+
reserved: entity.reserved,
95101
published: entity.published,
96102
modified: entity.modified,
97103
withdrawn: entity.withdrawn,
@@ -110,6 +116,7 @@ impl VulnerabilityHead {
110116
identifier: vuln.id.clone(),
111117
title: advisory_vulnerability.title.clone(),
112118
description: advisory_vulnerability.description.clone(),
119+
reserved: advisory_vulnerability.reserved_date,
113120
published: None,
114121
modified: None,
115122
withdrawn: None,

modules/fundamental/tests/advisory/csaf/delete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ async fn delete_check_vulns(ctx: &TrustifyContext) -> anyhow::Result<()> {
131131
identifier: "CVE-2023-33201".to_string(),
132132
title: None,
133133
description: None,
134+
reserved: None,
134135
published: None,
135136
modified: None,
136137
withdrawn: None,

modules/fundamental/tests/advisory/csaf/reingest.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ async fn change_ps_list_vulns(ctx: &TrustifyContext) -> anyhow::Result<()> {
143143
identifier: "CVE-2023-33201".to_string(),
144144
title: None,
145145
description: None,
146+
reserved: None,
146147
published: None,
147148
modified: None,
148149
withdrawn: None,
@@ -240,6 +241,7 @@ async fn change_ps_list_vulns_all(ctx: &TrustifyContext) -> anyhow::Result<()> {
240241
identifier: "CVE-2023-33201".to_string(),
241242
title: None,
242243
description: None,
244+
reserved: None,
243245
published: None,
244246
modified: None,
245247
withdrawn: None,
@@ -261,6 +263,7 @@ async fn change_ps_list_vulns_all(ctx: &TrustifyContext) -> anyhow::Result<()> {
261263
identifier: "CVE-2023-33201".to_string(),
262264
title: None,
263265
description: None,
266+
reserved: None,
264267
published: None,
265268
modified: None,
266269
withdrawn: None,

0 commit comments

Comments
 (0)