Skip to content

Commit 7a70831

Browse files
fsckTrolldemorted
authored andcommitted
Fix path generation for sshkeyfiles
1 parent 21cac37 commit 7a70831

File tree

3 files changed

+145
-2
lines changed

3 files changed

+145
-2
lines changed

Cargo.lock

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ lazy_static = "1.0"
1313
getopts = "0.2"
1414
reqwest = "*"
1515
ssh2 = "*"
16+
dirs = "1.0"

src/storage.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern crate dirs;
12
use std::io::Write;
23
use std::fs::File;
34
use std::fs::OpenOptions;
@@ -57,7 +58,11 @@ pub fn generate_authorized_key_files(destinations: &[Destination]) -> Result<(),
5758
// append deploy key
5859
let mut deploy_key = String::new();
5960
// TODO: User-configable ssh key
60-
if let Ok(mut deploy_key_file) = File::open("~/.ssh/id_ed25519.pub") {
61+
let mut path = dirs::home_dir().unwrap();
62+
path.push(".ssh");
63+
path.push("id_ed25519.pub");
64+
println!("Loading SSH-pubkeyfile {:?}",path);
65+
if let Ok(mut deploy_key_file) = File::open(path) {
6166
deploy_key_file.read_to_string(&mut deploy_key)?;
6267
write!(authorized_keys_file, "{}", &deploy_key)?
6368
}
@@ -97,8 +102,12 @@ pub fn generate_authorized_key_files(destinations: &[Destination]) -> Result<(),
97102
}
98103

99104
pub fn load_deploy_keypair() -> Result<(), EnokeysError> {
105+
let mut path = dirs::home_dir().unwrap();
106+
path.push(".ssh");
107+
path.push("id_ed25519");
108+
println!("Loading SSH-keyfile {:?}",path);
100109
// TODO: User-configable ssh key
101-
match File::open("~/.ssh/id_ed25519") {
110+
match File::open(path) {
102111
Ok(_) => Ok(()),
103112
Err(e) => Err(EnokeysError::IOError(e))
104113
}

0 commit comments

Comments
 (0)