Skip to content
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
5 changes: 5 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ pub async fn check_tcp_connection(host: String, port: u16) -> Result<bool> {

Ok(result)
}

#[tauri::command]
pub async fn is_rustfs_process_running() -> Result<bool> {
Ok(state::is_rustfs_process_running())
}
3 changes: 3 additions & 0 deletions src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub struct RustFsConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub port: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub console_port: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub host: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub access_key: Option<String>,
Expand All @@ -22,6 +24,7 @@ impl Default for RustFsConfig {
binary_path: None,
data_path: String::new(),
port: Some(9000),
console_port: Some(9001),
host: Some("127.0.0.1".to_string()),
access_key: Some("rustfsadmin".to_string()),
secret_key: Some("rustfsadmin".to_string()),
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub enum Error {
#[error("Data path does not exist: {0}")]
DataPathNotExist(String),

#[error("API port and console port must be different")]
PortConflict,

#[error("RustFS binary not found at {0}")]
BinaryNotFound(String),

Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ pub fn run() {
commands::get_app_logs,
commands::get_rustfs_logs,
commands::diagnose_rustfs_binary,
commands::check_tcp_connection
commands::check_tcp_connection,
commands::is_rustfs_process_running
])
.build(tauri::generate_context!())
.expect("error building tauri application")
Expand Down
26 changes: 24 additions & 2 deletions src-tauri/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ pub fn launch(config: RustFsConfig) -> Result<String> {
return Err(Error::DataPathRequired);
}

let api_port = config.port.unwrap_or(9000);
let console_port = config.console_port.unwrap_or(9001);

if config.console_enable && api_port == console_port {
return Err(Error::PortConflict);
}

let binary_path = match &config.binary_path {
Some(path) => PathBuf::from(path),
None => get_binary_path()?,
Expand Down Expand Up @@ -199,10 +206,16 @@ pub fn launch(config: RustFsConfig) -> Result<String> {
let address = format!(
"{}:{}",
config.host.as_deref().unwrap_or("127.0.0.1"),
config.port.unwrap_or(9000)
api_port
);
cmd.arg("--address").arg(&address);

let console_address = format!(
"{}:{}",
config.host.as_deref().unwrap_or("127.0.0.1"),
console_port
);

if let Some(access_key) = &config.access_key {
cmd.arg("--access-key").arg(access_key);
}
Expand All @@ -211,6 +224,7 @@ pub fn launch(config: RustFsConfig) -> Result<String> {
}
if config.console_enable {
cmd.arg("--console-enable");
cmd.arg("--console-address").arg(&console_address);
}

#[cfg(windows)]
Expand All @@ -220,7 +234,15 @@ pub fn launch(config: RustFsConfig) -> Result<String> {
cmd.creation_flags(CREATE_NO_WINDOW);
}

add_app_log(format!("Spawning command: {:?}", cmd));
add_app_log(format!(
"Spawning RustFS: binary={}, address={}, console_enable={}, console_address={}, access_key_set={}, secret_key_set={}",
binary_path.display(),
address,
config.console_enable,
console_address,
config.access_key.is_some(),
config.secret_key.is_some()
));
let mut child = cmd
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down
42 changes: 41 additions & 1 deletion src-tauri/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,34 @@ lazy_static! {

lazy_static! {
static ref ANSI_REGEX: Regex = Regex::new(r"\x1B\[[0-9;]*m").unwrap();
static ref SECRET_PATTERNS: Vec<Regex> = vec![
Regex::new(r#"(--access-key\s+)(\S+)"#).unwrap(),
Regex::new(r#"(--secret-key\s+)(\S+)"#).unwrap(),
Regex::new(r#"(access_key\s*=\s*)([^,\s]+)"#).unwrap(),
Regex::new(r#"(secret_key\s*=\s*)([^,\s]+)"#).unwrap(),
Regex::new(r#"(access_key:\s*Some\(")([^"]+)("\))"#).unwrap(),
Regex::new(r#"(secret_key:\s*Some\(")([^"]+)("\))"#).unwrap(),
Regex::new(r#"("access_key"\s*:\s*")([^"]+)(")"#).unwrap(),
Regex::new(r#"("secret_key"\s*:\s*")([^"]+)(")"#).unwrap(),
];
}

fn clean_ansi_codes(s: &str) -> String {
ANSI_REGEX.replace_all(s, "").to_string()
}

fn redact_secrets(s: &str) -> String {
SECRET_PATTERNS.iter().fold(s.to_string(), |acc, regex| {
regex.replace_all(&acc, "${1}[REDACTED]${3}").to_string()
})
}

fn clean_log_message(s: &str) -> String {
redact_secrets(&clean_ansi_codes(s))
}

fn buffer_log(logs: &Arc<Mutex<VecDeque<String>>>, message: String, capacity: usize) -> String {
let cleaned_message = clean_ansi_codes(&message);
let cleaned_message = clean_log_message(&message);
let log_entry = format!(
"[{}] {}",
chrono::Local::now().format("%H:%M:%S"),
Expand Down Expand Up @@ -75,6 +95,26 @@ pub fn get_rustfs_logs() -> Vec<String> {
RUSTFS_LOGS.lock().unwrap().iter().cloned().collect()
}

pub fn is_rustfs_process_running() -> bool {
let mut process_guard = RUSTFS_PROCESS.lock().unwrap();

match process_guard.as_mut() {
Some(child) => match child.try_wait() {
Ok(None) => true,
Ok(Some(_)) => {
*process_guard = None;
false
}
Err(e) => {
add_app_log(format!("Failed to inspect RustFS process status: {}", e));
*process_guard = None;
false
}
},
None => false,
}
}

pub fn set_rustfs_process(process: Child) {
let pid = process.id();
*RUSTFS_PROCESS.lock().unwrap() = Some(process);
Expand Down
Loading
Loading