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
2,975 changes: 2,975 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bssh"
version = "0.3.0"
edition = "2021"
edition = "2024"
authors = ["Jeongkyu Shin"]
description = "Parallel SSH command execution tool for cluster management"
license = "Apache-2.0"
Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ pub enum Commands {

#[arg(help = "Remote destination path")]
destination: String,

#[arg(short = 'r', long, help = "Recursively upload directories")]
recursive: bool,
},

#[command(about = "Download files from remote hosts")]
Expand All @@ -117,6 +120,9 @@ pub enum Commands {

#[arg(help = "Local destination directory")]
destination: PathBuf,

#[arg(short = 'r', long, help = "Recursively download directories")]
recursive: bool,
},
}

Expand Down
70 changes: 39 additions & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ impl Config {

// Try current directory config.yaml
let current_dir_config = PathBuf::from("config.yaml");
if current_dir_config.exists() {
if let Ok(config) = Self::load(&current_dir_config).await {
return Ok(config);
}
if current_dir_config.exists()
&& let Ok(config) = Self::load(&current_dir_config).await
{
return Ok(config);
}

// Try ~/.config/bssh/config.yaml
if let Some(home_dir) = dirs::home_dir() {
let home_config = home_dir.join(".config").join("bssh").join("config.yaml");
if home_config.exists() {
if let Ok(config) = Self::load(&home_config).await {
return Ok(config);
}
if home_config.exists()
&& let Ok(config) = Self::load(&home_config).await
{
return Ok(config);
}
}

Expand Down Expand Up @@ -234,25 +234,23 @@ impl Config {
}

pub fn get_ssh_key(&self, cluster_name: Option<&str>) -> Option<String> {
if let Some(cluster_name) = cluster_name {
if let Some(cluster) = self.get_cluster(cluster_name) {
if let Some(key) = &cluster.defaults.ssh_key {
return Some(key.clone());
}
}
if let Some(cluster_name) = cluster_name
&& let Some(cluster) = self.get_cluster(cluster_name)
&& let Some(key) = &cluster.defaults.ssh_key
{
return Some(key.clone());
}

self.defaults.ssh_key.clone()
}
}

fn expand_tilde(path: &Path) -> PathBuf {
if let Some(path_str) = path.to_str() {
if path_str.starts_with("~/") {
if let Ok(home) = std::env::var("HOME") {
return PathBuf::from(path_str.replacen("~", &home, 1));
}
}
if let Some(path_str) = path.to_str()
&& path_str.starts_with("~/")
&& let Ok(home) = std::env::var("HOME")
{
return PathBuf::from(path_str.replacen("~", &home, 1));
}
path.to_path_buf()
}
Expand Down Expand Up @@ -328,8 +326,10 @@ mod tests {

#[test]
fn test_expand_env_vars() {
std::env::set_var("TEST_VAR", "test_value");
std::env::set_var("TEST_USER", "testuser");
unsafe {
std::env::set_var("TEST_VAR", "test_value");
std::env::set_var("TEST_USER", "testuser");
}

// Test ${VAR} syntax
assert_eq!(expand_env_vars("Hello ${TEST_VAR}!"), "Hello test_value!");
Expand All @@ -355,7 +355,9 @@ mod tests {

#[test]
fn test_expand_tilde() {
std::env::set_var("HOME", "/home/user");
unsafe {
std::env::set_var("HOME", "/home/user");
}
let path = Path::new("~/.ssh/config");
let expanded = expand_tilde(path);
assert_eq!(expanded, PathBuf::from("/home/user/.ssh/config"));
Expand Down Expand Up @@ -401,10 +403,12 @@ clusters:
#[test]
fn test_backendai_env_parsing() {
// Set up Backend.AI environment variables
std::env::set_var("BACKENDAI_CLUSTER_HOSTS", "sub1,main1");
std::env::set_var("BACKENDAI_CLUSTER_HOST", "main1");
std::env::set_var("BACKENDAI_CLUSTER_ROLE", "main");
std::env::set_var("USER", "testuser");
unsafe {
std::env::set_var("BACKENDAI_CLUSTER_HOSTS", "sub1,main1");
std::env::set_var("BACKENDAI_CLUSTER_HOST", "main1");
std::env::set_var("BACKENDAI_CLUSTER_ROLE", "main");
std::env::set_var("USER", "testuser");
}

let cluster = Config::from_backendai_env().unwrap();

Expand All @@ -420,7 +424,9 @@ clusters:
}

// Test with sub role - should skip the first (main) node
std::env::set_var("BACKENDAI_CLUSTER_ROLE", "sub");
unsafe {
std::env::set_var("BACKENDAI_CLUSTER_ROLE", "sub");
}
let cluster = Config::from_backendai_env().unwrap();
assert_eq!(cluster.nodes.len(), 1);

Expand All @@ -432,8 +438,10 @@ clusters:
}

// Clean up
std::env::remove_var("BACKENDAI_CLUSTER_HOSTS");
std::env::remove_var("BACKENDAI_CLUSTER_HOST");
std::env::remove_var("BACKENDAI_CLUSTER_ROLE");
unsafe {
std::env::remove_var("BACKENDAI_CLUSTER_HOSTS");
std::env::remove_var("BACKENDAI_CLUSTER_HOST");
std::env::remove_var("BACKENDAI_CLUSTER_ROLE");
}
}
}
2 changes: 1 addition & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use tokio::sync::Semaphore;

use crate::node::Node;
use crate::ssh::{client::CommandResult, known_hosts::StrictHostKeyChecking, SshClient};
use crate::ssh::{SshClient, client::CommandResult, known_hosts::StrictHostKeyChecking};

pub struct ParallelExecutor {
nodes: Vec<Node>,
Expand Down
Loading
Loading