From c482c2f44efdda1a08f7e1e40ad37b9868b5359b Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Wed, 22 Nov 2023 10:17:14 +0100 Subject: [PATCH] Refactor: documentation changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christoph Krämer --- rust/examples/nasl-cli/transpile.toml | 37 ++++++++++++++++++--------- rust/feed/src/transpile/mod.rs | 9 +++---- rust/feed/src/verify/mod.rs | 1 - rust/nasl-cli/src/main.rs | 4 +-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/rust/examples/nasl-cli/transpile.toml b/rust/examples/nasl-cli/transpile.toml index af5b7bbde..e6969e974 100644 --- a/rust/examples/nasl-cli/transpile.toml +++ b/rust/examples/nasl-cli/transpile.toml @@ -6,28 +6,33 @@ # nasl-cli -v feed transpile -p /tmp/feed -r example/replace.toml # ``` +# Transforms +# > register_product(cpe: ..., location: ..., port: ..., service: 'www') +# To: +# > register_product(cpe: ..., location: ..., port: ..., service: 'www', service_to_be: 'world-wide-web') [[cmds]] [cmds.find] FunctionByNameAndParameter = [ "register_product", [ - { Name = "cpe" }, - { Name = "location" }, - { Name = "port" }, - { NameValue = [ - "service", - "\"www\"", -] }, -], + { Name = "cpe" }, + { Name = "location" }, + { Name = "port" }, + { NameValue = [ + "service", + "\"www\"", + ] }, + ], ] [cmds.with.Parameter.Push] -Named = [ - "service_to_be", - "\"world-wide-web\"", -] +Named = [ "service_to_be", "\"world-wide-web\"", ] +# Transforms +# > register_product(cpe: ..., location: ..., port: ..., service: 'www', service_to_be: 'world-wide-web') +# To: +# > register_product(cpe: ..., location: ..., port: ..., service_to_be: 'world-wide-web') [[cmds]] [cmds.find] @@ -45,6 +50,10 @@ FunctionByNameAndParameter = [ [cmds.with.Parameter] RemoveNamed = "service" +# Transforms +# > register_product(cpe: ..., location: ..., port: ..., service_to_be: 'world-wide-web') +# To: +# > register_product(cpe: ..., location: ..., port: ..., service: 'world-wide-web') [[cmds]] [cmds.find] @@ -54,6 +63,10 @@ FunctionByName = "register_product" previous = "service_to_be" new = "service" +# Transforms +# > register_host_detail +# To: +# > add_host_detail [[cmds]] [cmds.find] diff --git a/rust/feed/src/transpile/mod.rs b/rust/feed/src/transpile/mod.rs index 744b7f24b..a4eedc6a8 100644 --- a/rust/feed/src/transpile/mod.rs +++ b/rust/feed/src/transpile/mod.rs @@ -11,7 +11,7 @@ use crate::{verify, NaslFileFinder}; pub enum FindParameter { /// Find a parameter by name Name(String), - /// Find a parameter by name + /// Find a parameter by name and value NameValue(String, String), /// Find a parameter by index Index(usize), @@ -59,7 +59,7 @@ pub enum ParameterOperation { RemoveNamed(String), /// Removes a parameter found by index Remove(usize), - /// Removes a parameter found by index + /// Removes all parameter RemoveAll, /// Renames a parameter Rename { @@ -107,7 +107,7 @@ impl std::fmt::Display for ParameterOperation { pub enum Replace { /// Replaces name of a function Name(String), - /// Replaces name of a function + /// Remove finding Remove, /// Replace parameter Parameter(ParameterOperation), @@ -258,7 +258,6 @@ impl<'a> Matcher for FunctionNameMatcher<'a> { impl Find { /// Checks if statement matches the wanted search operation pub fn matches(&self, s: &Statement) -> bool { - // FunctionNameMatcher { name, parameter }.matches(s) let (name, parameter) = match self { Find::FunctionByName(name) => (Some(name as &str), None), Find::FunctionByParameter(x) => (None, Some(x as &[_])), @@ -270,7 +269,7 @@ impl Find { } #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] -/// Describes what should be replaces +/// Describes what should be replaced pub struct ReplaceCommand { /// The identifier to find pub find: Find, diff --git a/rust/feed/src/verify/mod.rs b/rust/feed/src/verify/mod.rs index 596474888..617b7bf86 100644 --- a/rust/feed/src/verify/mod.rs +++ b/rust/feed/src/verify/mod.rs @@ -264,7 +264,6 @@ impl Hasher { /// Loads a given hashsums file and lazily verifies the loaded filename key of the sums file and verifies /// the hash within the sums file with an calculated hash of the found content. -// pub struct HashSumNameLoader<'a, R> { reader: &'a dyn AsBufReader, hasher: Hasher, diff --git a/rust/nasl-cli/src/main.rs b/rust/nasl-cli/src/main.rs index da07ddeea..0ebc3628e 100644 --- a/rust/nasl-cli/src/main.rs +++ b/rust/nasl-cli/src/main.rs @@ -95,7 +95,7 @@ enum FeedAction { /// /// The rules describe how to find a certain element and how to replace it. /// Currently only toml in the following format is supported: - /// ```text + /// ```toml /// [[cmds]] /// /// [cmds.find] @@ -169,7 +169,6 @@ impl RunAction<()> for FeedAction { cmds: Vec, } - // TODO add from impl let rules = std::fs::read_to_string(rules).unwrap(); let rules: Wrapper = toml::from_str(&rules).unwrap(); let rules = rules.cmds; @@ -470,7 +469,6 @@ When piping a scan json it is enriched with the scan-config xml and may the port verbose: verbose > 0, }, } - // ah } _ => unreachable!("subcommand_required prevents None"), },