-
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.
- Loading branch information
1 parent
76df204
commit e9efcb2
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
libs/cti/src/breaches/domain/events/breach_created_event.rs
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,122 @@ | ||
use events::domain::domain_event::DomainEvent; | ||
|
||
use crate::{breaches::domain::entities::{breach_id::BreachId, breach_product::BreachProduct, breach_product_type::BreachProductType, breach_product_version::BreachProductVersion, breach_vendor::BreachVendor}, cves::domain::entities::{ | ||
cve_assigner_id::CveAssignerId, cve_assigner_name::CveAssignerName, cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState, cve_updated_date::CveUpdatedDate | ||
}}; | ||
|
||
pub struct BreachCreatedEvent { | ||
pub id: String, | ||
|
||
// Breach data | ||
pub breach_id: BreachId, | ||
|
||
// Product data | ||
pub vendor: BreachVendor, | ||
pub product: BreachProduct, | ||
pub product_version: BreachProductVersion, | ||
pub product_type: BreachProductType, | ||
|
||
// CVE data | ||
pub cve_id: CveId, | ||
pub cve_state: CveState, | ||
pub cve_description: CveDescription, | ||
pub cve_assigner_id: CveAssignerId, | ||
pub cve_assigner_name: CveAssignerName, | ||
pub cve_date_published: CvePublicationDate, | ||
pub cve_date_updated: CveUpdatedDate, | ||
|
||
pub occurred_on: String, | ||
} | ||
|
||
impl BreachCreatedEvent { | ||
pub fn new( | ||
breach_id: &BreachId, | ||
vendor: &BreachVendor, | ||
product: &BreachProduct, | ||
product_version: &BreachProductVersion, | ||
product_type: &BreachProductType, | ||
cve_id: &CveId, | ||
cve_state: &CveState, | ||
cve_description: &CveDescription, | ||
cve_assigner_id: &CveAssignerId, | ||
cve_assigner_name: &CveAssignerName, | ||
cve_date_published: &CvePublicationDate, | ||
cve_date_updated: &CveUpdatedDate, | ||
) -> Self { | ||
let id = uuid::Uuid::new_v4().to_string(); | ||
let occurred_on = chrono::Utc::now().to_rfc3339(); | ||
Self { | ||
id, | ||
breach_id: breach_id.clone(), | ||
vendor: vendor.clone(), | ||
product: product.clone(), | ||
product_version: product_version.clone(), | ||
product_type: product_type.clone(), | ||
cve_id: cve_id.clone(), | ||
cve_state: cve_state.clone(), | ||
cve_description: cve_description.clone(), | ||
cve_assigner_id: cve_assigner_id.clone(), | ||
cve_assigner_name: cve_assigner_name.clone(), | ||
cve_date_published: cve_date_published.clone(), | ||
cve_date_updated: cve_date_updated.clone(), | ||
occurred_on, | ||
} | ||
} | ||
|
||
pub fn new_shared( | ||
breach_id: &BreachId, | ||
vendor: &BreachVendor, | ||
product: &BreachProduct, | ||
product_version: &BreachProductVersion, | ||
product_type: &BreachProductType, | ||
cve_id: &CveId, | ||
cve_state: &CveState, | ||
cve_description: &CveDescription, | ||
cve_assigner_id: &CveAssignerId, | ||
cve_assigner_name: &CveAssignerName, | ||
cve_date_published: &CvePublicationDate, | ||
cve_date_updated: &CveUpdatedDate, | ||
) -> std::sync::Arc<Self> { | ||
std::sync::Arc::new(Self::new( | ||
breach_id, | ||
vendor, | ||
product, | ||
product_version, | ||
product_type, | ||
cve_id, | ||
cve_state, | ||
cve_description, | ||
cve_assigner_id, | ||
cve_assigner_name, | ||
cve_date_published, | ||
cve_date_updated, | ||
)) | ||
} | ||
} | ||
|
||
impl DomainEvent for BreachCreatedEvent { | ||
fn event_type(&self) -> String { | ||
"[email protected]".to_string() | ||
} | ||
} | ||
|
||
impl Clone for BreachCreatedEvent { | ||
fn clone(&self) -> Self { | ||
let mut event = Self::new( | ||
&self.breach_id, | ||
&self.vendor, | ||
&self.product, | ||
&self.product_version, | ||
&self.product_type, | ||
&self.cve_id, | ||
&self.cve_state, | ||
&self.cve_description, | ||
&self.cve_assigner_id, | ||
&self.cve_assigner_name, | ||
&self.cve_date_published, | ||
&self.cve_date_updated, | ||
); | ||
event.occurred_on = self.occurred_on.clone(); | ||
return event; | ||
} | ||
} |
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 @@ | ||
pub mod breach_created_event; |