Browse Source

Prereqs

master
Adrian Heine 8 years ago
parent
commit
2ccc56a097
  1. 9
      src/resources/mod.rs
  2. 9
      src/symbols/acme/cert.rs
  3. 8
      src/symbols/hook.rs
  4. 5
      src/symbols/tls/csr.rs
  5. 5
      src/symbols/tls/self_signed_cert.rs

9
src/resources/mod.rs

@ -22,3 +22,12 @@ impl<'a> Resource for DirResource<'a> {
fn get_type(&self) -> &str { "dir" } fn get_type(&self) -> &str { "dir" }
fn get_value(&self) -> &str { &*self.path } 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 }
}

9
src/symbols/acme/cert.rs

@ -6,6 +6,7 @@ use std::io::{self, Write};
use command_runner::CommandRunner; use command_runner::CommandRunner;
use symbols::Symbol; use symbols::Symbol;
use resources::{FileResource, Resource};
pub struct AcmeCert<'a> { pub struct AcmeCert<'a> {
domain: Cow<'a, str>, 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 { fn get_csr_path(&self) -> String {
format!("/etc/ssl/local_certs/{}.csr", self.domain) format!("/etc/ssl/local_certs/{}.csr", self.domain)
} }
@ -74,6 +71,10 @@ impl<'a> Symbol for AcmeCert<'a> {
try!(file.write_all(&output.stdout)); try!(file.write_all(&output.stdout));
Ok(()) Ok(())
} }
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
vec![Box::new(FileResource { path: self.get_csr_path().into() })]
}
} }
#[cfg(test)] #[cfg(test)]

8
src/symbols/hook.rs

@ -1,6 +1,7 @@
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use resources::Resource;
use symbols::Symbol; use symbols::Symbol;
pub struct Hook<A, B> where A: Symbol, B: 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()); try!(self.a.execute());
self.b.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 { impl<A, B> fmt::Display for Hook<A, B> where A: Symbol, B: Symbol {

5
src/symbols/tls/csr.rs

@ -3,6 +3,7 @@ use std::error::Error;
use std::fmt; use std::fmt;
use command_runner::CommandRunner; use command_runner::CommandRunner;
use resources::{Resource, FileResource};
use symbols::Symbol; use symbols::Symbol;
pub struct TlsCsr<'a> { 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))); 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(()) Ok(())
} }
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
vec![Box::new(FileResource { path: self.get_key_path().into() })]
}
} }
#[cfg(test)] #[cfg(test)]

5
src/symbols/tls/self_signed_cert.rs

@ -3,6 +3,7 @@ use std::error::Error;
use std::fmt; use std::fmt;
use command_runner::CommandRunner; use command_runner::CommandRunner;
use resources::{Resource, FileResource};
use symbols::Symbol; use symbols::Symbol;
pub struct SelfSignedTlsCert<'a> { pub struct SelfSignedTlsCert<'a> {
@ -55,6 +56,10 @@ impl<'a> Symbol for SelfSignedTlsCert<'a> {
Ok(_) => Ok(()) Ok(_) => Ok(())
} }
} }
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
vec![Box::new(FileResource { path: self.get_key_path().into() })]
}
} }
#[cfg(test)] #[cfg(test)]

Loading…
Cancel
Save