Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: infisto storage, create results file on scan init #1517

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 deletions 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 @@ -199,15 +199,19 @@ where
{
async fn insert_scan(&self, scan: models::Scan) -> Result<(), Error> {
let id = scan.scan_id.clone().unwrap_or_default();
let key = format!("scan_{id}");
let scan_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(&scan_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
Loading