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

Add: feed transpile command #1523

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
472 changes: 194 additions & 278 deletions rust/Cargo.lock

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions rust/examples/nasl-cli/transpile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This demo shows how to use a configuration to rename:
# `www` to `world-wide-web` when in register_product the parameter cpe, location, port are set and when service is set to `www`
# `register_host_detail` to `add_host_detail`
# To test it get a community feed and run:
# ```
# nasl-cli -v feed transpile -p /tmp/feed -r example/replace.toml
# ```

[[cmds]]

[cmds.find]
FunctionByNameAndParameter = [
"register_product",
[
{ Name = "cpe" },
{ Name = "location" },
{ Name = "port" },
{ NameValue = [
"service",
"\"www\"",
] },
],
]

[cmds.with.Parameter.Push]
Named = [
"service_to_be",
"\"world-wide-web\"",
]

[[cmds]]

[cmds.find]
FunctionByNameAndParameter = [
"register_product",
[
{ Name = "cpe" },
{ Name = "location" },
{ Name = "port" },
{ Name = "service" },
{ Name = "service_to_be" },
],
]

[cmds.with.Parameter]
RemoveNamed = "service"

[[cmds]]

[cmds.find]
FunctionByName = "register_product"

[cmds.with.Parameter.Rename]
previous = "service_to_be"
new = "service"

[[cmds]]

[cmds.find]
FunctionByName = "register_host_detail"

[cmds.with]
Name = "add_host_detail"
nichtsfrei marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions rust/feed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ sequoia-ipc = "0.30.1"
sequoia-openpgp = { version ="1.16.1", default-features = false, features = ["crypto-openssl"] }
anyhow = "1.0.75"
tracing = "0.1.37"
glob = "0.3.1"
serde = { version = "1.0", features = ["derive"]}

[dev-dependencies]
toml = "0.8.8"
2 changes: 2 additions & 0 deletions rust/feed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
mod oid;
pub mod transpile;
mod update;
mod verify;

Expand All @@ -17,3 +18,4 @@ pub use verify::Error as VerifyError;
pub use verify::FileNameLoader;
pub use verify::HashSumNameLoader;
pub use verify::Hasher;
pub use verify::NaslFileFinder;
6 changes: 3 additions & 3 deletions rust/feed/src/oid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where

fn script_oid(stmt: &Statement) -> Option<String> {
match stmt {
Statement::Call(t, stms) => match t.category() {
Statement::Call(t, stms, _) => match t.category() {
TokenCategory::Identifier(IdentifierType::Undefined(s)) => match s as &str {
"script_oid" => stms.first().map(|x| x.to_string()),
_ => None,
Expand All @@ -52,8 +52,8 @@ where
fn single(&self, key: String) -> Result<String, update::ErrorKind> {
let code = self.loader.load(key.as_ref())?;
for stmt in nasl_syntax::parse(&code) {
if let Statement::If(_, stmts, _) = stmt? {
if let Statement::Block(x) = &*stmts {
if let Statement::If(_, _, stmts, _, _) = stmt? {
if let Statement::Block(_, x, _) = &*stmts {
for stmt in x {
if let Some(oid) = Self::script_oid(stmt) {
return Ok(oid);
Expand Down
Loading
Loading