Skip to content

Commit

Permalink
Feat: Inspect HTTP logs for service forwarding (#249)
Browse files Browse the repository at this point in the history
* WIP: add sniff http logs

* feat: refact kube forward code and add button to inspect logs

* feat: try open logs with default editor first

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections

* feat: add logs only to service forwards and add timeout to tcp connections
  • Loading branch information
hcavarsan authored Jun 6, 2024
1 parent 9c7c4b3 commit d606a0a
Show file tree
Hide file tree
Showing 17 changed files with 1,099 additions and 914 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/kftray-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ whoami = "1.5.1"
tempfile = "3.9"
h2 = { optional = true, version = "0.4.5" }
fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs" }
open = "1.5"
flate2 = "1.0"

[dev-dependencies]
tempfile = "3.9"
Expand Down
37 changes: 37 additions & 0 deletions crates/kftray-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,40 @@ pub async fn import_configs_from_github(

Ok(())
}

#[tauri::command]
pub async fn open_log_file(log_file_path: String) -> Result<(), String> {
use std::env;
use std::process::Command;

println!("Opening log file: {}", log_file_path);

let editor = env::var("EDITOR").unwrap_or_else(|_| "nano".to_string());
let editor_command: Vec<&str> = editor.split_whitespace().collect();

let result = if editor_command.len() > 1 {
Command::new(editor_command[0])
.args(&editor_command[1..])
.arg(&log_file_path)
.spawn()
} else {
Command::new(&editor).arg(&log_file_path).spawn()
};

match result {
Ok(mut child) => match child.wait() {
Ok(status) if status.success() => Ok(()),
Ok(status) => Err(format!("Editor exited with status: {}", status)),
Err(err) => Err(format!("Failed to wait on editor process: {}", err)),
},
Err(err) => {
println!(
"Error opening with editor '{}': {}. Trying default method...",
editor, err
);
open::that(&log_file_path)
.map(|_| ())
.map_err(|err| format!("Error opening log file with default method: {}", err))
}
}
}
Loading

0 comments on commit d606a0a

Please sign in to comment.