mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 01:26:04 -08:00
Don't prompt for password if a ssh key is set for that host (#186)
* feat: don't ask password if a ssh key is set for that host * fix: User from ssh config was not used as it should * fix: forgot a file
This commit is contained in:
committed by
GitHub
parent
b7369162d2
commit
044f2436f8
@@ -7,10 +7,11 @@ use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// Ext
|
||||
use remotefs_ssh::{SshConfigParseRule, SshKeyStorage as SshKeyStorageTrait};
|
||||
use remotefs_ssh::SshKeyStorage as SshKeyStorageTrait;
|
||||
use ssh2_config::SshConfig;
|
||||
|
||||
use super::config_client::ConfigClient;
|
||||
use crate::utils::ssh as ssh_utils;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SshKeyStorage {
|
||||
@@ -34,19 +35,6 @@ impl SshKeyStorage {
|
||||
self.hosts.insert(key, p);
|
||||
}
|
||||
|
||||
/// Parse ssh2 config
|
||||
fn parse_ssh2_config(path: &str) -> Result<SshConfig, String> {
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
let mut reader = File::open(path)
|
||||
.map_err(|e| format!("failed to open {path}: {e}"))
|
||||
.map(BufReader::new)?;
|
||||
SshConfig::default()
|
||||
.parse(&mut reader, SshConfigParseRule::ALLOW_UNKNOWN_FIELDS)
|
||||
.map_err(|e| format!("Failed to parse ssh2 config: {e}"))
|
||||
}
|
||||
|
||||
/// Resolve host via termscp ssh keys storage
|
||||
fn resolve_host_in_termscp_storage(&self, host: &str, username: &str) -> Option<&Path> {
|
||||
let key: String = Self::make_mapkey(host, username);
|
||||
@@ -89,7 +77,7 @@ impl From<&ConfigClient> for SshKeyStorage {
|
||||
// read ssh2 config
|
||||
let ssh_config = cfg_client.get_ssh_config().and_then(|x| {
|
||||
debug!("reading ssh config at {}", x);
|
||||
Self::parse_ssh2_config(x).ok()
|
||||
ssh_utils::parse_ssh2_config(x).ok()
|
||||
});
|
||||
let mut hosts: HashMap<String, PathBuf> =
|
||||
HashMap::with_capacity(cfg_client.iter_ssh_keys().count());
|
||||
|
||||
Reference in New Issue
Block a user