Merge pull request #2 from fan-tastic-z/fix-threatbook-data-error

fix: reduce threatbook error reporting
This commit is contained in:
fan-tastic-z
2025-09-01 14:36:57 +08:00
committed by GitHub
2 changed files with 21 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ use crate::{
domain::models::vuln_information::{CreateVulnInformation, Severity},
errors::Error,
output::plugins::{VulnPlugin, register_plugin},
utils::http_client::HttpClient,
utils::{http_client::HttpClient, util::check_over_two_month},
};
const HOME_PAGE_URL: &str = "https://x.threatbook.com/v5/node/vul_module/homePage";
@@ -63,6 +63,11 @@ impl VulnPlugin for ThreatBookPlugin {
if v.solution {
tags.push("有修复方案".to_string());
}
let mut pushed = false;
if let Some(publish_date) = v.vuln_publish_time {
pushed = check_over_two_month(publish_date.as_str(), v.vuln_update_time.as_str())
.unwrap_or_default();
}
let data = CreateVulnInformation {
key: v.id,
@@ -78,7 +83,7 @@ impl VulnPlugin for ThreatBookPlugin {
tags,
reasons: Vec::new(),
github_search: vec![],
pushed: false,
pushed,
};
self.sender.send(data).change_context_lazy(|| {
Error::Message("Failed to send vuln information to channel".to_string())

View File

@@ -1,4 +1,4 @@
use chrono::{DateTime, Duration, Local, NaiveDate, Utc};
use chrono::{DateTime, Duration, Local, Months, NaiveDate, Utc};
use error_stack::Result;
use hmac::{Hmac, Mac};
use sha2::Sha256;
@@ -48,3 +48,16 @@ pub fn check_over_two_week(date: &str) -> Result<bool, Error> {
}
Ok(true)
}
pub fn check_over_two_month(publish_data: &str, update_data: &str) -> Result<bool, Error> {
let publish = NaiveDate::parse_from_str(publish_data, "%Y-%m-%d")
.map_err(|e| Error::Message(format!("parse date error: {:?}", e)))?;
let update = NaiveDate::parse_from_str(update_data, "%Y-%m-%d")
.map_err(|e| Error::Message(format!("parse date error: {:?}", e)))?;
let publish_plus_two_months = publish
.checked_add_months(Months::new(2))
.ok_or_else(|| Error::Message("date calculation overflow".to_string()))?;
Ok(update >= publish_plus_two_months)
}