From a3a6446ae32c483592355c8801479f41c7d7e753 Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Wed, 14 Feb 2024 07:36:01 +0100 Subject: [PATCH] Change: ci: add head -n 1 to be more explicit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the extra lines won't be used it is more explicit to reduce it to a single line. Co-authored-by: Christoph Krämer --- .github/workflows/ddependabot.yml | 0 .github/workflows/init.yaml | 2 +- rust/feed/src/update/error.rs | 3 --- rust/feed/src/update/mod.rs | 2 +- rust/infisto/src/base.rs | 8 ++------ rust/infisto/src/serde.rs | 1 - rust/json-storage/src/lib.rs | 10 ++++++---- rust/models/src/advisories.rs | 3 +-- rust/models/src/lib.rs | 1 - rust/models/src/vt.rs | 1 - rust/nasl-interpreter/tests/description.rs | 3 ++- rust/openvasd/src/controller/feed.rs | 23 +++++++++++----------- rust/openvasd/src/storage/mod.rs | 10 +++------- rust/redis-storage/src/connector.rs | 14 ++++++------- rust/storage/src/item.rs | 3 ++- rust/storage/src/lib.rs | 3 --- 16 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 .github/workflows/ddependabot.yml diff --git a/.github/workflows/ddependabot.yml b/.github/workflows/ddependabot.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/.github/workflows/init.yaml b/.github/workflows/init.yaml index 94b2be1f6..7a2c49940 100644 --- a/.github/workflows/init.yaml +++ b/.github/workflows/init.yaml @@ -57,7 +57,7 @@ jobs: if: ( env.IS_VERSION_TAG == 'true' ) run: | # find the latest version that is not ourself - export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort) + export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort | head -n 1) # get major minor patch versions IFS='.' read -r latest_major latest_minor latest_patch << EOF $LATEST_VERSION diff --git a/rust/feed/src/update/error.rs b/rust/feed/src/update/error.rs index 9ed780799..59eaf25d3 100644 --- a/rust/feed/src/update/error.rs +++ b/rust/feed/src/update/error.rs @@ -34,7 +34,6 @@ pub struct Error { pub kind: ErrorKind, } - impl std::fmt::Display for ErrorKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { @@ -56,8 +55,6 @@ impl std::fmt::Display for Error { impl std::error::Error for Error {} - - impl From for Error { fn from(value: verify::Error) -> Self { let fin = match &value { diff --git a/rust/feed/src/update/mod.rs b/rust/feed/src/update/mod.rs index 55a6bb575..3fbe2caba 100644 --- a/rust/feed/src/update/mod.rs +++ b/rust/feed/src/update/mod.rs @@ -82,7 +82,7 @@ where impl<'a, S, L, V, K, R> Update where S: Sync + Send + Dispatcher, - K: AsRef + Display + Default + From + 'static, + K: AsRef + Display + Default + From + 'static, L: Sync + Send + Loader + AsBufReader, V: Iterator, verify::Error>>, R: Read + 'a, diff --git a/rust/infisto/src/base.rs b/rust/infisto/src/base.rs index c34beb8f6..3fc349a57 100644 --- a/rust/infisto/src/base.rs +++ b/rust/infisto/src/base.rs @@ -489,12 +489,8 @@ impl IndexedByteStorage for CachedIndexFileStorer { .append_all_index(key, &initial_index, &data[1..])?; (self.cache.len() - 1, end_index) } - std::io::ErrorKind::NotFound if data.is_empty() => { - (0, vec![]) - } - _ => { - return Err(Error::FileOpen(ioe)) - }, + std::io::ErrorKind::NotFound if data.is_empty() => (0, vec![]), + _ => return Err(Error::FileOpen(ioe)), }, Err(e) => return Err(e), } diff --git a/rust/infisto/src/serde.rs b/rust/infisto/src/serde.rs index 29bbb97c2..2f08fa7ef 100644 --- a/rust/infisto/src/serde.rs +++ b/rust/infisto/src/serde.rs @@ -18,7 +18,6 @@ where { /// Serializes given data to Vec pub fn serialize(t: T) -> Result { - match rmp_serde::to_vec(&t) { Ok(v) => Ok(Serialization::Serialized(v)), Err(_) => Err(base::Error::Serialize), diff --git a/rust/json-storage/src/lib.rs b/rust/json-storage/src/lib.rs index 1c584a682..cbf6b7076 100644 --- a/rust/json-storage/src/lib.rs +++ b/rust/json-storage/src/lib.rs @@ -10,7 +10,7 @@ use std::{ sync::{Arc, Mutex}, }; -use storage::{self, item::PerItemDispatcher, Kb, StorageError, NotusAdvisory}; +use storage::{self, item::PerItemDispatcher, Kb, NotusAdvisory, StorageError}; /// Wraps write calls of json elements to be as list. /// @@ -131,14 +131,14 @@ where _: Box>, ) -> Result<(), StorageError> { - Ok(()) + Ok(()) } } impl storage::Retriever for ItemDispatcher where S: Write, - K: 'static + K: 'static, { fn retrieve( &self, @@ -147,7 +147,9 @@ where ) -> Result>, StorageError> { Ok(match scope { // currently not supported - storage::Retrieve::NVT(_) | storage::Retrieve::NotusAdvisory(_) => Box::new([].into_iter()), + storage::Retrieve::NVT(_) | storage::Retrieve::NotusAdvisory(_) => { + Box::new([].into_iter()) + } storage::Retrieve::KB(s) => Box::new({ let kbs = self.kbs.lock().map_err(StorageError::from)?; let kbs = kbs.clone(); diff --git a/rust/models/src/advisories.rs b/rust/models/src/advisories.rs index 6c2c2f845..e4ad380be 100644 --- a/rust/models/src/advisories.rs +++ b/rust/models/src/advisories.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; /// Represents an advisory json file for notus product. #[cfg_attr(feature = "serde_support", derive(serde::Deserialize))] -#[derive(Debug, Clone,PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ProductsAdivisories { /// Version of the advisory file pub version: String, @@ -173,7 +173,6 @@ impl From for Vulnerability { None => "".to_string(), }, }; - let refs = HashMap::new(); Self { diff --git a/rust/models/src/lib.rs b/rust/models/src/lib.rs index ac9c8e6ae..0bb3a6444 100644 --- a/rust/models/src/lib.rs +++ b/rust/models/src/lib.rs @@ -30,7 +30,6 @@ pub use status::*; pub use target::*; pub use vt::*; - #[cfg(test)] mod tests { diff --git a/rust/models/src/vt.rs b/rust/models/src/vt.rs index 93a9617d6..7000d9f19 100644 --- a/rust/models/src/vt.rs +++ b/rust/models/src/vt.rs @@ -18,4 +18,3 @@ pub struct VT { /// The list of parameters for the VT pub parameters: Vec, } - diff --git a/rust/nasl-interpreter/tests/description.rs b/rust/nasl-interpreter/tests/description.rs index 941dc0271..3da7764a8 100644 --- a/rust/nasl-interpreter/tests/description.rs +++ b/rust/nasl-interpreter/tests/description.rs @@ -93,7 +93,8 @@ if(description) assert_eq!( storage .retrieve(&key, storage::Retrieve::NVT(None)) - .unwrap().collect::>(), + .unwrap() + .collect::>(), vec![ NVT(Oid("0.0.0.0.0.0.0.0.0.1".to_owned())), NVT(FileName(key)), diff --git a/rust/openvasd/src/controller/feed.rs b/rust/openvasd/src/controller/feed.rs index 870620d40..216f092c3 100644 --- a/rust/openvasd/src/controller/feed.rs +++ b/rust/openvasd/src/controller/feed.rs @@ -26,28 +26,29 @@ where let last_hash = ctx.db.feed_hash().await; if signature_check { if let Err(err) = feed::verify::check_signature(&path) { - tracing::warn!("Signature of {} is not corredct, skipping: {}", path.display(), err); - + tracing::warn!( + "Signature of {} is not corredct, skipping: {}", + path.display(), + err + ); } } - let hash = tokio::task::spawn_blocking(move || { - match FeedIdentifier::sumfile_hash(path) { + let hash = + tokio::task::spawn_blocking(move || match FeedIdentifier::sumfile_hash(path) { Ok(h) => h, Err(e) => { tracing::warn!("Failed to compute sumfile hash: {e:?}"); "".to_string() } - } - }) - .await - .unwrap(); + }) + .await + .unwrap(); if last_hash.is_empty() || last_hash != hash { - match ctx.db.synchronize_feeds(hash).await{ - Ok(_) => {}, + match ctx.db.synchronize_feeds(hash).await { + Ok(_) => {} Err(e) => tracing::warn!("Unable to sync feed: {e}"), } - } tokio::time::sleep(interval).await; } diff --git a/rust/openvasd/src/storage/mod.rs b/rust/openvasd/src/storage/mod.rs index bd6978cec..6bd36121e 100644 --- a/rust/openvasd/src/storage/mod.rs +++ b/rust/openvasd/src/storage/mod.rs @@ -109,11 +109,10 @@ pub trait NVTStorer { /// directories and update the meta information. async fn synchronize_feeds(&self, hash: String) -> Result<(), Error>; - /// Retrieves just all oids. async fn oids(&self) -> Result + Send>, Error> { let vts = self.vts().await?; - Ok(Box::new(vts.map(|x|x.oid))) + Ok(Box::new(vts.map(|x| x.oid))) } /// Retrieves NVTs. @@ -123,11 +122,8 @@ pub trait NVTStorer { /// Retrieves a NVT. /// - async fn vt_by_oid( - &self, - oid: &str, - ) -> Result, Error> { - Ok(self.vts().await?.find(|x|x.oid == oid)) + async fn vt_by_oid(&self, oid: &str) -> Result, Error> { + Ok(self.vts().await?.find(|x| x.oid == oid)) } /// Returns the currently stored feed hash. diff --git a/rust/redis-storage/src/connector.rs b/rust/redis-storage/src/connector.rs index bd8adf5a7..0709a24f3 100644 --- a/rust/redis-storage/src/connector.rs +++ b/rust/redis-storage/src/connector.rs @@ -662,8 +662,6 @@ where .map_err(|e| DbError::SystemError(format!("{e:?}")))?; cache.delete_namespace() } - - } impl storage::item::ItemDispatcher for CacheDispatcher @@ -686,7 +684,11 @@ where kbs.push(kb); Ok(()) } - fn dispatch_advisory(&self, key: &str, adv: Box>) -> Result<(), StorageError> { + fn dispatch_advisory( + &self, + key: &str, + adv: Box>, + ) -> Result<(), StorageError> { let mut cache = Arc::as_ref(&self.cache).lock()?; cache.redis_add_advisory(key, *adv).map_err(|e| e.into()) } @@ -763,11 +765,7 @@ mod tests { .unwrap(); Ok(()) } - fn lindex( - &mut self, - _: &str, - _: isize, - ) -> crate::dberror::RedisStorageResult { + fn lindex(&mut self, _: &str, _: isize) -> crate::dberror::RedisStorageResult { Ok(String::new()) } diff --git a/rust/storage/src/item.rs b/rust/storage/src/item.rs index baee48ed0..2f0bf07fa 100644 --- a/rust/storage/src/item.rs +++ b/rust/storage/src/item.rs @@ -572,7 +572,8 @@ pub trait ItemDispatcher { Ok(()) } /// Stores an advisory - fn dispatch_advisory(&self, _: &str, _: Box>) -> Result<(), StorageError>; + fn dispatch_advisory(&self, _: &str, _: Box>) + -> Result<(), StorageError>; } /// Collects the information while being in a description run and calls the dispatch method diff --git a/rust/storage/src/lib.rs b/rust/storage/src/lib.rs index 9fde8a5ef..1c1a1579d 100644 --- a/rust/storage/src/lib.rs +++ b/rust/storage/src/lib.rs @@ -52,11 +52,8 @@ pub enum Field { KB(Kb), /// Notus advisories, when None then the impl can assume finish NotusAdvisory(Box>), - } - - impl From for Field { fn from(value: NVTField) -> Self { Self::NVT(value)