diff --git a/.github/test.yaml b/.github/test.yaml deleted file mode 100644 index d7c53e3999..0000000000 --- a/.github/test.yaml +++ /dev/null @@ -1,4 +0,0 @@ -openvas: - repository: temp-openvas-scanner - pullPolicy: Always - tag: "latest" diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 46fdbc7abc..afd7024284 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -16,7 +16,7 @@ The CI pipeline incorporates multiple jobs, each with a specific function in the ### 1. Initialization (`init`) -If the initialization fails it will prevent furter execution of `build`. +If the initialization fails it will prevent further execution of `build`. - **Purpose**: Sets the release type based on the input or event that triggered the workflow. - **Workflow File**: `init.yaml` @@ -25,7 +25,7 @@ If the initialization fails it will prevent furter execution of `build`. - **Purpose**: Executes unit tests to validate code changes. - **Workflow File**: `tests.yml` -If the unit tests fails it will prevent furter execution of `build`. +If the unit tests fails it will prevent further execution of `build`. ### 3. Build (`build`) - **Purpose**: Compiles and builds the project, preparing it for testing and deployment. @@ -33,7 +33,7 @@ If the unit tests fails it will prevent furter execution of `build`. - **Workflow File**: `build.yml` -If the build fails it will prevent furter execution of `functional`. +If the build fails it will prevent further execution of `functional`. ### 4. Linting (`linting`) - **Purpose**: Ensures code quality and consistency through linting. @@ -47,7 +47,7 @@ If linting fails it will not prevent execution of the other steps, as it may be - **Dependencies**: Needs a successful `build`. - **Workflow File**: `functional.yaml` -If the functional tests fail it will prevent furter execution of `containerization`. +If the functional tests fail it will prevent further execution of `containerization`. ### 6. Containerization - **Purpose**: Packages the build into Docker containers. diff --git a/rust/nasl-interpreter/src/include.rs b/rust/nasl-interpreter/src/include.rs index efd20180ca..ff97087f18 100644 --- a/rust/nasl-interpreter/src/include.rs +++ b/rust/nasl-interpreter/src/include.rs @@ -2,12 +2,6 @@ // // SPDX-License-Identifier: GPL-2.0-or-later - - - - - - #[cfg(test)] mod tests { use std::collections::HashMap; diff --git a/rust/nasl-interpreter/src/interpreter.rs b/rust/nasl-interpreter/src/interpreter.rs index 44a51865ee..79f4b0688d 100644 --- a/rust/nasl-interpreter/src/interpreter.rs +++ b/rust/nasl-interpreter/src/interpreter.rs @@ -5,7 +5,7 @@ use std::{collections::HashMap, io}; use nasl_syntax::{ - IdentifierType, LoadError, NaslValue, StatementKind::*, Token, TokenCategory, Statement, + IdentifierType, LoadError, NaslValue, Statement, StatementKind::*, Token, TokenCategory, }; use storage::StorageError; @@ -50,7 +50,6 @@ where } } - fn include(&mut self, name: &Statement) -> InterpretResult { match self.resolve(name)? { NaslValue::String(key) => { @@ -70,7 +69,7 @@ where _ => Err(InterpretError::unsupported(name, "string")), } } - + /// Tries to interpret a statement and retries n times on a retry error /// /// When encountering a retrievable error: @@ -215,14 +214,12 @@ where } NoOp => Ok(NaslValue::Null), EoF => Ok(NaslValue::Null), - AttackCategory => { + AttackCategory => { match statement.as_token().category() { TokenCategory::Identifier(IdentifierType::ACT(cat)) => Ok(NaslValue::AttackCategory(*cat)), _ => unreachable!("AttackCategory must have ACT token but got {:?}, this is an bug within the lexer.", statement.as_token()) } - - }, Continue => Ok(NaslValue::Continue), Break => Ok(NaslValue::Break), diff --git a/rust/nasl-syntax/src/lexer.rs b/rust/nasl-syntax/src/lexer.rs index d6178ec52f..17fb19f9d2 100644 --- a/rust/nasl-syntax/src/lexer.rs +++ b/rust/nasl-syntax/src/lexer.rs @@ -89,7 +89,6 @@ fn infix_binding_power(op: &Operation) -> Option<(u8, u8)> { Some(res) } - enum InFixState { NoInfix, ReturnContinue(Statement), diff --git a/rust/nasl-syntax/src/variable_extension.rs b/rust/nasl-syntax/src/variable_extension.rs index 4cb2fd9089..685b49650f 100644 --- a/rust/nasl-syntax/src/variable_extension.rs +++ b/rust/nasl-syntax/src/variable_extension.rs @@ -5,7 +5,8 @@ use crate::{ error::SyntaxError, lexer::{End, Lexer}, - token::{Category}, Statement, StatementKind, + token::Category, + Statement, StatementKind, }; pub(crate) trait CommaGroup { diff --git a/rust/openvasd/src/controller/entry.rs b/rust/openvasd/src/controller/entry.rs index b716b70f57..d08097d602 100644 --- a/rust/openvasd/src/controller/entry.rs +++ b/rust/openvasd/src/controller/entry.rs @@ -6,7 +6,7 @@ //! //! All known paths must be handled in the entrypoint function. -use std::{fmt::Display, sync::Arc, marker::PhantomData}; +use std::{fmt::Display, marker::PhantomData, sync::Arc}; use super::{context::Context, ClientIdentifier}; @@ -126,7 +126,6 @@ pub struct EntryPoint { pub ctx: Arc>, pub cid: Arc, _phantom: PhantomData, - } impl EntryPoint { @@ -136,12 +135,9 @@ impl EntryPoint { cid, _phantom: PhantomData, } - } - } - impl hyper::service::Service> for EntryPoint where S: ScanStarter @@ -264,7 +260,8 @@ where } } (&Method::POST, Scans(None)) => { - match crate::request::json_request::(&ctx.response, req).await { + match crate::request::json_request::(&ctx.response, req).await + { Ok(mut scan) => { if scan.scan_id.is_some() { return Ok(ctx @@ -389,9 +386,7 @@ where }; match ctx.db.get_results(&id, begin, end).await { - Ok(results) => { - Ok(ctx.response.ok_byte_stream(results).await) - }, + Ok(results) => Ok(ctx.response.ok_byte_stream(results).await), Err(crate::storage::Error::NotFound) => { Ok(ctx.response.not_found("scans/results", &id)) } @@ -412,7 +407,8 @@ where None => Ok(ctx.response.empty(hyper::StatusCode::OK)), }, (&Method::GET, GetVts(Some(vt_selection))) => { - let selection: Vec = vt_selection.split(',').map(|x| x.to_string()).collect(); + let selection: Vec = + vt_selection.split(',').map(|x| x.to_string()).collect(); match &ctx.redis_cache { Some(cache) => match cache.get_vts(Some(selection)).await { @@ -427,4 +423,3 @@ where }) } } - diff --git a/rust/openvasd/src/main.rs b/rust/openvasd/src/main.rs index 86aee30772..b65ce2fff9 100644 --- a/rust/openvasd/src/main.rs +++ b/rust/openvasd/src/main.rs @@ -9,7 +9,6 @@ use redis_storage::{ CacheDispatcher, RedisCtx, VtHelper, FEEDUPDATE_SELECTOR, NOTUSUPDATE_SELECTOR, }; - pub mod config; pub mod controller; pub mod crypt; @@ -22,7 +21,6 @@ pub mod scan; pub mod storage; pub mod tls; - fn create_context( db: DB, config: &config::Config, @@ -48,19 +46,23 @@ fn create_context( if let Some(redis) = config.redis_socket.redis_socket.to_str() { let notus_cache: CacheDispatcher; match CacheDispatcher::init(redis, NOTUSUPDATE_SELECTOR) { - Ok(c) => {notus_cache = c;}, - Err(e) =>{ + Ok(c) => { + notus_cache = c; + } + Err(e) => { notus_cache = CacheDispatcher::default(); tracing::warn!("No notus cache found: {e}"); - }, + } }; let vts_cache: CacheDispatcher; match CacheDispatcher::init(redis, FEEDUPDATE_SELECTOR) { - Ok(c) => {vts_cache = c;}, - Err(e) =>{ + Ok(c) => { + vts_cache = c; + } + Err(e) => { vts_cache = CacheDispatcher::default(); tracing::warn!("No vts cache found: {e}"); - }, + } }; let cache = VtHelper::new(notus_cache, vts_cache); ctx_builder = ctx_builder.redis_cache(ospcmd::GetVtsWrapper::new(cache)); @@ -76,7 +78,6 @@ fn create_context( .build() } - #[tokio::main] async fn main() -> Result<(), Box> { let config = config::Config::load(); diff --git a/rust/openvasd/src/ospcmd/getvts.rs b/rust/openvasd/src/ospcmd/getvts.rs index bc352c5611..1d29211488 100644 --- a/rust/openvasd/src/ospcmd/getvts.rs +++ b/rust/openvasd/src/ospcmd/getvts.rs @@ -7,15 +7,14 @@ use std::marker::PhantomData; use async_trait::async_trait; use redis_storage::{RedisAddAdvisory, RedisAddNvt, RedisGetNvt, RedisWrapper, VtHelper}; -use storage::{StorageError, item::Nvt}; +use storage::{item::Nvt, StorageError}; use tokio::sync::RwLock; #[async_trait] pub trait GetVts { async fn get_oids(&self) -> Result, StorageError>; - async fn get_vts(&self, vt_selection: Option>) - -> Result, StorageError>; + async fn get_vts(&self, vt_selection: Option>) -> Result, StorageError>; } #[derive(Debug, Default)] @@ -41,7 +40,6 @@ where } } - #[async_trait] impl GetVts for GetVtsWrapper where @@ -52,11 +50,7 @@ where self.vthelper.read().await.get_oids() } - async fn get_vts( - &self, - vt_selection: Option>, - ) -> Result, StorageError> { - + async fn get_vts(&self, vt_selection: Option>) -> Result, StorageError> { let oids: Vec; if let Some(selection) = vt_selection { oids = selection; @@ -70,7 +64,7 @@ where match self.vthelper.read().await.retrieve_single_nvt(&oid)? { Some(vt) => vt, None => continue, - } + }, ); } Ok(nvts) diff --git a/rust/openvasd/src/request.rs b/rust/openvasd/src/request.rs index 21219c4867..43385cdf40 100644 --- a/rust/openvasd/src/request.rs +++ b/rust/openvasd/src/request.rs @@ -19,13 +19,13 @@ where T: serde::de::DeserializeOwned, H: hyper::body::Body, ::Error: std::error::Error, - { let body = req.into_body(); let bytes = match body.collect().await { Ok(x) => x.to_bytes(), Err(e) => { - return Err(response.internal_server_error(&e));}, + return Err(response.internal_server_error(&e)); + } }; match serde_json::from_slice(&bytes) { Ok(json) => Ok(json), diff --git a/rust/openvasd/src/response.rs b/rust/openvasd/src/response.rs index b3bdc534f2..efc55a3407 100644 --- a/rust/openvasd/src/response.rs +++ b/rust/openvasd/src/response.rs @@ -198,7 +198,7 @@ impl Response { #[inline] pub async fn ok_json_stream(&self, value: T) -> Result where - T: Iterator + Send + 'static, + T: Iterator + Send + 'static, S: Serialize + Clone + Send + std::fmt::Debug + 'static, { let value = value.map(|x| serde_json::to_vec(&x).unwrap()); diff --git a/rust/openvasd/src/tls.rs b/rust/openvasd/src/tls.rs index d275fdcbce..a31011d9bc 100644 --- a/rust/openvasd/src/tls.rs +++ b/rust/openvasd/src/tls.rs @@ -198,8 +198,7 @@ where let certfile = fs::File::open(filename) .map_err(|e| error(format!("failed to open {:?}: {}", filename, e)))?; let mut reader = io::BufReader::new(certfile); - rustls_pemfile::certs(&mut reader) - .map(|x| x.into_iter().map(CertificateDer::from).collect()) + rustls_pemfile::certs(&mut reader).map(|x| x.into_iter().map(CertificateDer::from).collect()) } // Load private key from file. diff --git a/rust/redis-storage/src/connector.rs b/rust/redis-storage/src/connector.rs index cb282187a9..6e39f8acb6 100644 --- a/rust/redis-storage/src/connector.rs +++ b/rust/redis-storage/src/connector.rs @@ -298,7 +298,10 @@ pub trait RedisGetNvt: RedisWrapper { let mut prefs_list = self.lrange(&keyname, 0, -1)?; let mut prefs: Vec = Vec::new(); for p in prefs_list.iter_mut() { - if let Some(sp) = p.splitn(4, "|||").collect_tuple::<(&str, &str, &str, &str)>(){ + if let Some(sp) = p + .splitn(4, "|||") + .collect_tuple::<(&str, &str, &str, &str)>() + { prefs.push(NvtPreference::from(sp)); } } @@ -309,9 +312,11 @@ pub trait RedisGetNvt: RedisWrapper { fn get_tags(tags: &str) -> BTreeMap { let mut tag_map = BTreeMap::new(); - let tag_list = tags - .split('|') - .map(|x| x.splitn(2, '=').collect_tuple::<(&str, &str)>().unwrap_or_default()); + let tag_list = tags.split('|').map(|x| { + x.splitn(2, '=') + .collect_tuple::<(&str, &str)>() + .unwrap_or_default() + }); for (k, v) in tag_list.into_iter() { if let Ok(tk) = TagKey::from_str(k) { @@ -630,7 +635,6 @@ where self.vts.retrieve_nvt(oid) } } - } /// Cache implementation.