Explorar el Código

refactor: change ssh_key_path from String to PathBuf

Type-safer for filesystem paths (serde deserializes TOML strings
into PathBuf seamlessly).  Updated load_secret_key signature to
accept &Path.
Alexander Korolev hace 4 meses
padre
commit
c3f680e662
Se han modificado 4 ficheros con 7 adiciones y 7 borrados
  1. 1 1
      src/before_serve.rs
  2. 4 4
      src/config.rs
  3. 1 1
      src/exec.rs
  4. 1 1
      src/ssh.rs

+ 1 - 1
src/before_serve.rs

@@ -175,7 +175,7 @@ mod tests {
     fn test_config(before_serve: HashMap<String, crate::config::BeforeServeTable>) -> Config {
         Config {
             ssh_user: "u".to_string(),
-            ssh_key_path: "/k".to_string(),
+            ssh_key_path: "/k".into(),
             clusters: vec![test_cluster()],
             nccl: HashMap::new(),
             hf_cache_dir: None,

+ 4 - 4
src/config.rs

@@ -34,7 +34,7 @@ pub struct Cluster {
 #[derive(Clone, Deserialize)]
 pub struct Config {
     pub ssh_user: String,
-    pub ssh_key_path: String,
+    pub ssh_key_path: std::path::PathBuf,
     pub clusters: Vec<Cluster>,
     #[serde(default)]
     pub nccl: HashMap<String, NcclConfig>,
@@ -264,7 +264,7 @@ mod tests {
     fn test_config() -> Config {
         Config {
             ssh_user: "u".to_string(),
-            ssh_key_path: "/k".to_string(),
+            ssh_key_path: "/k".into(),
             clusters: vec![test_cluster()],
             nccl: HashMap::new(),
             hf_cache_dir: None,
@@ -389,7 +389,7 @@ nodes = [
     fn test_select_cluster_by_name() {
         let mut config = Config {
             ssh_user: "user".to_string(),
-            ssh_key_path: "/path/to/key".to_string(),
+            ssh_key_path: "/path/to/key".into(),
             clusters: vec![test_cluster()],
             nccl: HashMap::new(),
             hf_cache_dir: None,
@@ -407,7 +407,7 @@ nodes = [
     fn test_select_cluster_auto() {
         let mut config = Config {
             ssh_user: "user".to_string(),
-            ssh_key_path: "/path/to/key".to_string(),
+            ssh_key_path: "/path/to/key".into(),
             clusters: vec![test_cluster()],
             nccl: HashMap::new(),
             hf_cache_dir: None,

+ 1 - 1
src/exec.rs

@@ -152,7 +152,7 @@ mod tests {
             .collect();
         Config {
             ssh_user: "u".to_string(),
-            ssh_key_path: "/k".to_string(),
+            ssh_key_path: "/k".into(),
             clusters: vec![],
             nccl: HashMap::new(),
             hf_cache_dir: None,

+ 1 - 1
src/ssh.rs

@@ -186,7 +186,7 @@ pub async fn fetch_host_key(config: &Config, node: &Node) -> Result<String> {
 }
 
 /// Loads an SSH private key from the given path.
-pub fn load_secret_key(path: &str) -> Result<russh::keys::PrivateKey> {
+pub fn load_secret_key(path: &std::path::Path) -> Result<russh::keys::PrivateKey> {
     russh_load_secret_key(path, None).context("Failed to load SSH key")
 }