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.

61 lines
1.2 KiB

7 years ago
5 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
5 years ago
5 years ago
5 years ago
7 years ago
7 years ago
5 years ago
5 years ago
5 years ago
5 years ago
7 years ago
5 years ago
  1. use crate::command_runner::CommandRunner;
  2. use crate::symbols::Symbol;
  3. use std::borrow::Borrow;
  4. use std::error::Error;
  5. use std::path::Path;
  6. #[derive(Debug)]
  7. pub struct Csr<C, D, K, P> {
  8. command_runner: C,
  9. domain: D,
  10. key_path: K,
  11. csr_path: P,
  12. }
  13. impl<C, D, K, P> Csr<C, D, K, P> {
  14. pub fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
  15. Self {
  16. command_runner,
  17. domain,
  18. key_path,
  19. csr_path,
  20. }
  21. }
  22. }
  23. impl<C: CommandRunner, D: Borrow<str>, K: Borrow<Path>, P: Borrow<Path>> Symbol
  24. for Csr<C, D, K, P>
  25. {
  26. fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
  27. if !self.csr_path.borrow().exists() {
  28. return Ok(false);
  29. }
  30. let output = self.command_runner.get_stderr(
  31. "openssl",
  32. args!["req", "-in", self.csr_path.borrow(), "-noout", "-verify",],
  33. )?;
  34. Ok(output == b"verify OK\n")
  35. }
  36. fn execute(&self) -> Result<(), Box<dyn Error>> {
  37. self.command_runner.run_successfully(
  38. "openssl",
  39. args![
  40. "req",
  41. "-new",
  42. "-sha256",
  43. "-key",
  44. self.key_path.borrow(),
  45. "-out",
  46. self.csr_path.borrow(),
  47. "-subj",
  48. format!("/CN={}", self.domain.borrow()),
  49. ],
  50. )?;
  51. Ok(())
  52. }
  53. }
  54. #[cfg(test)]
  55. mod test {}