diff --git a/apps/cti/src/main.rs b/apps/cti/src/main.rs index ccfdc4d..1335135 100644 --- a/apps/cti/src/main.rs +++ b/apps/cti/src/main.rs @@ -17,7 +17,10 @@ use cti::cves::{ create_one::{ create_cve_command_handler::CreateCveCommandHandler, cve_creator::CveCreator, }, - find_one::{cve_finder::CveFinder, find_cve_q_handler::FindCveQueryHandler}, update_one::{cve_updater::CveUpdater, update_cve_command_handler::UpdateCveCommandHandler}, + find_one::{cve_finder::CveFinder, find_cve_q_handler::FindCveQueryHandler}, + update_one::{ + cve_updater::CveUpdater, update_cve_command_handler::UpdateCveCommandHandler, + }, }, infrastructure::sqlx::sqlx_postgres_cve_repository::SqlxPostgresCveRepository, }; diff --git a/libs/cti/src/breaches/application/mod.rs b/libs/cti/src/breaches/application/mod.rs index e69de29..8b13789 100644 --- a/libs/cti/src/breaches/application/mod.rs +++ b/libs/cti/src/breaches/application/mod.rs @@ -0,0 +1 @@ + diff --git a/libs/cti/src/breaches/domain/entities/breach.rs b/libs/cti/src/breaches/domain/entities/breach.rs index 91d93b9..7eadf04 100644 --- a/libs/cti/src/breaches/domain/entities/breach.rs +++ b/libs/cti/src/breaches/domain/entities/breach.rs @@ -1,8 +1,15 @@ use aggregate_root::domain::aggregate_root::AggregateRoot; -use crate::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}; +use crate::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, +}; -use super::{breach_id::BreachId, breach_product::BreachProduct, breach_product_type::BreachProductType, breach_product_version::BreachProductVersion, breach_vendor::BreachVendor}; +use super::{ + breach_id::BreachId, breach_product::BreachProduct, breach_product_type::BreachProductType, + breach_product_version::BreachProductVersion, breach_vendor::BreachVendor, +}; pub struct Breach { // Breach data diff --git a/libs/cti/src/breaches/domain/entities/mod.rs b/libs/cti/src/breaches/domain/entities/mod.rs index 96b85d3..7668732 100644 --- a/libs/cti/src/breaches/domain/entities/mod.rs +++ b/libs/cti/src/breaches/domain/entities/mod.rs @@ -1,6 +1,6 @@ +pub mod breach; pub mod breach_id; pub mod breach_product; pub mod breach_product_type; pub mod breach_product_version; pub mod breach_vendor; -pub mod breach; \ No newline at end of file diff --git a/libs/cti/src/breaches/domain/events/breach_created_event.rs b/libs/cti/src/breaches/domain/events/breach_created_event.rs index 8812486..dab9834 100644 --- a/libs/cti/src/breaches/domain/events/breach_created_event.rs +++ b/libs/cti/src/breaches/domain/events/breach_created_event.rs @@ -1,8 +1,16 @@ 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 -}}; +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, diff --git a/libs/cti/src/breaches/domain/events/mod.rs b/libs/cti/src/breaches/domain/events/mod.rs index 3635a52..d106a54 100644 --- a/libs/cti/src/breaches/domain/events/mod.rs +++ b/libs/cti/src/breaches/domain/events/mod.rs @@ -1 +1 @@ -pub mod breach_created_event; \ No newline at end of file +pub mod breach_created_event; diff --git a/libs/cti/src/breaches/domain/mod.rs b/libs/cti/src/breaches/domain/mod.rs index 7b58fd9..3f0ff06 100644 --- a/libs/cti/src/breaches/domain/mod.rs +++ b/libs/cti/src/breaches/domain/mod.rs @@ -1,3 +1,3 @@ pub mod entities; +pub mod events; pub mod repositories; -pub mod events; \ No newline at end of file diff --git a/libs/cti/src/breaches/domain/repositories/breach_repository.rs b/libs/cti/src/breaches/domain/repositories/breach_repository.rs index c455172..16fa4fc 100644 --- a/libs/cti/src/breaches/domain/repositories/breach_repository.rs +++ b/libs/cti/src/breaches/domain/repositories/breach_repository.rs @@ -1,5 +1,6 @@ use crate::{ - breaches::domain::entities::{breach::Breach, breach_id::BreachId}, shared::domain::errors::DomainError + breaches::domain::entities::{breach::Breach, breach_id::BreachId}, + shared::domain::errors::DomainError, }; use async_trait::async_trait; diff --git a/libs/cti/src/breaches/domain/repositories/mod.rs b/libs/cti/src/breaches/domain/repositories/mod.rs index 2bada07..e636352 100644 --- a/libs/cti/src/breaches/domain/repositories/mod.rs +++ b/libs/cti/src/breaches/domain/repositories/mod.rs @@ -1 +1 @@ -pub mod breach_repository; \ No newline at end of file +pub mod breach_repository; diff --git a/libs/cti/src/breaches/infrastructure/mod.rs b/libs/cti/src/breaches/infrastructure/mod.rs index e69de29..8b13789 100644 --- a/libs/cti/src/breaches/infrastructure/mod.rs +++ b/libs/cti/src/breaches/infrastructure/mod.rs @@ -0,0 +1 @@ + diff --git a/libs/cti/src/breaches/mod.rs b/libs/cti/src/breaches/mod.rs index fbc4a14..50d0795 100644 --- a/libs/cti/src/breaches/mod.rs +++ b/libs/cti/src/breaches/mod.rs @@ -1,3 +1,3 @@ -pub mod domain; pub mod application; -pub mod infrastructure; \ No newline at end of file +pub mod domain; +pub mod infrastructure; diff --git a/libs/cti/src/cves/application/create_one/create_cve_command_handler.rs b/libs/cti/src/cves/application/create_one/create_cve_command_handler.rs index 7e0bf5f..fbf8c2d 100644 --- a/libs/cti/src/cves/application/create_one/create_cve_command_handler.rs +++ b/libs/cti/src/cves/application/create_one/create_cve_command_handler.rs @@ -8,7 +8,10 @@ use crate::cves::{ application::cve_command_response::CveCommandResponse, 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 + 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, }, repositories::cve_repository::CveRepository, }, @@ -68,7 +71,15 @@ impl CommandHandler for CreateCveCommandHandler CveCommandResponse::boxed_ok(), diff --git a/libs/cti/src/cves/application/create_one/cve_creator.rs b/libs/cti/src/cves/application/create_one/cve_creator.rs index 5bdc5bd..161fbb9 100644 --- a/libs/cti/src/cves/application/create_one/cve_creator.rs +++ b/libs/cti/src/cves/application/create_one/cve_creator.rs @@ -5,7 +5,10 @@ use events::domain::event_bus::EventBus; use crate::{ cves::domain::{ entities::{ - cve::Cve, 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 + cve::Cve, 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, }, events::cve_created_event::CveCreatedEvent, repositories::cve_repository::CveRepository, @@ -37,13 +40,29 @@ impl CveCreator { date_updated: CveUpdatedDate, ) -> Result<(), DomainError> { tracing::debug!("Starting CVE creation for {}.", id); - let cve = Cve::from(&id, &state, &description, &assigner_id, &assigner_name, &date_published, &date_updated); + let cve = Cve::from( + &id, + &state, + &description, + &assigner_id, + &assigner_name, + &date_published, + &date_updated, + ); let res = self.repository.create_one(&cve).await; if res.is_err() { tracing::info!("Error creating CVE with id: {}.", id); return Err(res.err().unwrap()); } - let created_event = CveCreatedEvent::new_shared(&id, &state, &description, &assigner_id, &assigner_name, &date_published, &date_updated); + let created_event = CveCreatedEvent::new_shared( + &id, + &state, + &description, + &assigner_id, + &assigner_name, + &date_published, + &date_updated, + ); self.event_bus.publish(created_event).await; tracing::debug!("CVE with id: {} created.", id); Ok(()) diff --git a/libs/cti/src/cves/application/update_one/cve_updater.rs b/libs/cti/src/cves/application/update_one/cve_updater.rs index ad0fb6a..cc39c00 100644 --- a/libs/cti/src/cves/application/update_one/cve_updater.rs +++ b/libs/cti/src/cves/application/update_one/cve_updater.rs @@ -5,7 +5,10 @@ use events::domain::event_bus::EventBus; use crate::{ cves::domain::{ entities::{ - cve::Cve, 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 + cve::Cve, 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, }, events::cve_updated_event::CveUpdatedEvent, repositories::cve_repository::CveRepository, @@ -44,7 +47,15 @@ impl CveUpdater { }; tracing::debug!("CVE {} found.", id); tracing::debug!("Starting CVE update for {}.", id); - let cve = Cve::from(&id, &state, &description, &assigner_id, &assigner_name, &date_published, &date_updated); + let cve = Cve::from( + &id, + &state, + &description, + &assigner_id, + &assigner_name, + &date_published, + &date_updated, + ); if cve == old_cve { tracing::info!("CVE with id: {} is already up to date.", id); return Ok(()); diff --git a/libs/cti/src/cves/application/update_one/mod.rs b/libs/cti/src/cves/application/update_one/mod.rs index 188f23f..4e3534f 100644 --- a/libs/cti/src/cves/application/update_one/mod.rs +++ b/libs/cti/src/cves/application/update_one/mod.rs @@ -1,4 +1,3 @@ - pub mod cve_updater; pub mod update_cve_command; -pub mod update_cve_command_handler; \ No newline at end of file +pub mod update_cve_command_handler; diff --git a/libs/cti/src/cves/application/update_one/update_cve_command_handler.rs b/libs/cti/src/cves/application/update_one/update_cve_command_handler.rs index b1f4992..661e72c 100644 --- a/libs/cti/src/cves/application/update_one/update_cve_command_handler.rs +++ b/libs/cti/src/cves/application/update_one/update_cve_command_handler.rs @@ -1,13 +1,24 @@ use async_trait::async_trait; -use cqrs::domain::{command::Command, command_bus_response::CommandBusResponse, command_handler::CommandHandler}; +use cqrs::domain::{ + command::Command, command_bus_response::CommandBusResponse, command_handler::CommandHandler, +}; use events::domain::event_bus::EventBus; -use crate::cves::{application::cve_command_response::CveCommandResponse, 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}, repositories::cve_repository::CveRepository}}; +use crate::cves::{ + application::cve_command_response::CveCommandResponse, + 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, + }, + repositories::cve_repository::CveRepository, + }, +}; use super::{cve_updater::CveUpdater, update_cve_command::UpdateCveCommand}; - - pub struct UpdateCveCommandHandler { updater: CveUpdater, } @@ -60,7 +71,15 @@ impl CommandHandler for UpdateCveCommandHandler CveCommandResponse::boxed_ok(), diff --git a/libs/cti/src/cves/domain/entities/cve.rs b/libs/cti/src/cves/domain/entities/cve.rs index 85a522f..4750978 100644 --- a/libs/cti/src/cves/domain/entities/cve.rs +++ b/libs/cti/src/cves/domain/entities/cve.rs @@ -1,7 +1,9 @@ use aggregate_root::domain::aggregate_root::AggregateRoot; use super::{ - 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 + 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 Cve { diff --git a/libs/cti/src/cves/domain/entities/mod.rs b/libs/cti/src/cves/domain/entities/mod.rs index b15f6f5..7d30c74 100644 --- a/libs/cti/src/cves/domain/entities/mod.rs +++ b/libs/cti/src/cves/domain/entities/mod.rs @@ -1,8 +1,8 @@ pub mod cve; +pub mod cve_assigner_id; +pub mod cve_assigner_name; pub mod cve_description; pub mod cve_id; pub mod cve_publication_date; -pub mod cve_updated_date; pub mod cve_state; -pub mod cve_assigner_id; -pub mod cve_assigner_name; +pub mod cve_updated_date; diff --git a/libs/cti/src/cves/domain/events/cve_created_event.rs b/libs/cti/src/cves/domain/events/cve_created_event.rs index ee5e028..889ea64 100644 --- a/libs/cti/src/cves/domain/events/cve_created_event.rs +++ b/libs/cti/src/cves/domain/events/cve_created_event.rs @@ -1,7 +1,9 @@ use events::domain::domain_event::DomainEvent; use crate::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 + 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 CveCreatedEvent { diff --git a/libs/cti/src/cves/domain/events/cve_updated_event.rs b/libs/cti/src/cves/domain/events/cve_updated_event.rs index d2fd8ef..a6755cb 100644 --- a/libs/cti/src/cves/domain/events/cve_updated_event.rs +++ b/libs/cti/src/cves/domain/events/cve_updated_event.rs @@ -1,7 +1,9 @@ use events::domain::domain_event::DomainEvent; use crate::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 + 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 CveUpdatedEvent { @@ -39,7 +41,6 @@ impl CveUpdatedEvent { cve_old_date_published: &CvePublicationDate, cve_updated_date: &CveUpdatedDate, cve_old_updated_date: &CveUpdatedDate, - ) -> Self { let id = uuid::Uuid::new_v4().to_string(); let occurred_on = chrono::Utc::now().to_rfc3339(); diff --git a/libs/cti/src/cves/infrastructure/dtos/cve_json_dto.rs b/libs/cti/src/cves/infrastructure/dtos/cve_json_dto.rs index 45baeac..7cd5d54 100644 --- a/libs/cti/src/cves/infrastructure/dtos/cve_json_dto.rs +++ b/libs/cti/src/cves/infrastructure/dtos/cve_json_dto.rs @@ -1,10 +1,10 @@ use crate::cves::domain::entities::cve_assigner_name::CveAssignerName; -use crate::cves::domain::entities::cve_updated_date::CveUpdatedDate; -use crate::cves::domain::entities::{cve::Cve, cve_assigner_id::CveAssignerId}; use crate::cves::domain::entities::cve_description::CveDescription; use crate::cves::domain::entities::cve_id::CveId; use crate::cves::domain::entities::cve_publication_date::CvePublicationDate; use crate::cves::domain::entities::cve_state::CveState; +use crate::cves::domain::entities::cve_updated_date::CveUpdatedDate; +use crate::cves::domain::entities::{cve::Cve, cve_assigner_id::CveAssignerId}; use crate::shared::domain::errors::DomainError; use serde::{Deserialize, Serialize}; @@ -27,7 +27,7 @@ pub fn parse_to_dto(cve: &Cve) -> CveJsonDto { description: cve.description.value(), assigner_id: Some(cve.assigner_id.value()), assigner_name: Some(cve.assigner_name.value()), - + date_published: Some(cve.date_published.value()), date_updated: Some(cve.date_updated.value()), } @@ -54,7 +54,15 @@ pub fn parse_to_domain(dto: &CveJsonDto) -> Result { .or_else(|e| Err(e)) .unwrap(); - let cve = Cve::new(id, state, description, assigner_id, assigner_name, date_published, date_updated); + let cve = Cve::new( + id, + state, + description, + assigner_id, + assigner_name, + date_published, + date_updated, + ); Ok(cve) } diff --git a/libs/cti/src/cves/infrastructure/sqlx/sqlx_cve.rs b/libs/cti/src/cves/infrastructure/sqlx/sqlx_cve.rs index ffa7f74..fee1cbe 100644 --- a/libs/cti/src/cves/infrastructure/sqlx/sqlx_cve.rs +++ b/libs/cti/src/cves/infrastructure/sqlx/sqlx_cve.rs @@ -1,7 +1,9 @@ use sqlx::FromRow; use crate::cves::domain::entities::{ - cve::Cve, 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 + cve::Cve, 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, }; #[derive(Debug, FromRow, Clone)] diff --git a/libs/cti/src/lib.rs b/libs/cti/src/lib.rs index 3f2fb75..860804b 100644 --- a/libs/cti/src/lib.rs +++ b/libs/cti/src/lib.rs @@ -1,3 +1,3 @@ -pub mod cves; pub mod breaches; +pub mod cves; pub mod shared;