Skip to content

Commit

Permalink
Add breach finder use case
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4t4nuk1 committed Dec 19, 2024
1 parent 1994088 commit f5e1d08
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
36 changes: 36 additions & 0 deletions libs/cti/src/breaches/application/find_one/breach_finder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use tracing::debug;

use crate::{
breaches::domain::{entities::{breach::Breach, breach_product::BreachProduct, breach_product_version::BreachProductVersion, breach_vendor::BreachVendor}, repositories::breach_repository::BreachRepository}, cves::domain::entities::{cve::Cve, cve_id::CveId}, shared::domain::errors::DomainError
};
use std::sync::Arc;

pub struct BreachFinder<R: BreachRepository> {
repository: Arc<R>,
}

impl<R: BreachRepository> BreachFinder<R> {
pub fn new(repository: Arc<R>) -> BreachFinder<R> {
BreachFinder {
repository,
}
}

pub async fn run(
&self,
vendor: BreachVendor,
product: BreachProduct,
product_version: BreachProductVersion,
cve_id: CveId,
) -> Result<Breach, DomainError> {
debug!("Finding Breach with CVE: {} for Product: {}:{}:{}.", cve_id, vendor, product, product_version);
let res = self.repository.find_one(&cve_id, &vendor, &product, &product_version).await;
if res.is_err() {
debug!("Error finding Breach with CVE: {} for Product: {}:{}:{}.", cve_id, vendor, product, product_version);
return Err(res.err().unwrap());
}
debug!("Breach with CVE: {} for Product: {}:{}:{}.", cve_id, vendor, product, product_version);

res
}
}
1 change: 1 addition & 0 deletions libs/cti/src/breaches/application/find_one/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod find_breach_query;
pub mod breach_finder;
6 changes: 6 additions & 0 deletions libs/cti/src/breaches/domain/entities/breach_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ impl Hash for BreachProduct {
self.value.hash(state);
}
}

impl std::fmt::Display for BreachProduct {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ impl Hash for BreachProductVersion {
self.value.hash(state);
}
}

impl std::fmt::Display for BreachProductVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value)
}
}
6 changes: 6 additions & 0 deletions libs/cti/src/breaches/domain/entities/breach_vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ impl Hash for BreachVendor {
self.value.hash(state);
}
}

impl std::fmt::Display for BreachVendor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value)
}
}

0 comments on commit f5e1d08

Please sign in to comment.