-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the way we inject Passphrase
- Loading branch information
Showing
9 changed files
with
106 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod app_ctx; | ||
pub use app_ctx::*; | ||
mod ssh_private_key_cache; | ||
pub use ssh_private_key_cache::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct CertData { | ||
pub private_key: String, | ||
pub pass_phrase: Option<String>, | ||
} | ||
|
||
pub struct SshPrivateKeyCache { | ||
cert_data: Option<CertData>, | ||
} | ||
|
||
impl SshPrivateKeyCache { | ||
pub async fn new(path: Option<String>, pass_key: Option<String>) -> Self { | ||
if path.is_none() { | ||
return Self { cert_data: None }; | ||
} | ||
|
||
let path = rust_extensions::file_utils::format_path(path.unwrap()); | ||
|
||
let cert = tokio::fs::read_to_string(path.as_str()).await; | ||
|
||
if let Err(err) = &cert { | ||
panic!( | ||
"Can not read ssh private key file '{}'. Error: {}", | ||
path.as_str(), | ||
err | ||
); | ||
} | ||
|
||
Self { | ||
cert_data: CertData { | ||
private_key: cert.unwrap(), | ||
pass_phrase: pass_key, | ||
} | ||
.into(), | ||
} | ||
} | ||
|
||
pub fn get_cert_data(&self) -> Option<CertData> { | ||
self.cert_data.clone() | ||
} | ||
|
||
pub fn set_ssh_pass_phrase(&mut self, pass_phrase: Option<String>) { | ||
if let Some(cert_data) = &mut self.cert_data { | ||
cert_data.pass_phrase = pass_phrase; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters