ssh_cfg

Crates.iossh_cfg
lib.rsssh_cfg
version0.3.0
sourcesrc
created_at2021-03-13 01:42:33.295933
updated_at2021-12-02 08:47:47.818151
descriptionParses `~/.ssh/config` asynchronously.
homepage
repositoryhttps://github.com/azriel91/ssh_cfg
max_upload_size
id368089
size161,670
Azriel Hoh (azriel91)

documentation

https://docs.rs/ssh_cfg/

README

🌐 SSH Cfg

Crates.io docs.rs CI

Parses ~/.ssh/config asynchronously.

use ssh_cfg::{SshConfigParser, SshOptionKey};
use tokio::runtime;

async fn parse_ssh_config() -> Result<(), Box<dyn std::error::Error>> {
    let ssh_config = SshConfigParser::parse_home().await?;

    // Print first host config
    if let Some((first_host, host_config)) = ssh_config.iter().next() {
        println!("Host: {}", first_host);

        // Print its configured SSH key if any
        if let Some(identity_file) = host_config.get(&SshOptionKey::IdentityFile) {
            println!("  {} {}", SshOptionKey::IdentityFile, identity_file);
        }
    }

    // Print all host configs
    println!();
    println!("{:#?}", ssh_config);

    Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let rt = runtime::Builder::new_current_thread().build()?;
    rt.block_on(parse_ssh_config())
}

Currently values are stored as Strings. Ideally we would parse them into a strong data model.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 27

cargo fmt