diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2026-02-03 20:12:08 +0100 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2026-02-03 20:12:08 +0100 |
| commit | 7961d8f77889d71cc14da2d3d89f17631efdc4b2 (patch) | |
| tree | 0c008df00d5895d5188a729c37b62b63afe90dfa /src/main.rs | |
| parent | d280db3939bc3d5d0c61f19c30b42aa5c5c3d195 (diff) | |
Add known hosts support
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 6b4839f..e290ec5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -190,6 +190,7 @@ fn perform_registry_request(registry: &str, url: &str, accept: &'static str, aut struct Repository { url: String, key: Option<std::path::PathBuf>, + host: Option<std::path::PathBuf>, dest: std::path::PathBuf, } @@ -544,8 +545,8 @@ fn run_tool(db: &Connection, auth: &mut Auth, repos: &Vec<Repository>, mut infil .arg("fetch") .arg("origin"); - if let Some(key) = &repo.key { - gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -i \"{}\"", key.to_str().unwrap())); + if let Some(key) = &repo.key && let Some(host) = &repo.host { + gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -o UserKnownHostsFile=\"{}\" -i \"{}\"", host.to_str().unwrap(), key.to_str().unwrap())); } let exit = gitcmd.status() .expect("Git command failed"); @@ -592,9 +593,8 @@ fn run_tool(db: &Connection, auth: &mut Auth, repos: &Vec<Repository>, mut infil .arg(&repo.url) .arg(&repo.dest); - if let Some(key) = &repo.key { - println!("Using repo key {}", key.display()); - gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -i \"{}\"", key.to_str().unwrap())); + if let Some(key) = &repo.key && let Some(host) = &repo.host { + gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -o UserKnownHostsFile=\"{}\" -i \"{}\"", host.to_str().unwrap(), key.to_str().unwrap())); } let exit = gitcmd.status() @@ -717,8 +717,8 @@ fn run_tool(db: &Connection, auth: &mut Auth, repos: &Vec<Repository>, mut infil .arg("origin") .arg("+HEAD:version-bump"); - if let Some(key) = &repo.key { - gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -i \"{}\"", key.to_str().unwrap())); + if let Some(key) = &repo.key && let Some(host) = &repo.host { + gitcmd.env("GIT_SSH_COMMAND", format!("ssh -F none -o IdentitiesOnly=yes -o UserKnownHostsFile=\"{}\" -i \"{}\"", host.to_str().unwrap(), key.to_str().unwrap())); } let exit = gitcmd.status() @@ -970,6 +970,18 @@ fn main() { }; match reader.parse_next() { + Ok(json_event_parser::JsonEvent::ObjectKey(k)) if &k == "host" => {}, + _ => panic!("Invalid config json"), + } + + let host_name = match reader.parse_next() { + Ok(json_event_parser::JsonEvent::String(v)) => { + v.into_owned() + }, + _ => panic!("Invalid config json"), + }; + + match reader.parse_next() { Ok(json_event_parser::JsonEvent::ObjectKey(k)) if &k == "dest" => {}, _ => panic!("Invalid config json"), } @@ -989,6 +1001,7 @@ fn main() { repos.push(Repository{ url: k, key: Some(workdir.join(path.parent().unwrap().join(std::path::PathBuf::from(key_name)))), + host: Some(workdir.join(path.parent().unwrap().join(std::path::PathBuf::from(host_name)))), dest: scratch_path.as_ref().unwrap().join(dest), }); |
