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.

55 lines
2.0 KiB

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