Skip to content

Commit

Permalink
Refactor: documentation changes.
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph Krämer <[email protected]>
  • Loading branch information
nichtsfrei and Kraemii committed Nov 22, 2023
1 parent cb80d19 commit c482c2f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
37 changes: 25 additions & 12 deletions rust/examples/nasl-cli/transpile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -54,6 +63,10 @@ FunctionByName = "register_product"
previous = "service_to_be"
new = "service"

# Transforms
# > register_host_detail
# To:
# > add_host_detail
[[cmds]]

[cmds.find]
Expand Down
9 changes: 4 additions & 5 deletions rust/feed/src/transpile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 &[_])),
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion rust/feed/src/verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>,
hasher: Hasher,
Expand Down
4 changes: 1 addition & 3 deletions rust/nasl-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -169,7 +169,6 @@ impl RunAction<()> for FeedAction {
cmds: Vec<feed::transpile::ReplaceCommand>,
}

// 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;
Expand Down Expand Up @@ -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"),
},
Expand Down

0 comments on commit c482c2f

Please sign in to comment.