A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

7 years ago
  1. use command_runner::{CommandRunner, SetuidCommandRunner};
  2. use symbols::{Action, Symbol, SymbolRunner};
  3. use symbols::acme::{AcmeCert, AcmeCertChain};
  4. use symbols::hook::Hook;
  5. use symbols::list::ListAction;
  6. use symbols::systemd::reload::ReloadService;
  7. use symbols::tls::SelfSignedTlsCert;
  8. pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner>{
  9. command_runner: &'a C,
  10. acme_command_runner: SetuidCommandRunner<'a, C>,
  11. symbol_runner: &'a R
  12. }
  13. impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner> SymbolFactory<'b, C, R> {
  14. pub fn new(command_runner: &'b C, symbol_runner: &'b R) -> Self {
  15. let acme_user = "acme"; // FIXME: CONFIG
  16. let acme_command_runner = SetuidCommandRunner::new(acme_user, command_runner);
  17. SymbolFactory { command_runner: command_runner, acme_command_runner: acme_command_runner, symbol_runner: symbol_runner }
  18. }
  19. pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box<Action + 'a> {
  20. Box::new(ListAction::new(vec![
  21. Box::new(SelfSignedTlsCert::new(
  22. host.into(),
  23. self.command_runner
  24. )).into_action(self.symbol_runner),
  25. Box::new(Hook::new(
  26. nginx_server_symbol,
  27. ReloadService::new("nginx", self.command_runner)
  28. )).into_action(self.symbol_runner),
  29. Box::new(AcmeCert::new(
  30. host.into(),
  31. &self.acme_command_runner
  32. )).into_action(self.symbol_runner),
  33. Box::new(Hook::new(
  34. AcmeCertChain::new(
  35. host.into(),
  36. &self.acme_command_runner
  37. ),
  38. ReloadService::new("nginx", self.command_runner)
  39. )).into_action(self.symbol_runner)
  40. ]))
  41. }
  42. }