Browse Source

Add factory

master
Adrian Heine 5 years ago
parent
commit
c91eb2f04e
  1. 47
      src/symbols/factory.rs
  2. 1
      src/symbols/mod.rs

47
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<Action + 'a> {
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)
]))
}
}

1
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;

Loading…
Cancel
Save