Command runner args, Paths and AsRef
This commit is contained in:
parent
5d5e9dfcb4
commit
3ccf64fac1
32 changed files with 696 additions and 721 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
|
@ -19,8 +20,10 @@ impl<'a, C: CommandRunner> TlsKey<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_path(&self) -> String {
|
||||
format!("/etc/ssl/private/{}.key", self.domain)
|
||||
fn get_path(&self) -> PathBuf {
|
||||
["/etc/ssl/private", &format!("{}.key", self.domain)]
|
||||
.iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_bytes(&self) -> u32 {
|
||||
|
|
@ -36,13 +39,20 @@ impl<'a, C: CommandRunner> fmt::Display for TlsKey<'a, C> {
|
|||
|
||||
impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !Path::new(&self.get_path()).exists() {
|
||||
if !self.get_path().exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let output = self.command_runner.get_output(
|
||||
"openssl",
|
||||
&["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"],
|
||||
&[
|
||||
OsStr::new("rsa"),
|
||||
"-in".as_ref(),
|
||||
self.get_path().as_ref(),
|
||||
"-noout".as_ref(),
|
||||
"-check".as_ref(),
|
||||
"-text".as_ref(),
|
||||
],
|
||||
)?;
|
||||
Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
}
|
||||
|
|
@ -51,10 +61,10 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
|
|||
self.command_runner.run_successfully(
|
||||
"openssl",
|
||||
&[
|
||||
"genrsa",
|
||||
"-out",
|
||||
&self.get_path(),
|
||||
&self.get_bytes().to_string(),
|
||||
OsStr::new("genrsa"),
|
||||
"-out".as_ref(),
|
||||
self.get_path().as_ref(),
|
||||
self.get_bytes().to_string().as_ref(),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue