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.

88 lines
2.0 KiB

3 years ago
6 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
3 years ago
5 years ago
6 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
4 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
4 years ago
5 years ago
3 years ago
5 years ago
7 years ago
6 years ago
3 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
3 years ago
6 years ago
3 years ago
5 years ago
6 years ago
5 years ago
  1. use resources::Resource;
  2. use std::error::Error;
  3. use std::fmt::Display;
  4. pub trait Action {
  5. fn run(&self) -> Result<(), Box<dyn Error>>;
  6. }
  7. pub trait SymbolRunner {
  8. fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>;
  9. }
  10. impl<R: SymbolRunner + ?Sized> SymbolRunner for Box<R> {
  11. fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>> {
  12. (**self).run_symbol(symbol)
  13. }
  14. }
  15. // Symbol
  16. pub trait Symbol: Display {
  17. fn target_reached(&self) -> Result<bool, Box<dyn Error>>;
  18. fn execute(&self) -> Result<(), Box<dyn Error>>;
  19. fn get_prerequisites(&self) -> Vec<Resource> {
  20. vec![]
  21. }
  22. fn provides(&self) -> Option<Vec<Resource>> {
  23. None
  24. }
  25. fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a>;
  26. fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a>
  27. where
  28. Self: 'a;
  29. }
  30. // SymbolAction
  31. pub struct SymbolAction<'a, S: Symbol + 'a> {
  32. runner: &'a dyn SymbolRunner,
  33. symbol: &'a S,
  34. }
  35. impl<'a, S: Symbol> SymbolAction<'a, S> {
  36. pub fn new(runner: &'a dyn SymbolRunner, symbol: &'a S) -> Self {
  37. Self { runner, symbol }
  38. }
  39. }
  40. impl<'a, S: Symbol> Action for SymbolAction<'a, S> {
  41. fn run(&self) -> Result<(), Box<dyn Error>> {
  42. self.runner.run_symbol(self.symbol)
  43. }
  44. }
  45. pub struct OwnedSymbolAction<'a, S: Symbol + 'a> {
  46. runner: &'a dyn SymbolRunner,
  47. symbol: S,
  48. }
  49. impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> {
  50. pub fn new(runner: &'a dyn SymbolRunner, symbol: S) -> Self {
  51. Self { runner, symbol }
  52. }
  53. }
  54. impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> {
  55. fn run(&self) -> Result<(), Box<dyn Error>> {
  56. self.runner.run_symbol(&self.symbol)
  57. }
  58. }
  59. pub mod acme;
  60. pub mod cron;
  61. pub mod dir;
  62. pub mod factory;
  63. pub mod file;
  64. pub mod git;
  65. pub mod hook;
  66. pub mod list;
  67. pub mod mariadb;
  68. pub mod nginx;
  69. pub mod noop;
  70. pub mod npm;
  71. pub mod owner;
  72. pub mod postgresql;
  73. pub mod stored_directory;
  74. pub mod systemd;
  75. pub mod tls;
  76. pub mod user;
  77. pub mod wordpress;