From c91eb2f04e01b0f283a7b53fce55c3b06557f69e Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Thu, 21 Sep 2017 21:08:56 +0200 Subject: [PATCH] Add factory --- src/symbols/factory.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ src/symbols/mod.rs | 1 + 2 files changed, 48 insertions(+) create mode 100644 src/symbols/factory.rs diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs new file mode 100644 index 0000000..2019b33 --- /dev/null +++ b/src/symbols/factory.rs @@ -0,0 +1,47 @@ +use command_runner::{CommandRunner, SetuidCommandRunner}; +use symbols::{Action, Symbol, SymbolRunner}; +use symbols::acme::{AcmeCert, AcmeCertChain}; +use symbols::hook::Hook; +use symbols::list::ListAction; +use symbols::systemd::reload::ReloadService; +use symbols::tls::SelfSignedTlsCert; + +pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner>{ + command_runner: &'a C, + acme_command_runner: SetuidCommandRunner<'a, C>, + symbol_runner: &'a R +} + +impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner> SymbolFactory<'b, C, R> { + + pub fn new(command_runner: &'b C, symbol_runner: &'b R) -> Self { + let acme_user = "acme"; // FIXME: CONFIG + + let acme_command_runner = SetuidCommandRunner::new(acme_user, command_runner); + SymbolFactory { command_runner: command_runner, acme_command_runner: acme_command_runner, symbol_runner: symbol_runner } + } + + pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box { + Box::new(ListAction::new(vec![ + Box::new(SelfSignedTlsCert::new( + host.into(), + self.command_runner + )).into_action(self.symbol_runner), + Box::new(Hook::new( + nginx_server_symbol, + ReloadService::new("nginx", self.command_runner) + )).into_action(self.symbol_runner), + Box::new(AcmeCert::new( + host.into(), + &self.acme_command_runner + )).into_action(self.symbol_runner), + Box::new(Hook::new( + AcmeCertChain::new( + host.into(), + &self.acme_command_runner + ), + ReloadService::new("nginx", self.command_runner) + )).into_action(self.symbol_runner) + ])) + } +} diff --git a/src/symbols/mod.rs b/src/symbols/mod.rs index caa361f..c0f391c 100644 --- a/src/symbols/mod.rs +++ b/src/symbols/mod.rs @@ -61,6 +61,7 @@ impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> { pub mod acme; pub mod dir; +pub mod factory; pub mod file; pub mod git; pub mod hook;