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

Fix panic on fluere-config/src/init.rs:14:43 #73

Merged
merged 9 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ repository = "https://github.com/SkuldNorniern/fluere"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version = "4.0.32", features = ["cargo"]}
tokio = { version = "1.32", features = ["full","macros", "rt-multi-thread"] }
clap = { version = "4.0.32", features = ["cargo"] }
tokio = { version = "1.32", features = ["full", "macros", "rt-multi-thread"] }
pnet = { version = "0.34.0", features = ["std"] }
pnet_macros_support = "0.34.0"
pnet_macros = "0.34.0"
# using custom forked version of pcap-rs for fixing audits
pcap = { version = "1.1.0",git = "https://github.com/SkuldNorniern/pcap", rev= "40f1163"}
pcap = { version = "1.1.0", git = "https://github.com/SkuldNorniern/pcap", rev = "40f1163" }

chrono = { version = "0.4.29", default-features = false, features = ["clock"] }
libc = "0.2"
csv = "1.1"
nom = "7.1.2"
snafu = "0.7.4"
serde = { version = "1.0.186", features = ["derive"]}
serde = { version = "1.0.186", features = ["derive"] }
toml = "0.7.1"

fluere_plugin = { version = "0.1.0", path = "./fluere-plugin" }
fluere-config = { version = "0.1.0", path = "./fluere-config" }
fluere-config = { version = "0.1.1", path = "./fluere-config" }
fluereflow = { version = "0.3.1", path = "./fluereflow" }

ratatui = { version = "0.23.0", features = ["all-widgets"] }
Expand All @@ -38,13 +38,12 @@ logs = "0.7.1"
env_logger = "0.10.0"



[workspace]
members = [
"fluere-plugin",
"fluere-config",
#"fluere-plugin-trait",
"fluereflow"
"fluere-plugin",
"fluere-config",
#"fluere-plugin-trait",
"fluereflow",
]

[package.metadata.rpm]
Expand All @@ -61,5 +60,5 @@ libpcap = "*"

[package.metadata.generate-rpm]
assets = [
{ source = "target/release/fluere", dest = "/usr/bin/fluere", mode = "755" },
{ source = "target/release/fluere", dest = "/usr/bin/fluere", mode = "755" },
]
2 changes: 1 addition & 1 deletion fluere-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fluere-config"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
readme = "README.md"
description = "Configuration manager for Fluere."
Expand Down
8 changes: 7 additions & 1 deletion fluere-config/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
let path_file = path_base.join(Path::new("fluere.toml"));
println!("path_file: {:?}", path_file);
if !path_base.exists() {
fs::create_dir_all(path_base).unwrap();
match fs::create_dir_all(&path_base) {
Ok(_) => (),
Err(e) => {
eprintln!("Failed to create directory at {:?}: {}", path_base, e);
return Config::default();
}
}
}

if !path_file.exists() {
Expand Down Expand Up @@ -62,5 +68,5 @@
};

let path_config = path_base.join("fluere");
path_config

Check warning on line 71 in fluere-config/src/init.rs

View workflow job for this annotation

GitHub Actions / clippy

returning the result of a `let` binding from a block

warning: returning the result of a `let` binding from a block --> fluere-config/src/init.rs:71:5 | 70 | let path_config = path_base.join("fluere"); | ------------------------------------------- unnecessary `let` binding 71 | path_config | ^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return = note: `#[warn(clippy::let_and_return)]` on by default help: return the expression directly | 70 ~ 71 ~ path_base.join("fluere") |
}
35 changes: 19 additions & 16 deletions fluere-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@
let lua_guard = lua_clone.lock().await;
let lua = &*lua_guard;
// println!("lua path: {}", path);
let lua_plugin_path = format!("package.path = package.path .. \";{}/?.lua\"", path);
let lua_plugin_path =
format!("package.path = package.path .. \";{}/?.lua\"", path);
let _ = lua.load(lua_plugin_path).exec();

let chunk = lua.load(&code);
let plugin_table: mlua::Table = chunk.eval()?;
let func: mlua::Function = plugin_table.get("init")?;

