Inherit OpenSSH config in SDK by default
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s

This commit is contained in:
DuProcess
2026-07-16 22:24:06 -04:00
parent 4f1d192f7a
commit dc34183118
+45 -1
View File
@@ -156,7 +156,7 @@ impl DoshClientBuilder {
.unwrap_or_default(); .unwrap_or_default();
let raw_server = host_config.ssh.clone().unwrap_or_else(|| self.host.clone()); let raw_server = host_config.ssh.clone().unwrap_or_else(|| self.host.clone());
let ssh_port = host_config.ssh_port.or(self.client.config.ssh_port); let ssh_port = host_config.ssh_port.or(self.client.config.ssh_port);
let ssh_config = load_sdk_ssh_config(host_config.ssh_config.as_deref(), ssh_port)?; let ssh_config = load_sdk_ssh_config_for_target(&host_config, &raw_server, ssh_port)?;
let udp_host = selected_sdk_udp_host( let udp_host = selected_sdk_udp_host(
self.udp_host.as_deref(), self.udp_host.as_deref(),
&host_config, &host_config,
@@ -493,6 +493,10 @@ fn load_sdk_ssh_config(alias: Option<&str>, ssh_port: Option<u16>) -> Result<Sdk
let Some(alias) = alias else { let Some(alias) = alias else {
return Ok(SdkSshConfig::default()); return Ok(SdkSshConfig::default());
}; };
let alias = alias.trim();
if alias.is_empty() {
return Ok(SdkSshConfig::default());
}
let mut command = Command::new("ssh"); let mut command = Command::new("ssh");
command.arg("-G"); command.arg("-G");
if let Some(ssh_port) = ssh_port { if let Some(ssh_port) = ssh_port {
@@ -508,6 +512,26 @@ fn load_sdk_ssh_config(alias: Option<&str>, ssh_port: Option<u16>) -> Result<Sdk
Ok(parse_sdk_ssh_config(&String::from_utf8(output.stdout)?)) Ok(parse_sdk_ssh_config(&String::from_utf8(output.stdout)?))
} }
fn load_sdk_ssh_config_for_target(
host_config: &HostConfig,
raw_server: &str,
ssh_port: Option<u16>,
) -> Result<SdkSshConfig> {
let (alias, explicit) = sdk_ssh_config_lookup(host_config, raw_server);
match load_sdk_ssh_config(Some(alias), ssh_port) {
Ok(config) => Ok(config),
Err(_) if !explicit => Ok(SdkSshConfig::default()),
Err(err) => Err(err),
}
}
fn sdk_ssh_config_lookup<'a>(host_config: &'a HostConfig, raw_server: &'a str) -> (&'a str, bool) {
match host_config.ssh_config.as_deref().map(str::trim) {
Some(alias) if !alias.is_empty() => (alias, true),
_ => (raw_server, false),
}
}
fn parse_sdk_ssh_config(raw: &str) -> SdkSshConfig { fn parse_sdk_ssh_config(raw: &str) -> SdkSshConfig {
let mut config = SdkSshConfig::default(); let mut config = SdkSshConfig::default();
for line in raw.lines() { for line in raw.lines() {
@@ -1003,6 +1027,26 @@ mod tests {
); );
} }
#[test]
fn sdk_ssh_config_lookup_uses_raw_target_by_default() {
let host = HostConfig::default();
assert_eq!(
sdk_ssh_config_lookup(&host, "deploy@prod"),
("deploy@prod", false)
);
}
#[test]
fn sdk_ssh_config_lookup_prefers_explicit_alias() {
let host = HostConfig {
ssh_config: Some(" prod ".to_string()),
..HostConfig::default()
};
assert_eq!(sdk_ssh_config_lookup(&host, "deploy@raw"), ("prod", true));
}
#[test] #[test]
fn sdk_identity_paths_follow_cli_precedence_and_identities_only() { fn sdk_identity_paths_follow_cli_precedence_and_identities_only() {
let dir = tempfile::tempdir().unwrap(); let dir = tempfile::tempdir().unwrap();