Skip to content

Commit

Permalink
OPT imports
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4t4nuk1 committed Dec 14, 2024
1 parent e9efcb2 commit 6e28a66
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 40 deletions.
5 changes: 4 additions & 1 deletion apps/cti/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions libs/cti/src/breaches/application/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 9 additions & 2 deletions libs/cti/src/breaches/domain/entities/breach.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/cti/src/breaches/domain/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 11 additions & 3 deletions libs/cti/src/breaches/domain/events/breach_created_event.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libs/cti/src/breaches/domain/events/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod breach_created_event;
pub mod breach_created_event;
2 changes: 1 addition & 1 deletion libs/cti/src/breaches/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod entities;
pub mod events;
pub mod repositories;
pub mod events;
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion libs/cti/src/breaches/domain/repositories/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod breach_repository;
pub mod breach_repository;
1 change: 1 addition & 0 deletions libs/cti/src/breaches/infrastructure/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions libs/cti/src/breaches/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod domain;
pub mod application;
pub mod infrastructure;
pub mod domain;
pub mod infrastructure;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -68,7 +71,15 @@ impl<R: CveRepository, E: EventBus> CommandHandler for CreateCveCommandHandler<R

match self
.creator
.run(id, state, description, assigner_id, assigner_name, publication_date, updated_date)
.run(
id,
state,
description,
assigner_id,
assigner_name,
publication_date,
updated_date,
)
.await
{
Ok(_) => CveCommandResponse::boxed_ok(),
Expand Down
25 changes: 22 additions & 3 deletions libs/cti/src/cves/application/create_one/cve_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,13 +40,29 @@ impl<R: CveRepository, E: EventBus> CveCreator<R, E> {
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(())
Expand Down
15 changes: 13 additions & 2 deletions libs/cti/src/cves/application/update_one/cve_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,7 +47,15 @@ impl<R: CveRepository, E: EventBus> CveUpdater<R, E> {
};
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(());
Expand Down
3 changes: 1 addition & 2 deletions libs/cti/src/cves/application/update_one/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub mod cve_updater;
pub mod update_cve_command;
pub mod update_cve_command_handler;
pub mod update_cve_command_handler;
Original file line number Diff line number Diff line change
@@ -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<R: CveRepository, E: EventBus> {
updater: CveUpdater<R, E>,
}
Expand Down Expand Up @@ -60,7 +71,15 @@ impl<R: CveRepository, E: EventBus> CommandHandler for UpdateCveCommandHandler<R

match self
.updater
.run(id, state, description, assigner_id, assigner_name, publication_date, updated_date)
.run(
id,
state,
description,
assigner_id,
assigner_name,
publication_date,
updated_date,
)
.await
{
Ok(_) => CveCommandResponse::boxed_ok(),
Expand Down
4 changes: 3 additions & 1 deletion libs/cti/src/cves/domain/entities/cve.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions libs/cti/src/cves/domain/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion libs/cti/src/cves/domain/events/cve_created_event.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions libs/cti/src/cves/domain/events/cve_updated_event.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions libs/cti/src/cves/infrastructure/dtos/cve_json_dto.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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()),
}
Expand All @@ -54,7 +54,15 @@ pub fn parse_to_domain(dto: &CveJsonDto) -> Result<Cve, DomainError> {
.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)
}
4 changes: 3 additions & 1 deletion libs/cti/src/cves/infrastructure/sqlx/sqlx_cve.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion libs/cti/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod cves;
pub mod breaches;
pub mod cves;
pub mod shared;

0 comments on commit 6e28a66

Please sign in to comment.