Prereqs
This commit is contained in:
parent
7d629e38d8
commit
2ccc56a097
5 changed files with 32 additions and 4 deletions
|
|
@ -22,3 +22,12 @@ impl<'a> Resource for DirResource<'a> {
|
|||
fn get_type(&self) -> &str { "dir" }
|
||||
fn get_value(&self) -> &str { &*self.path }
|
||||
}
|
||||
|
||||
pub struct FileResource<'a> {
|
||||
pub path: Cow<'a, str>
|
||||
}
|
||||
|
||||
impl<'a> Resource for FileResource<'a> {
|
||||
fn get_type(&self) -> &str { "file" }
|
||||
fn get_value(&self) -> &str { &*self.path }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use std::io::{self, Write};
|
|||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::Symbol;
|
||||
use resources::{FileResource, Resource};
|
||||
|
||||
pub struct AcmeCert<'a> {
|
||||
domain: Cow<'a, str>,
|
||||
|
|
@ -20,10 +21,6 @@ impl<'a> AcmeCert<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_key_path(&self) -> String {
|
||||
format!("/etc/ssl/private/{}.key", self.domain)
|
||||
}
|
||||
|
||||
fn get_csr_path(&self) -> String {
|
||||
format!("/etc/ssl/local_certs/{}.csr", self.domain)
|
||||
}
|
||||
|
|
@ -74,6 +71,10 @@ impl<'a> Symbol for AcmeCert<'a> {
|
|||
try!(file.write_all(&output.stdout));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
||||
vec![Box::new(FileResource { path: self.get_csr_path().into() })]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use resources::Resource;
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct Hook<A, B> where A: Symbol, B: Symbol {
|
||||
|
|
@ -23,6 +24,13 @@ impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol {
|
|||
try!(self.a.execute());
|
||||
self.b.execute()
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
||||
let mut r = vec![];
|
||||
r.extend(self.a.get_prerequisites().into_iter());
|
||||
r.extend(self.b.get_prerequisites().into_iter());
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B> fmt::Display for Hook<A, B> where A: Symbol, B: Symbol {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::error::Error;
|
|||
use std::fmt;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use resources::{Resource, FileResource};
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct TlsCsr<'a> {
|
||||
|
|
@ -50,6 +51,10 @@ impl<'a> Symbol for TlsCsr<'a> {
|
|||
let output = try!(self.command_runner.run_with_args("openssl", &["req", "-new", "-sha256", "-key", &self.get_key_path(), "-out", &self.get_csr_path(), "-subj", &format!("/CN={}", self.domain)]).map_err(|e| Box::new(e)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
||||
vec![Box::new(FileResource { path: self.get_key_path().into() })]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::error::Error;
|
|||
use std::fmt;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use resources::{Resource, FileResource};
|
||||
use symbols::Symbol;
|
||||
|
||||
pub struct SelfSignedTlsCert<'a> {
|
||||
|
|
@ -55,6 +56,10 @@ impl<'a> Symbol for SelfSignedTlsCert<'a> {
|
|||
Ok(_) => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
||||
vec![Box::new(FileResource { path: self.get_key_path().into() })]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue