Browse Source

WIP Impl Action

master
Adrian Heine 5 years ago
parent
commit
b8bac1142c
  1. 59
      src/schema.rs
  2. 10
      src/symbols/acme/account_key.rs
  3. 10
      src/symbols/acme/cert.rs
  4. 10
      src/symbols/acme/chain.rs
  5. 10
      src/symbols/dir.rs
  6. 10
      src/symbols/file.rs
  7. 10
      src/symbols/git/checkout.rs
  8. 10
      src/symbols/git/submodules.rs
  9. 12
      src/symbols/hook.rs
  10. 12
      src/symbols/if_already_present.rs
  11. 57
      src/symbols/list.rs
  12. 10
      src/symbols/mariadb/database.rs
  13. 10
      src/symbols/mariadb/database_dump.rs
  14. 10
      src/symbols/mariadb/user.rs
  15. 46
      src/symbols/mod.rs
  16. 10
      src/symbols/nginx/server.rs
  17. 10
      src/symbols/npm.rs
  18. 10
      src/symbols/owner.rs
  19. 10
      src/symbols/stored_directory.rs
  20. 13
      src/symbols/systemd/node_js_user_service.rs
  21. 10
      src/symbols/systemd/reload.rs
  22. 10
      src/symbols/systemd/user_session.rs
  23. 10
      src/symbols/tls/csr.rs
  24. 10
      src/symbols/tls/key.rs
  25. 10
      src/symbols/tls/self_signed_cert.rs
  26. 12
      src/symbols/user.rs
  27. 10
      src/symbols/wordpress/plugin.rs
  28. 10
      src/symbols/wordpress/translation.rs

59
src/schema.rs

