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; 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) ])) } pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box { 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) } }