Skip to content

Commit

Permalink
misc: add AbstractPlatform::user_ssh_config
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Dec 19, 2024
1 parent 0fe943b commit 384a870
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ pub trait AbstractPlatform {
/// On most platforms this will be `/etc/ssh/ssh_config`
fn system_ssh_config() -> &'static str;

/// Path to the user ssh config file.
/// On most platforms this will be `${HOME}/.ssh/config`
/// # Note
/// This is a _theoretical_ path construction; it does not guarantee that the path actually exists.
/// That is up to the caller to determine and reason about.
/// # Errors
/// If the current user's home directory could not be determined
fn user_ssh_config() -> Result<PathBuf>;

/// The directory to store user configuration files in.
///
/// On Unix platforms this is the traditional home directory.
Expand Down
9 changes: 9 additions & 0 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ impl super::AbstractPlatform for Platform {
"/etc/ssh/ssh_config"
}

fn user_ssh_config() -> Result<PathBuf> {
let Some(mut pb) = dirs::home_dir() else {
anyhow::bail!("could not determine home directory");
};
pb.push(".ssh");
pb.push("config");
Ok(pb)
}

fn user_config_dir() -> Option<PathBuf> {
dirs::home_dir()
}
Expand Down

0 comments on commit 384a870

Please sign in to comment.