@ -1,9 +1,10 @@
use std::cell::RefCell;
use std::error::Error;
use std::fmt;
use loggers::Logger;
use repository::SymbolRepository;
use symbols::Symbol;
use symbols::{Symbol, SymbolRunner};
#[derive(Debug)]
pub enum SymbolRunError {
@ -35,15 +36,20 @@ impl fmt::Display for SymbolRunError {
}
}
pub trait SymbolRunner {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>;
pub struct InitializingSymbolRunner<L: Logger> {
logger: RefCell<L>
}
pub struct InitializingSymbolRunner;
impl<L: Logger> InitializingSymbolRunner<L> {
pub fn new(logger: L) -> Self {
Self { logger: RefCell::new(logger) }
}
}
impl SymbolRunner for InitializingSymbolRunner {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>
impl<L: Logger> SymbolRunner for InitializingSymbolRunner<L> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
{
let mut logger = self.logger.borrow_mut();
let target_reached = try!(symbol.target_reached());
if target_reached {
logger.write(format!("{} already reached", symbol).as_str());
@ -61,11 +67,20 @@ impl SymbolRunner for InitializingSymbolRunner {
}
}
pub struct DrySymbolRunner;
pub struct DrySymbolRunner<L: Logger> {
logger: RefCell<L>
}
impl SymbolRunner for DrySymbolRunner {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>
impl<L: Logger> DrySymbolRunner<L> {
pub fn new(logger: L) -> Self {
Self { logger: RefCell::new(logger) }
}
}
impl<L: Logger> SymbolRunner for DrySymbolRunner<L> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
{
let mut logger = self.logger.borrow_mut();
let target_reached = try!(symbol.target_reached());
logger.debug(format!("Symbol reports target_reached: {:?}", target_reached).as_str());
if !target_reached {
@ -75,19 +90,20 @@ impl SymbolRunner for DrySymbolRunner {
}
}
pub struct ReportingSymbolRunner<'a, R: 'a + SymbolRunner>(&'a R);
pub struct ReportingSymbolRunner<'a, R: 'a + SymbolRunner, L: Logger>(&'a R, RefCell<L>);
impl<'a, R> ReportingSymbolRunner<'a, R> where R: SymbolRunner {
pub fn new(symbol_runner: &'a R) -> Self {
ReportingSymbolRunner(symbol_runner)
impl<'a, R, L> ReportingSymbolRunner<'a, R, L> where R: SymbolRunner, L: Logger {
pub fn new(symbol_runner: &'a R, logger: L) -> Self {
ReportingSymbolRunner(symbol_runner, RefCell::new(logger))
}
}
impl<'a, R> SymbolRunner for ReportingSymbolRunner<'a, R> where R: SymbolRunner {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>
impl<'a, R, L> SymbolRunner for ReportingSymbolRunner<'a, R, L> where R: SymbolRunner, L: Logger {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
{
let mut logger = self.1.borrow_mut();
logger.debug(format!("Running symbol {}", symbol).as_str());
let res = self.0.run_symbol(logger, symbol);
let res = self.0.run_symbol(symbol);
match &res {
&Err(ref e) => {
logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str());
@ -100,7 +116,6 @@ impl<'a, R> SymbolRunner for ReportingSymbolRunner<'a, R> where R: SymbolRunner
}
}
use std::cell::RefCell;
use std::collections::HashSet;
use resources::Resource;
@ -116,7 +131,7 @@ impl<'a, R> NonRepeatingSymbolRunner<'a, R> where R: SymbolRunner {
}
impl<'a, R> SymbolRunner for NonRepeatingSymbolRunner<'a, R> where R: SymbolRunner {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
{
if let Some(resources) = symbol.provides() {
let mut done = self.done.borrow_mut();
@ -131,7 +146,7 @@ impl<'a, R> SymbolRunner for NonRepeatingSymbolRunner<'a, R> where R: SymbolRunn
return Ok(());
}
}
self.upstream.run_symbol(logger, &*symbol)
self.upstream.run_symbol(&*symbol)
}
}
use std::marker::PhantomData;
@ -145,14 +160,14 @@ impl<'a, 's, R, G> RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: Symb
}
impl<'a, 's, R, G> SymbolRunner for RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: SymbolRunner, G: SymbolRepository<'s> {
fn run_symbol<S: ?Sized + Symbol + fmt::Display>(&self, logger: &mut Logger, symbol: &S) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
{
for resource in symbol.get_prerequisites() {
if let Some(dep) = self.1.get_symbol(&resource) {
try!(self.run_symbol(logger, &*dep));
try!(dep.as_action(self).run());
}
}
self.0.run_symbol(logger, &*symbol)
self.0.run_symbol(&*symbol)
}
}

10
src/symbols/acme/account_key.rs

@ -5,7 +5,7 @@ use std::path::Path;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct AcmeAccountKey<'a> {
path: Cow<'a, str>,
@ -51,6 +51,14 @@ impl<'a> Symbol for AcmeAccountKey<'a> {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", Path::new(self.get_path()).parent().unwrap().to_string_lossy() ) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/acme/cert.rs

@ -6,7 +6,7 @@ use std::io::Write;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource;
pub struct AcmeCert<'a> {
@ -62,6 +62,14 @@ impl<'a> Symbol for AcmeCert<'a> {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("file", self.get_csr_path()) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/acme/chain.rs

@ -6,7 +6,7 @@ use std::io::Write;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource;
pub struct AcmeCertChain<'a> {
@ -63,6 +63,14 @@ impl<'a> Symbol for AcmeCertChain<'a> {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("file", self.get_single_cert_path()) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/dir.rs

@ -5,7 +5,7 @@ use std::io;
use std::path::Path;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct Dir<D> where D: AsRef<str> + fmt::Display {
path: D
@ -50,6 +50,14 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> + fmt::Display {
fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![ Resource::new("dir", self.path.to_string()) ])
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<D> fmt::Display for Dir<D> where D: AsRef<str> + fmt::Display {

10
src/symbols/file.rs

@ -6,7 +6,7 @@ use std::io::{Read, Write};
use std::ops::Deref;
use std::path::Path;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource;
pub struct File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {
@ -56,6 +56,14 @@ impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", Path::new(self.path.as_ref()).parent().unwrap().to_string_lossy() ) ]
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<C, D> fmt::Display for File<C, D> where C: Deref<Target=str>, D: AsRef<str> + fmt::Display {

10
src/symbols/git/checkout.rs

@ -5,7 +5,7 @@ use std::path::Path;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct GitCheckout<'a> {
target: &'a str,
@ -72,6 +72,14 @@ impl<'a> Symbol for GitCheckout<'a> {
fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![ Resource::new("dir", self.target.to_string()) ])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/git/submodules.rs

@ -3,7 +3,7 @@ use std::fmt;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct GitSubmodules<'a> {
target: &'a str,
@ -46,6 +46,14 @@ impl<'a> Symbol for GitSubmodules<'a> {
try!(self._run_in_target_repo(&["submodule", "update", "--init"]));
Ok(())
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

12
src/symbols/hook.rs

@ -2,7 +2,7 @@ use std::error::Error;
use std::fmt;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct Hook<A, B> where A: Symbol, B: Symbol {
a: A,
@ -42,6 +42,14 @@ impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol {
}
if r.len() > 0 { Some(r) } else { None }
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<A, B> fmt::Display for Hook<A, B> where A: Symbol, B: Symbol {
@ -55,7 +63,7 @@ mod test {
use std::error::Error;
use std::fmt;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::hook::Hook;
struct ErrSymbol(String);

12
src/symbols/if_already_present.rs

@ -2,7 +2,7 @@ use std::error::Error;
use std::fmt;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct IfAlreadyPresent<A, B> where A: Symbol, B: Symbol {
a: A,
@ -50,6 +50,14 @@ impl<A, B> Symbol for IfAlreadyPresent<A, B> where A: Symbol, B: Symbol {
}
if r.len() > 0 { Some(r) } else { None }
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<A, B> fmt::Display for IfAlreadyPresent<A, B> where A: Symbol, B: Symbol {
@ -63,7 +71,7 @@ mod test {
use std::error::Error;
use std::fmt;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::if_already_present::IfAlreadyPresent;
struct ErrSymbol(String);

57
src/symbols/list.rs

@ -2,7 +2,7 @@ use std::error::Error;
use std::fmt;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, Symbol, SymbolRunner};
pub struct List<'a> {
symbols: Vec<Box<Symbol + 'a>>
@ -17,10 +17,8 @@ impl<'a> List<'a> {
impl<'a> Symbol for List<'a> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
for symbol in &self.symbols {
match symbol.target_reached() {
Ok(false) => return Ok(false),
Err(e) => return Err(e),
Ok(true) => {}
if !try!(symbol.target_reached()) {
return Ok(false);
}
}
Ok(true)
@ -52,6 +50,53 @@ impl<'a> Symbol for List<'a> {
}
if r.len() > 0 { Some(r) } else { None }
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolListAction::new(runner, &self.symbols))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(ListAction::new(self.symbols.into_iter().map(|s| s.into_action(runner)).collect()))
}
}
struct SymbolListAction<'a> {
runner: &'a SymbolRunner,
symbols: &'a Vec<Box<Symbol + 'a>>
}
impl<'a> SymbolListAction<'a> {
fn new(runner: &'a SymbolRunner, symbols: &'a Vec<Box<Symbol + 'a>>) -> Self {
Self { runner: runner, symbols: symbols }
}
}
impl<'a> Action for SymbolListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
for symbol in self.symbols {
try!(symbol.as_action(self.runner).run());
}
Ok(())
}
}
pub struct ListAction<'a> {
actions: Vec<Box<Action + 'a>>
}
impl<'a> ListAction<'a> {
pub fn new(actions: Vec<Box<Action + 'a>>) -> Self {
Self { actions: actions }
}
}
impl<'a> Action for ListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
for action in &self.actions {
try!(action.run());
}
Ok(())
}
}
impl<'a> fmt::Display for List<'a> {
@ -70,7 +115,7 @@ mod test {
use std::error::Error;
use std::fmt;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::hook::List;
struct ErrSymbol(String);

10
src/symbols/mariadb/database.rs

@ -3,7 +3,7 @@ use std::error::Error;
use std::fmt;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct MariaDBDatabase<'a> {
db_name: Cow<'a, str>,
@ -41,6 +41,14 @@ impl<'a> Symbol for MariaDBDatabase<'a> {
try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name)));
self.command_runner.run_successfully("sh", &["-c", &format!("mariadb '{}' < {}", self.db_name, self.seed_file)])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/mariadb/database_dump.rs

@ -4,7 +4,7 @@ use std::fmt;
use std::str::FromStr;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use storage::Storage;
pub struct DatabaseDump<'a, S> where S: Storage {
@ -45,6 +45,14 @@ impl<'a, S> Symbol for DatabaseDump<'a, S> where S: Storage {
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("sh", &["-c", &format!("mysqldump '{}' > {}", self.db_name, self.storage.write_filename())])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/mariadb/user.rs

@ -4,7 +4,7 @@ use std::fmt;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct MariaDBUser<'a> {
user_name: Cow<'a, str>,
@ -44,6 +44,14 @@ impl<'a> Symbol for MariaDBUser<'a> {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("user", self.user_name.to_string()) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

46
src/symbols/mod.rs

@ -2,6 +2,15 @@ use std::error::Error;
use std::fmt::Display;
use resources::Resource;
pub trait Action {
fn run(&self) -> Result<(), Box<Error>>;
}
pub trait SymbolRunner {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>;
}
// Symbol
pub trait Symbol: Display {
fn target_reached(&self) -> Result<bool, Box<Error>>;
fn execute(&self) -> Result<(), Box<Error>>;
@ -11,6 +20,43 @@ pub trait Symbol: Display {
fn provides(&self) -> Option<Vec<Resource>> {
None
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a>;
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a;
}
// SymbolAction
struct SymbolAction<'a, S: Symbol + 'a> {
runner: &'a SymbolRunner,
symbol: &'a S
}
impl<'a, S: Symbol> SymbolAction<'a, S> {
fn new(runner: &'a SymbolRunner, symbol: &'a S) -> Self {
Self { runner: runner, symbol: symbol }
}
}
impl<'a, S: Symbol> Action for SymbolAction<'a, S> {
fn run(&self) -> Result<(), Box<Error>> {
self.runner.run_symbol(self.symbol)
}
}
struct OwnedSymbolAction<'a, S: Symbol + 'a> {
runner: &'a SymbolRunner,
symbol: S
}
impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> {
fn new(runner: &'a SymbolRunner, symbol: S) -> Self {
Self { runner: runner, symbol: symbol }
}
}
impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> {
fn run(&self) -> Result<(), Box<Error>> {
self.runner.run_symbol(&self.symbol)
}
}
pub mod acme;

10
src/symbols/nginx/server.rs

@ -4,7 +4,7 @@ use std::io;
use std::ops::Deref;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::file::File as FileSymbol;
use resources::Resource;
@ -146,6 +146,14 @@ impl<'a, C> Symbol for NginxServer<'a, C> where C: Deref<Target=str> {
fn get_prerequisites(&self) -> Vec<Resource> {
self.file.get_prerequisites()
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, C> fmt::Display for NginxServer<'a, C> where C: Deref<Target=str> {

10
src/symbols/npm.rs

@ -3,7 +3,7 @@ use std::fmt;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct NpmInstall<'a> {
target: &'a str,
@ -37,6 +37,14 @@ impl<'a> Symbol for NpmInstall<'a> {
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("sh", &["-c", &format!("cd '{}' && npm install --production --unsafe-perm", self.target)])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/owner.rs

@ -9,7 +9,7 @@ use users::get_user_by_name;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct Owner<'a, D> where D: AsRef<str> + fmt::Display {
path: D,
@ -40,6 +40,14 @@ impl<'a, D> Symbol for Owner<'a, D> where D: AsRef<str> + fmt::Display {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("user", self.user_name.to_string()) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, D> fmt::Display for Owner<'a, D> where D: AsRef<str> + fmt::Display {

10
src/symbols/stored_directory.rs

@ -8,7 +8,7 @@ use std::str::FromStr;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use storage::Storage;
#[derive(Debug, PartialEq)]
@ -91,6 +91,14 @@ impl<'a, S> Symbol for StoredDirectory<'a, S> where S: Storage {
None
}
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

13
src/symbols/systemd/node_js_user_service.rs

@ -1,8 +1,7 @@
use std::error::Error;
use std::os::unix::fs::PermissionsExt;
use std::fmt;
use std::io;
use std::fs::{self, Metadata};
use std::fs;
use std::process::Output;
use std::thread::sleep;
use std::time::Duration;
@ -10,7 +9,7 @@ use std::ops::Deref;
use command_runner::{CommandRunner, SetuidCommandRunner};
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::file::File as FileSymbol;
#[derive(Debug)]
@ -152,6 +151,14 @@ impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Targ
r.extend(self.file.get_prerequisites().into_iter());
r
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, C, R> fmt::Display for NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {

10
src/symbols/systemd/reload.rs

@ -2,7 +2,7 @@ use std::error::Error;
use std::fmt;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct ReloadService<'a> {
service: &'a str,
@ -26,6 +26,14 @@ impl<'a> Symbol for ReloadService<'a> {
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("systemctl", &["reload-or-restart", self.service])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a> fmt::Display for ReloadService<'a> {

10
src/symbols/systemd/user_session.rs

@ -4,7 +4,7 @@ use std::fmt;
use std::path::PathBuf;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
#[derive(Debug)]
pub enum SystemdUserSessionError<E: Error> {
@ -58,6 +58,14 @@ impl<'a> Symbol for SystemdUserSession<'a> {
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("loginctl", &["enable-linger", self.user_name.borrow()])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a> fmt::Display for SystemdUserSession<'a> {

10
src/symbols/tls/csr.rs

@ -5,7 +5,7 @@ use std::path::Path;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct TlsCsr<'a> {
domain: Cow<'a, str>,
@ -53,6 +53,14 @@ impl<'a> Symbol for TlsCsr<'a> {
fn get_prerequisites(&self) -> Vec<Resource> {
vec![Resource::new("file", self.get_key_path())]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/tls/key.rs

@ -4,7 +4,7 @@ use std::fmt;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct TlsKey<'a> {
domain: Cow<'a, str>,
@ -47,6 +47,14 @@ impl<'a> Symbol for TlsKey<'a> {
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("openssl", &["genrsa", "-out", &self.get_path(), &self.get_bytes().to_string()])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

10
src/symbols/tls/self_signed_cert.rs

@ -5,7 +5,7 @@ use std::path::Path;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct SelfSignedTlsCert<'a> {
domain: Cow<'a, str>,
@ -63,6 +63,14 @@ println!("{}", output.status.code().unwrap());
fn get_prerequisites(&self) -> Vec<Resource> {
vec![Resource::new("file", self.get_key_path())]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
#[cfg(test)]

12
src/symbols/user.rs

@ -5,7 +5,7 @@ use std::io::Error as IoError;
use command_runner::CommandRunner;
use resources::Resource;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
#[derive(Debug, PartialEq)]
pub enum UserAdderError<E: Error> {
@ -110,6 +110,14 @@ impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> {
fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![Resource::new("user", self.user_name.to_string())])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
pub struct SystemUserAdder<'a> {
@ -160,7 +168,7 @@ mod test {
use std::fmt;
use command_runner::StdCommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use symbols::user::User;
use symbols::user::UserAdder;
use symbols::user::UserAdderError;

10
src/symbols/wordpress/plugin.rs

@ -7,7 +7,7 @@ use std::ops::Deref;
use std::path::{Path, PathBuf};
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource;
pub struct WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: 'a + CommandRunner {
@ -66,6 +66,14 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> +
None => vec![]
}
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, C, R> fmt::Display for WordpressPlugin<'a, C, R> where C: Deref<Target=str> + fmt::Display, R: CommandRunner {

10
src/symbols/wordpress/translation.rs

@ -9,7 +9,7 @@ use std::ops::Deref;
use std::path::Path;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
use resources::Resource;
pub struct WordpressTranslation<'a, C, D, R> where C: Deref<Target=str> + fmt::Display, D: AsRef<str> + fmt::Display, R: 'a + CommandRunner {
@ -88,6 +88,14 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: Deref<Ta
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", self.path.as_ref()) ]
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, C, D, R> fmt::Display for WordpressTranslation<'a, C, D, R> where C: Deref<Target=str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {

Loading…
Cancel
Save