Browse Source

Update

master
Adrian Heine 5 years ago
parent
commit
2f18fbad27
  1. 14
      src/symbols/acme/account_key.rs
  2. 9
      src/symbols/factory.rs

14
src/symbols/acme/account_key.rs

@ -20,10 +20,6 @@ impl<'a, C: CommandRunner> AcmeAccountKey<'a, C> {
}
}
fn get_path(&self) -> &Path {
self.path.borrow()
}
fn get_bytes(&self) -> u32 {
4096
}
@ -31,25 +27,25 @@ impl<'a, C: CommandRunner> AcmeAccountKey<'a, C> {
impl<'a, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "AcmeAccountKey {}", self.get_path().display())
write!(f, "AcmeAccountKey {}", self.path.display())
}
}
impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
if !self.get_path().exists() {
if !self.path.exists() {
return Ok(false);
}
let stdout = try!(self.command_runner.get_output("openssl", &["rsa".as_ref(), "-in".as_ref(), self.get_path().as_os_str(), "-noout".as_ref(), "-check".as_ref(), "-text".as_ref()]));
let stdout = try!(self.command_runner.get_output("openssl", &["rsa".as_ref(), "-in".as_ref(), self.path.as_os_str(), "-noout".as_ref(), "-check".as_ref(), "-text".as_ref()]));
Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
}
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("openssl", &["genrsa".as_ref(), "-out".as_ref(), self.get_path().as_os_str(), self.get_bytes().to_string().as_ref()])
self.command_runner.run_successfully("openssl", &["genrsa".as_ref(), "-out".as_ref(), self.path.as_os_str(), self.get_bytes().to_string().as_ref()])
}
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", self.get_path().parent().unwrap().to_string_lossy() ) ]
vec![ Resource::new("dir", self.path.parent().unwrap().to_string_lossy() ) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {

9
src/symbols/factory.rs

@ -1,6 +1,7 @@
use command_runner::{CommandRunner, SetuidCommandRunner};
use symbols::{Action, Symbol, SymbolRunner};
use symbols::acme::{AcmeCert, AcmeCertChain};
use symbols::file::File;
use symbols::hook::Hook;
use symbols::list::ListAction;
use symbols::systemd::reload::ReloadService;
@ -43,4 +44,12 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner> SymbolFactory<'b, C, R> {
)).into_action(self.symbol_runner)
]))
}
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box<Action + 'a> {
Box::new(File::new(
"/etc/nginx/snippets/acme-challenge.conf", "location ^~ /.well-known/acme-challenge/ {
alias /home/acme/challenges/;
try_files $uri =404;
}"
)).into_action(self.symbol_runner)
}
}
Loading…
Cancel
Save