Skip to content

Commit

Permalink
Fix: infisto storage, create results file on scan init
Browse files Browse the repository at this point in the history
In case the storage for a new scan was initialized, the file for the results was missing
Now creating a file for the results with an empty Vec
  • Loading branch information
Chris Chandler committed Oct 27, 2023
1 parent c4c8e4f commit f1d2c16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion rust/infisto/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ impl Range {

impl CachedIndexFileStorer {
/// Initializes the storage.
pub fn init(base: &str) -> Result<Self, Error> {
pub fn init<P>(base: P) -> Result<Self, Error>
where
P: AsRef<Path>,
{
let base = IndexedFileStorer::init(base)?;
let cache = [None, None, None, None, None];
Ok(Self { base, cache })
Expand Down
2 changes: 2 additions & 0 deletions rust/models/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::port::Protocol;
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(feature = "bincode_support", derive(bincode::Encode, bincode::Decode))]
pub struct Result {
/// Incremental ID of a result
pub id: usize,
Expand Down Expand Up @@ -78,6 +79,7 @@ impl<T: Into<Result>> From<(usize, T)> for Result {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(feature = "serde_support", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "bincode_support", derive(bincode::Encode, bincode::Decode))]
pub enum ResultType {
/// Vulnerability
Alarm,
Expand Down
6 changes: 5 additions & 1 deletion rust/openvasd/src/storage/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
id: &str,
(status, results): FetchResult,
) -> Result<(), Error> {
let key = format!("results_{}", id);
let key = format!("results_{id}");
self.update_status(id, status).await?;
let scan_key = format!("scan_{id}");

Expand Down Expand Up @@ -201,13 +201,17 @@ where
let id = scan.scan_id.clone().unwrap_or_default();
let key = format!("scan_{id}");
let status_key = format!("status_{id}");
let results_key = format!("results_{id}");
let storage = Arc::clone(&self.storage);
tokio::task::spawn_blocking(move || {
let scan = infisto::bincode::Serialization::serialize(scan)?;
let status = infisto::bincode::Serialization::serialize(models::Status::default())?;
let results =
infisto::bincode::Serialization::serialize(Vec::<models::Result>::default())?;
let mut storage = storage.write().unwrap();
storage.put(&key, scan)?;
storage.put(&status_key, status)?;
storage.put(&results_key, results)?;

let stored_key = infisto::bincode::Serialization::serialize(&id)?;
storage.append("scans", stored_key)?;
Expand Down

0 comments on commit f1d2c16

Please sign in to comment.