let argument_table = lua.create_table()?;

// println!("extra argument details{:?}", plugin_config.extra_arguments);
for (key, value) in plugin_config.extra_arguments.clone().unwrap().iter() {
for (key, value) in
plugin_config.extra_arguments.clone().unwrap().iter()
{
argument_table.set(key.as_str(), value.as_str())?;
}

func.call(argument_table)?;
lua.globals().set(name.as_str(), plugin_table)?;
/*let _ = lua_guard.context(|ctx| -> mlua::Result<()> {
Expand Down Expand Up @@ -101,14 +104,16 @@
match download_plugin_from_github(name) {
Ok(_) => {
let path = home_cache_path().join(name.split('/').last().unwrap());
match std::fs::read_to_string(path.join("init.lua"))
{
match std::fs::read_to_string(path.join("init.lua")) {
Ok(code) => {
let lua_clone = self.lua.clone();
let lua_guard = lua_clone.lock().await;
let lua = &*lua_guard;

let lua_plugin_path = format!("package.path = package.path .. \";{}/?.lua\"", path.to_str().unwrap());
let lua_plugin_path = format!(
"package.path = package.path .. \";{}/?.lua\"",
path.to_str().unwrap()
);
let _ = lua.load(lua_plugin_path).exec();
// println!("lua path: {}", path.to_str().unwrap());

Expand All @@ -119,7 +124,9 @@
let argument_table = lua.create_table()?;

// println!("extra argument details{:?}", plugin_config.extra_arguments);
for (key, value) in plugin_config.extra_arguments.clone().unwrap().iter() {
for (key, value) in
plugin_config.extra_arguments.clone().unwrap().iter()
{
argument_table.set(key.as_str(), value.as_str())?;
}

Expand Down Expand Up @@ -213,7 +220,7 @@
{
lua_table
.set(*key, record_vec[index].clone())
.expect(format!("Failed to set key: {}", key).as_str());

Check warning on line 223 in fluere-plugin/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

use of `expect` followed by a function call

warning: use of `expect` followed by a function call --> fluere-plugin/src/lib.rs:223:30 | 223 | ... .expect(format!("Failed to set key: {}", key).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Failed to set key: {}", key))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call = note: `#[warn(clippy::expect_fun_call)]` on by default
}

for plugin_name in plugins.iter() {
Expand All @@ -224,7 +231,7 @@

if let Ok(func) = plugin_table.get::<_, mlua::Function>("process_data") {
func.call::<mlua::Table<'_>, ()>(lua_table.clone())
.expect(format!("Error on plugin: {}", plugin_name).as_str());

Check warning on line 234 in fluere-plugin/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

use of `expect` followed by a function call

warning: use of `expect` followed by a function call --> fluere-plugin/src/lib.rs:234:34 | 234 | ... .expect(format!("Error on plugin: {}", plugin_name).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error on plugin: {}", plugin_name))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
} else {
println!(
"'process_data' function not found in plugin: {}",
Expand All @@ -251,7 +258,7 @@
// Cleanup each plugin before exiting
let lua_clone = self.lua.clone();
let plugins_clone = self.plugins.clone();

let lua = lua_clone.lock().await;
let plugins = plugins_clone.lock().await;

Expand All @@ -262,15 +269,11 @@
.expect("Plugin table not found");

if let Ok(func) = plugin_table.get::<_, mlua::Function>("cleanup") {
func.call::<(), ()>(()).expect(format!("Error on plugin: {}", plugin_name).as_str());
func.call::<(), ()>(())
.expect(format!("Error on plugin: {}", plugin_name).as_str());

Check warning on line 273 in fluere-plugin/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

use of `expect` followed by a function call

warning: use of `expect` followed by a function call --> fluere-plugin/src/lib.rs:273:22 | 273 | .expect(format!("Error on plugin: {}", plugin_name).as_str()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|_| panic!("Error on plugin: {}", plugin_name))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
} else {
println!(
"cleanup function not found in plugin: {}",
plugin_name
);
println!("cleanup function not found in plugin: {}", plugin_name);
}
}


}
}
Loading