-
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
0caeac1
commit 34d2bc8
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
libs/cti/src/cves/application/create_one/create_cve_command.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,33 @@ | ||
use cqrs::domain::command::Command; | ||
|
||
|
||
pub struct CreateCveCommand { | ||
pub id: Option<String>, | ||
pub state: Option<String>, | ||
pub date_published: Option<String>, | ||
pub description: Option<String>, | ||
} | ||
|
||
impl CreateCveCommand { | ||
pub const COMMAND_TYPE: &'static str = "[email protected]"; | ||
|
||
pub fn new(id: Option<String>, state: Option<String>, date_published: Option<String>, description: Option<String>) -> CreateCveCommand { | ||
|
||
CreateCveCommand { | ||
id, | ||
state, | ||
date_published, | ||
description, | ||
} | ||
} | ||
} | ||
|
||
impl Command for CreateCveCommand { | ||
fn command_type(&self) -> String { | ||
CreateCveCommand::COMMAND_TYPE.to_string() | ||
} | ||
|
||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
} |
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,39 @@ | ||
use std::sync::Arc; | ||
|
||
use events::domain::event_bus::EventBus; | ||
use tracing::debug; | ||
|
||
use crate::{cves::domain::{entities::{cve::Cve, cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState}, events::cve_created_event::CveCreatedEvent, repositories::cve_repository::CveRepository}, shared::domain::errors::DomainError}; | ||
|
||
|
||
|
||
pub struct CryptoKeyCreator<R: CveRepository, E: EventBus> { | ||
repository: Arc<R>, | ||
event_bus: Arc<E>, | ||
} | ||
|
||
impl<R: CveRepository, E: EventBus> CryptoKeyCreator<R, E> { | ||
pub fn new(cve_repository: Arc<R>, event_bus: Arc<E>) -> CryptoKeyCreator<R, E> { | ||
CryptoKeyCreator { repository: cve_repository, event_bus } | ||
} | ||
|
||
pub async fn run( | ||
&self, | ||
id: CveId, | ||
state: CveState, | ||
date_published: CvePublicationDate, | ||
description: CveDescription, | ||
) -> Result<(), DomainError> { | ||
debug!("Starting CVE creation"); | ||
let key = Cve::new(id.clone(), state.clone(), date_published.clone(), description.clone()); | ||
let res = self.repository.create_one(&key).await; | ||
if res.is_err() { | ||
debug!("Error creating CVE with id: {}", id.value()); | ||
return Err(res.err().unwrap()); | ||
} | ||
let created_event = CveCreatedEvent::new_shared(id.clone(), state, date_published, description); | ||
self.event_bus.publish(created_event).await; | ||
debug!("CVE with id: {} created", id.value()); | ||
Ok(()) | ||
} | ||
} |
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,3 @@ | ||
pub mod create_cve_command; | ||
|
||
pub mod cve_creator; |
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,4 +1,5 @@ | ||
|
||
pub trait Command { | ||
fn command_type(&self) -> String; | ||
fn as_any (&self) -> &dyn std::any::Any; | ||
} |