Browse Source

Cargo fix

master
Adrian Heine 5 years ago
parent
commit
9bab810b91
  1. 2
      src/bin.rs
  2. 6
      src/command_runner.rs
  3. 16
      src/factory.rs
  4. 6
      src/loggers.rs
  5. 12
      src/repository.rs
  6. 30
      src/schema.rs
  7. 8
      src/storage.rs
  8. 8
      src/symbols/acme/account_key.rs
  9. 8
      src/symbols/acme/cert.rs
  10. 8
      src/symbols/acme/chain.rs
  11. 10
      src/symbols/acme/user.rs
  12. 10
      src/symbols/dir.rs
  13. 30
      src/symbols/factory.rs
  14. 8
      src/symbols/file.rs
  15. 10
      src/symbols/git/checkout.rs
  16. 10
      src/symbols/git/submodules.rs
  17. 24
      src/symbols/hook.rs
  18. 26
      src/symbols/list.rs
  19. 12
      src/symbols/mariadb/database.rs
  20. 14
      src/symbols/mariadb/database_dump.rs
  21. 12
      src/symbols/mariadb/user.rs
  22. 26
      src/symbols/mod.rs
  23. 10
      src/symbols/nginx/server.rs
  24. 8
      src/symbols/noop.rs
  25. 8
      src/symbols/npm.rs
  26. 8
      src/symbols/owner.rs
  27. 10
      src/symbols/postgresql/database.rs
  28. 14
      src/symbols/postgresql/database_dump.rs
  29. 10
      src/symbols/stored_directory.rs
  30. 22
      src/symbols/systemd/node_js_user_service.rs
  31. 8
      src/symbols/systemd/reload.rs
  32. 10
      src/symbols/systemd/user_session.rs
  33. 8
      src/symbols/tls/csr.rs
  34. 8
      src/symbols/tls/key.rs
  35. 8
      src/symbols/tls/self_signed_cert.rs
  36. 18
      src/symbols/user.rs
  37. 10
      src/symbols/wordpress/plugin.rs
  38. 14
      src/symbols/wordpress/translation.rs

2
src/bin.rs

@ -1,7 +1,7 @@
use std::process::exit; use std::process::exit;
use std::env; use std::env;
pub fn schematics_main(run: &Fn (bool) -> Result<(), ()>) {
pub fn schematics_main(run: &dyn Fn (bool) -> Result<(), ()>) {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let dry_run = match args.len() { let dry_run = match args.len() {
1 => false, 1 => false,

6
src/command_runner.rs

@ -6,21 +6,21 @@ use std::process::Output;
pub trait CommandRunner { pub trait CommandRunner {
fn run_with_args<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult<Output>; fn run_with_args<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult<Output>;
fn get_output<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<Vec<u8>, Box<Error>> {
fn get_output<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<Vec<u8>, Box<dyn Error>> {
let output = try!(self.run_with_args(program, args)); let output = try!(self.run_with_args(program, args));
if !output.status.success() { if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into()); return Err(try!(String::from_utf8(output.stderr)).into());
} }
Ok(output.stdout) Ok(output.stdout)
} }
fn get_stderr<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<Vec<u8>, Box<Error>> {
fn get_stderr<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<Vec<u8>, Box<dyn Error>> {
let output = try!(self.run_with_args(program, args)); let output = try!(self.run_with_args(program, args));
if !output.status.success() { if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into()); return Err(try!(String::from_utf8(output.stderr)).into());
} }
Ok(output.stderr) Ok(output.stderr)
} }
fn run_successfully<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<(), Box<Error>> {
fn run_successfully<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<(), Box<dyn Error>> {
let output = try!(self.run_with_args(program, args)); let output = try!(self.run_with_args(program, args));
if output.status.success() { if output.status.success() {
Ok(()) Ok(())

16
src/factory.rs

@ -27,7 +27,7 @@ impl Factory {
DefaultSymbolRepository::new(command_runner) DefaultSymbolRepository::new(command_runner)
} }
pub fn get_symbol_runner<'a, RUNNER: SymbolRunner, REPO: SymbolRepository<'a>>(&self, symbol_runner: &'a RUNNER, repo: &'a REPO) -> Box<'a + SymbolRunner> {
pub fn get_symbol_runner<'a, RUNNER: SymbolRunner, REPO: SymbolRepository<'a>>(&self, symbol_runner: &'a RUNNER, repo: &'a REPO) -> Box<dyn 'a + SymbolRunner> {
let runner1 = ReportingSymbolRunner::new(symbol_runner, StdErrLogger); let runner1 = ReportingSymbolRunner::new(symbol_runner, StdErrLogger);
let runner2 = NonRepeatingSymbolRunner::new(runner1); let runner2 = NonRepeatingSymbolRunner::new(runner1);
Box::new(RequirementsResolvingSymbolRunner::new(runner2, repo)) Box::new(RequirementsResolvingSymbolRunner::new(runner2, repo))
@ -60,7 +60,7 @@ impl<'a, C: 'a + CommandRunner> DefaultSymbolRepository<'a, SystemUserAdder<'a,
} }
impl<'a, C: CommandRunner> SymbolRepository<'a> for DefaultSymbolRepository<'a, SystemUserAdder<'a, C>, C> { impl<'a, C: CommandRunner> SymbolRepository<'a> for DefaultSymbolRepository<'a, SystemUserAdder<'a, C>, C> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<Symbol + 'a>> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<dyn Symbol + 'a>> {
match resource.get_type() { match resource.get_type() {
"user" => Some(Box::new(User::new( "user" => Some(Box::new(User::new(
resource.get_value().to_string().into(), resource.get_value().to_string().into(),
@ -74,12 +74,12 @@ impl<'a, C: CommandRunner> SymbolRepository<'a> for DefaultSymbolRepository<'a,
Box::new(List::new(vec![ Box::new(List::new(vec![
Box::new(Dir::new(value.to_string())), Box::new(Dir::new(value.to_string())),
Box::new(Owner::new(value.to_string(), matches[1].to_string().into(), self.command_runner)) Box::new(Owner::new(value.to_string(), matches[1].to_string().into(), self.command_runner))
])) as Box<Symbol>
])) as Box<dyn Symbol>
} else if let Some(matches) = self.home.captures(value) { } else if let Some(matches) = self.home.captures(value) {
Box::new( Box::new(
User::new(matches[1].to_string().into(), self.command_runner, &self.user_adder) User::new(matches[1].to_string().into(), self.command_runner, &self.user_adder)
) as Box<Symbol>
} else { Box::new(Dir::new(value.to_string())) as Box<Symbol> }
) as Box<dyn Symbol>
} else { Box::new(Dir::new(value.to_string())) as Box<dyn Symbol> }
) )
}, },
"file" => { "file" => {
@ -88,17 +88,17 @@ impl<'a, C: CommandRunner> SymbolRepository<'a> for DefaultSymbolRepository<'a,
Some(Box::new(TlsCsr::new( Some(Box::new(TlsCsr::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner self.command_runner
)) as Box<Symbol>)
)) as Box<dyn Symbol>)
} else if let Some(matches) = self.private_key.captures(value) { } else if let Some(matches) = self.private_key.captures(value) {
Some(Box::new(TlsKey::new( Some(Box::new(TlsKey::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner self.command_runner
)) as Box<Symbol>)
)) as Box<dyn Symbol>)
} else if let Some(matches) = self.systemd_linger.captures(value) { } else if let Some(matches) = self.systemd_linger.captures(value) {
Some(Box::new(SystemdUserSession::new( Some(Box::new(SystemdUserSession::new(
matches[1].to_string().into(), matches[1].to_string().into(),
self.command_runner self.command_runner
)) as Box<Symbol>)
)) as Box<dyn Symbol>)
} else { None } } else { None }
}, },
_ => None _ => None

6
src/loggers.rs

@ -18,17 +18,17 @@ impl Logger for StdErrLogger {
} }
pub struct FilteringLogger<'a> { pub struct FilteringLogger<'a> {
logger: &'a mut Logger
logger: &'a mut dyn Logger
} }
impl<'a> FilteringLogger<'a> { impl<'a> FilteringLogger<'a> {
pub fn new(logger: &'a mut Logger) -> Self {
pub fn new(logger: &'a mut dyn Logger) -> Self {
FilteringLogger { logger } FilteringLogger { logger }
} }
} }
impl<'a> Logger for FilteringLogger<'a> { impl<'a> Logger for FilteringLogger<'a> {
fn debug(&mut self, str: &str) {
fn debug(&mut self, _str: &str) {
return return
} }
fn write(&mut self, str: &str) { fn write(&mut self, str: &str) {

12
src/repository.rs

@ -4,27 +4,27 @@ use symbols::Symbol;
use resources::Resource; use resources::Resource;
pub trait SymbolRepository<'a> { pub trait SymbolRepository<'a> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<Symbol + 'a>>;
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<dyn Symbol + 'a>>;
} }
impl<'a, C> SymbolRepository<'a> for C where C: Fn(&Resource) -> Option<Box<Symbol + 'a>> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<Symbol + 'a>> {
impl<'a, C> SymbolRepository<'a> for C where C: Fn(&Resource) -> Option<Box<dyn Symbol + 'a>> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<dyn Symbol + 'a>> {
self(resource) self(resource)
} }
} }
pub struct DispatchingSymbolRepository<'a> { pub struct DispatchingSymbolRepository<'a> {
repositories: HashMap<&'a str, Box<SymbolRepository<'a> + 'a>>
repositories: HashMap<&'a str, Box<dyn SymbolRepository<'a> + 'a>>
} }
impl<'a> DispatchingSymbolRepository<'a> { impl<'a> DispatchingSymbolRepository<'a> {
pub fn new(repositories: HashMap<&'a str, Box<SymbolRepository<'a> + 'a>>) -> Self {
pub fn new(repositories: HashMap<&'a str, Box<dyn SymbolRepository<'a> + 'a>>) -> Self {
DispatchingSymbolRepository { repositories } DispatchingSymbolRepository { repositories }
} }
} }
impl<'a> SymbolRepository<'a> for DispatchingSymbolRepository<'a> { impl<'a> SymbolRepository<'a> for DispatchingSymbolRepository<'a> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<Symbol + 'a>> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<dyn Symbol + 'a>> {
self.repositories.get(resource.get_type()).and_then(|repo| repo.get_symbol(resource)) self.repositories.get(resource.get_type()).and_then(|repo| repo.get_symbol(resource))
} }
} }

30
src/schema.rs

@ -8,7 +8,7 @@ use symbols::{Symbol, SymbolRunner};
#[derive(Debug)] #[derive(Debug)]
pub enum SymbolRunError { pub enum SymbolRunError {
Symbol(Box<Error>),
Symbol(Box<dyn Error>),
ExecuteDidNotReach(()) ExecuteDidNotReach(())
} }
@ -19,7 +19,7 @@ impl Error for SymbolRunError {
SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol" SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
SymbolRunError::Symbol(ref e) => Some(&**e), SymbolRunError::Symbol(ref e) => Some(&**e),
SymbolRunError::ExecuteDidNotReach(_) => None SymbolRunError::ExecuteDidNotReach(_) => None
@ -47,7 +47,7 @@ impl<L: Logger> InitializingSymbolRunner<L> {
} }
impl<L: Logger> SymbolRunner for InitializingSymbolRunner<L> { impl<L: Logger> SymbolRunner for InitializingSymbolRunner<L> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{ {
let mut logger = self.logger.borrow_mut(); let mut logger = self.logger.borrow_mut();
let target_reached = try!(symbol.target_reached()); let target_reached = try!(symbol.target_reached());
@ -78,7 +78,7 @@ impl<L: Logger> DrySymbolRunner<L> {
} }
impl<L: Logger> SymbolRunner for DrySymbolRunner<L> { impl<L: Logger> SymbolRunner for DrySymbolRunner<L> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{ {
let mut logger = self.logger.borrow_mut(); let mut logger = self.logger.borrow_mut();
let target_reached = try!(symbol.target_reached()); let target_reached = try!(symbol.target_reached());
@ -99,7 +99,7 @@ impl<'a, R, L> ReportingSymbolRunner<'a, R, L> where R: SymbolRunner, L: Logger
} }
impl<'a, R, L> SymbolRunner for ReportingSymbolRunner<'a, R, L> where R: SymbolRunner, L: Logger { impl<'a, R, L> SymbolRunner for ReportingSymbolRunner<'a, R, L> where R: SymbolRunner, L: Logger {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{ {
let mut logger = self.1.borrow_mut(); let mut logger = self.1.borrow_mut();
logger.debug(format!("Running symbol {}", symbol).as_str()); logger.debug(format!("Running symbol {}", symbol).as_str());
@ -131,7 +131,7 @@ impl<R> NonRepeatingSymbolRunner<R> where R: SymbolRunner {
} }
impl<R: SymbolRunner> SymbolRunner for NonRepeatingSymbolRunner<R> { impl<R: SymbolRunner> SymbolRunner for NonRepeatingSymbolRunner<R> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{ {
if let Some(resources) = symbol.provides() { if let Some(resources) = symbol.provides() {
let mut done = self.done.borrow_mut(); let mut done = self.done.borrow_mut();
@ -151,7 +151,7 @@ impl<R: SymbolRunner> SymbolRunner for NonRepeatingSymbolRunner<R> {
} }
use std::marker::PhantomData; use std::marker::PhantomData;
pub struct RequirementsResolvingSymbolRunner<'a, 's, R: 'a + SymbolRunner, G: 'a + SymbolRepository<'s>>(R, &'a G, PhantomData<Box<Symbol + 's>>);
pub struct RequirementsResolvingSymbolRunner<'a, 's, R: 'a + SymbolRunner, G: 'a + SymbolRepository<'s>>(R, &'a G, PhantomData<Box<dyn Symbol + 's>>);
impl<'s, 'a: 's, R, G> RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: SymbolRunner, G: SymbolRepository<'s> { impl<'s, 'a: 's, R, G> RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: SymbolRunner, G: SymbolRepository<'s> {
pub fn new(symbol_runner: R, symbol_repo: &'a G) -> Self { pub fn new(symbol_runner: R, symbol_repo: &'a G) -> Self {
@ -160,7 +160,7 @@ impl<'s, 'a: 's, R, G> RequirementsResolvingSymbolRunner<'a, 's, R, G> where R:
} }
impl<'s, 'a: 's, R, G> SymbolRunner for RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: SymbolRunner, G: SymbolRepository<'s> { impl<'s, 'a: 's, R, G> SymbolRunner for RequirementsResolvingSymbolRunner<'a, 's, R, G> where R: SymbolRunner, G: SymbolRepository<'s> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{ {
for resource in symbol.get_prerequisites() { for resource in symbol.get_prerequisites() {
if let Some(dep) = self.1.get_symbol(&resource) { if let Some(dep) = self.1.get_symbol(&resource) {
@ -202,23 +202,23 @@ mod test {
} }
struct DummySymbol<'a> { struct DummySymbol<'a> {
_execute: &'a Fn() -> Result<(), Box<Error>>,
_target_reached: &'a Fn() -> Result<bool, Box<Error>>
_execute: &'a dyn Fn() -> Result<(), Box<dyn Error>>,
_target_reached: &'a dyn Fn() -> Result<bool, Box<dyn Error>>
} }
impl<'b> Symbol for DummySymbol<'b> { impl<'b> Symbol for DummySymbol<'b> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
(self._target_reached)() (self._target_reached)()
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
(self._execute)() (self._execute)()
} }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }
@ -230,7 +230,7 @@ mod test {
} }
impl<'a> DummySymbol<'a> { impl<'a> DummySymbol<'a> {
fn new(target_reached: &'a Fn() -> Result<bool, Box<Error>>, execute: &'a Fn() -> Result<(), Box<Error>>) -> DummySymbol<'a> {
fn new(target_reached: &'a dyn Fn() -> Result<bool, Box<dyn Error>>, execute: &'a dyn Fn() -> Result<(), Box<dyn Error>>) -> DummySymbol<'a> {
DummySymbol { _target_reached: target_reached, _execute: execute } DummySymbol { _target_reached: target_reached, _execute: execute }
} }
} }

8
src/storage.rs

@ -5,8 +5,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
pub trait Storage { pub trait Storage {
fn write_filename(&self) -> String; fn write_filename(&self) -> String;
fn read_filename(&self) -> Result<String, Box<Error>>;
fn recent_date(&self) -> Result<u64, Box<Error>>;
fn read_filename(&self) -> Result<String, Box<dyn Error>>;
fn recent_date(&self) -> Result<u64, Box<dyn Error>>;
} }
#[derive(Clone)] #[derive(Clone)]
@ -30,11 +30,11 @@ impl Storage for SimpleStorage {
self.get_path(Some(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs())) self.get_path(Some(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()))
} }
fn read_filename(&self) -> Result<String, Box<Error>> {
fn read_filename(&self) -> Result<String, Box<dyn Error>> {
Ok(self.get_path(Some(try!(self.recent_date())))) Ok(self.get_path(Some(try!(self.recent_date()))))
} }
fn recent_date(&self) -> Result<u64, Box<Error>> {
fn recent_date(&self) -> Result<u64, Box<dyn Error>> {
let dir = self.get_path(None); let dir = self.get_path(None);
try!(read_dir(dir)) try!(read_dir(dir))
.map(|entry| entry.ok().and_then(|e| e.file_name().into_string().ok()).and_then(|filename| u64::from_str(&filename).ok())) .map(|entry| entry.ok().and_then(|e| e.file_name().into_string().ok()).and_then(|filename| u64::from_str(&filename).ok()))

8
src/symbols/acme/account_key.rs

@ -29,7 +29,7 @@ impl<'a, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> { impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.path.exists() { if !self.path.exists() {
return Ok(false); return Ok(false);
} }
@ -37,7 +37,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("openssl", &["genrsa".as_ref(), "-out".as_ref(), self.path.as_os_str(), self.get_bytes().to_string().as_ref()]) self.command_runner.run_successfully("openssl", &["genrsa".as_ref(), "-out".as_ref(), self.path.as_os_str(), self.get_bytes().to_string().as_ref()])
} }
@ -45,11 +45,11 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
vec![ Resource::new("dir", self.path.parent().unwrap().to_string_lossy() ) ] vec![ Resource::new("dir", self.path.parent().unwrap().to_string_lossy() ) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/acme/cert.rs

@ -37,7 +37,7 @@ impl<'a, C: CommandRunner> fmt::Display for AcmeCert<'a, C> {
const DAYS_IN_SECONDS: u32 = 24*60*60; const DAYS_IN_SECONDS: u32 = 24*60*60;
impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(&self.get_cert_path()).exists() { if !Path::new(&self.get_cert_path()).exists() {
return Ok(false); return Ok(false);
} }
@ -52,7 +52,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
} }
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
let output = try!(self.command_runner.get_output("acme-tiny", &["--account-key", "/home/acme/account.key", "--csr", &self.get_csr_path(), "--acme-dir", "/home/acme/challenges/"])); let output = try!(self.command_runner.get_output("acme-tiny", &["--account-key", "/home/acme/account.key", "--csr", &self.get_csr_path(), "--acme-dir", "/home/acme/challenges/"]));
let mut file = try!(FsFile::create(self.get_cert_path())); let mut file = try!(FsFile::create(self.get_cert_path()));
try!(file.write_all(&output)); try!(file.write_all(&output));
@ -63,11 +63,11 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
vec![ Resource::new("file", self.get_csr_path()) ] vec![ Resource::new("file", self.get_csr_path()) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/acme/chain.rs

@ -37,7 +37,7 @@ impl<'a, C: CommandRunner> fmt::Display for AcmeCertChain<'a, C> {
const DAYS_IN_SECONDS: u32 = 24*60*60; const DAYS_IN_SECONDS: u32 = 24*60*60;
impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> { impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(&self.get_cert_chain_path()).exists() { if !Path::new(&self.get_cert_chain_path()).exists() {
return Ok(false); return Ok(false);
} }
@ -50,7 +50,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
Ok(self.command_runner.run_successfully("openssl", &["verify", "-untrusted", "/home/acme/lets_encrypt_x3_cross_signed.pem", &self.get_cert_chain_path()]).is_ok()) Ok(self.command_runner.run_successfully("openssl", &["verify", "-untrusted", "/home/acme/lets_encrypt_x3_cross_signed.pem", &self.get_cert_chain_path()]).is_ok())
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
let output = try!(self.command_runner.get_output("cat", &[self.get_single_cert_path().as_ref(), "/home/acme/lets_encrypt_x3_cross_signed.pem"])); let output = try!(self.command_runner.get_output("cat", &[self.get_single_cert_path().as_ref(), "/home/acme/lets_encrypt_x3_cross_signed.pem"]));
let mut file = try!(FsFile::create(self.get_cert_chain_path())); let mut file = try!(FsFile::create(self.get_cert_chain_path()));
try!(file.write_all(&output)); try!(file.write_all(&output));
@ -61,11 +61,11 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
vec![ Resource::new("file", self.get_single_cert_path()) ] vec![ Resource::new("file", self.get_single_cert_path()) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/acme/user.rs

@ -22,10 +22,10 @@ impl<'a> AcmeUser<'a> {
} }
impl<'a> Symbol for AcmeUser<'a> { impl<'a> Symbol for AcmeUser<'a> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(false) Ok(false)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
fn get_prerequisites(&self) -> Vec<Resource> { fn get_prerequisites(&self) -> Vec<Resource> {
@ -34,11 +34,11 @@ impl<'a> Symbol for AcmeUser<'a> {
fn provides(&self) -> Option<Vec<Resource>> { fn provides(&self) -> Option<Vec<Resource>> {
None None
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }
@ -49,7 +49,7 @@ impl<'a> fmt::Display for AcmeUser<'a> {
} }
} }
pub fn new<'a, S: Into<Cow<'a, str>>, C: CommandRunner, P: 'a + Deref<Target=str>>(command_runner: &'a C, cert: P, user_name: S) -> Box<Symbol + 'a> { // impl trait
pub fn new<'a, S: Into<Cow<'a, str>>, C: CommandRunner, P: 'a + Deref<Target=str>>(command_runner: &'a C, cert: P, user_name: S) -> Box<dyn Symbol + 'a> { // impl trait
let user_name_cow = user_name.into(); let user_name_cow = user_name.into();
let account_key_file: PathBuf = ["/home", user_name_cow.borrow(), "account.key"].iter().collect(); let account_key_file: PathBuf = ["/home", user_name_cow.borrow(), "account.key"].iter().collect();
Box::new(List::new(vec![ Box::new(List::new(vec![

10
src/symbols/dir.rs

@ -18,7 +18,7 @@ impl<D> Dir<D> where D: AsRef<str> {
} }
impl<D> Symbol for Dir<D> where D: AsRef<str> { impl<D> Symbol for Dir<D> where D: AsRef<str> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let metadata = fs::metadata(self.path.as_ref()); let metadata = fs::metadata(self.path.as_ref());
// Check if dir exists // Check if dir exists
if let Err(e) = metadata { if let Err(e) = metadata {
@ -35,8 +35,8 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> {
} }
} }
fn execute(&self) -> Result<(), Box<Error>> {
fs::create_dir(self.path.as_ref()).map_err(|e| Box::new(e) as Box<Error>)
fn execute(&self) -> Result<(), Box<dyn Error>> {
fs::create_dir(self.path.as_ref()).map_err(|e| Box::new(e) as Box<dyn Error>)
} }
fn get_prerequisites(&self) -> Vec<Resource> { fn get_prerequisites(&self) -> Vec<Resource> {
@ -51,11 +51,11 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> {
Some(vec![ Resource::new("dir", self.path.as_ref()) ]) Some(vec![ Resource::new("dir", self.path.as_ref()) ])
} }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

30
src/symbols/factory.rs

@ -47,7 +47,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact
SymbolFactory { command_runner, acme_command_runner, symbol_runner, policy } SymbolFactory { command_runner, acme_command_runner, symbol_runner, policy }
} }
pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box<Action + 'a> {
pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box<dyn Action + 'a> {
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
Box::new(SelfSignedTlsCert::new( Box::new(SelfSignedTlsCert::new(
host.into(), host.into(),
@ -70,7 +70,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact
)).into_action(self.symbol_runner) )).into_action(self.symbol_runner)
])) ]))
} }
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box<Action + 'a> {
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box<dyn Action + 'a> {
Box::new(File::new( Box::new(File::new(
"/etc/nginx/snippets/acme-challenge.conf", "location ^~ /.well-known/acme-challenge/ { "/etc/nginx/snippets/acme-challenge.conf", "location ^~ /.well-known/acme-challenge/ {
alias /home/acme/challenges/; alias /home/acme/challenges/;
@ -83,7 +83,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact
format!("/run/php/{}.sock", user_name) format!("/run/php/{}.sock", user_name)
} }
fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> Box<Action + 'a> {
fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> Box<dyn Action + 'a> {
let socket = self.get_php_fpm_pool_socket_path(user_name); let socket = self.get_php_fpm_pool_socket_path(user_name);
Box::new(Hook::new( Box::new(Hook::new(
File::new( File::new(
@ -105,7 +105,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
)).into_action(self.symbol_runner) )).into_action(self.symbol_runner)
} }
pub fn serve_php<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<Action + 'a> {
pub fn serve_php<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name); let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name); let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
@ -121,7 +121,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
])) ]))
} }
pub fn serve_wordpress<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<Action + 'a> {
pub fn serve_wordpress<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name); let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name); let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
@ -139,7 +139,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
])) ]))
} }
pub fn serve_dokuwiki<'a>(&'a self, host_name: &'static str, root_dir: &'static str) -> Box<Action + 'a> {
pub fn serve_dokuwiki<'a>(&'a self, host_name: &'static str, root_dir: &'static str) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name); let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name); let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
@ -174,7 +174,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
])) ]))
} }
pub fn serve_nextcloud<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<Action + 'a> {
pub fn serve_nextcloud<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name); let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name); let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
@ -236,15 +236,15 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
])) ]))
} }
pub fn serve_redir<'a>(&'a self, host_name: &'static str, target: &'static str) -> Box<Action + 'a> {
pub fn serve_redir<'a>(&'a self, host_name: &'static str, target: &'static str) -> Box<dyn Action + 'a> {
self.get_nginx_acme_server(host_name, NginxServer::new_redir(host_name, target, self.command_runner)) self.get_nginx_acme_server(host_name, NginxServer::new_redir(host_name, target, self.command_runner))
} }
pub fn serve_static<'a>(&'a self, host_name: &'static str, dir: &'a str) -> Box<Action + 'a> {
pub fn serve_static<'a>(&'a self, host_name: &'static str, dir: &'a str) -> Box<dyn Action + 'a> {
self.get_nginx_acme_server(host_name, NginxServer::new_static(host_name, dir, self.command_runner)) self.get_nginx_acme_server(host_name, NginxServer::new_static(host_name, dir, self.command_runner))
} }
pub fn get_stored_directory<'a, T: Into<String>>(&'a self, storage_name: &'static str, target: T) -> (Box<Action + 'a>, Box<Action + 'a>) {
pub fn get_stored_directory<'a, T: Into<String>>(&'a self, storage_name: &'static str, target: T) -> (Box<dyn Action + 'a>, Box<dyn Action + 'a>) {
let data = SimpleStorage::new("/root/data".to_string(), storage_name.to_string()); let data = SimpleStorage::new("/root/data".to_string(), storage_name.to_string());
let string_target = target.into(); let string_target = target.into();
( (
@ -253,7 +253,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
) )
} }
pub fn get_mariadb_database<'a>(&'a self, name: &'static str) -> Box<Action + 'a> {
pub fn get_mariadb_database<'a>(&'a self, name: &'static str) -> Box<dyn Action + 'a> {
let db_dump = SimpleStorage::new("/root/data".to_string(), format!("{}.sql", name)); let db_dump = SimpleStorage::new("/root/data".to_string(), format!("{}.sql", name));
Box::new(ListAction::new(vec![ Box::new(ListAction::new(vec![
Box::new(MariaDBDatabase::new(name.into(), db_dump.read_filename().unwrap().into(), self.command_runner)).into_action(self.symbol_runner), Box::new(MariaDBDatabase::new(name.into(), db_dump.read_filename().unwrap().into(), self.command_runner)).into_action(self.symbol_runner),
@ -261,19 +261,19 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
])) ]))
} }
pub fn get_mariadb_user<'a>(&'a self, user_name: &'static str) -> Box<Action + 'a> {
pub fn get_mariadb_user<'a>(&'a self, user_name: &'static str) -> Box<dyn Action + 'a> {
Box::new(MariaDBUser::new(user_name.into(), self.command_runner)).into_action(self.symbol_runner) Box::new(MariaDBUser::new(user_name.into(), self.command_runner)).into_action(self.symbol_runner)
} }
pub fn get_git_checkout<'a, T: 'a + AsRef<str>>(&'a self, target: T, source: &'a str, branch: &'a str) -> Box<Action + 'a> {
pub fn get_git_checkout<'a, T: 'a + AsRef<str>>(&'a self, target: T, source: &'a str, branch: &'a str) -> Box<dyn Action + 'a> {
Box::new(GitCheckout::new(target, source, branch, self.command_runner)).into_action(self.symbol_runner) Box::new(GitCheckout::new(target, source, branch, self.command_runner)).into_action(self.symbol_runner)
} }
pub fn get_owner<'a, F: 'a + AsRef<str>>(&'a self, file: F, user: &'a str) -> Box<Action + 'a> {
pub fn get_owner<'a, F: 'a + AsRef<str>>(&'a self, file: F, user: &'a str) -> Box<dyn Action + 'a> {
Box::new(Owner::new(file, user.into(), self.command_runner)).into_action(self.symbol_runner) Box::new(Owner::new(file, user.into(), self.command_runner)).into_action(self.symbol_runner)
} }
pub fn get_file<'a, F: 'a + Deref<Target=str>, Q: 'a + AsRef<Path>>(&'a self, path: Q, content: F) -> Box<Action + 'a> {
pub fn get_file<'a, F: 'a + Deref<Target=str>, Q: 'a + AsRef<Path>>(&'a self, path: Q, content: F) -> Box<dyn Action + 'a> {
Box::new(File::new(path, content)).into_action(self.symbol_runner) Box::new(File::new(path, content)).into_action(self.symbol_runner)
} }
} }

8
src/symbols/file.rs

@ -21,7 +21,7 @@ impl<C, D> File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
} }
impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> { impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let file = FsFile::open(self.path.as_ref()); let file = FsFile::open(self.path.as_ref());
// Check if file exists // Check if file exists
if let Err(e) = file { if let Err(e) = file {
@ -44,7 +44,7 @@ impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
} }
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
let mut file = try!(FsFile::create(self.path.as_ref())); let mut file = try!(FsFile::create(self.path.as_ref()));
try!(file.write_all(self.content.as_bytes())); try!(file.write_all(self.content.as_bytes()));
Ok(()) Ok(())
@ -54,11 +54,11 @@ impl<C, D> Symbol for File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
vec![ Resource::new("dir", Path::new(self.path.as_ref()).parent().unwrap().to_string_lossy() ) ] 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> {
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/git/checkout.rs

@ -29,7 +29,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>> fmt::Display for GitCheckout<'a, C, T>
use std::fs::metadata; use std::fs::metadata;
impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> { impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> {
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<dyn Error>> {
let mut new_args = vec!["-C", self.target.as_ref()]; let mut new_args = vec!["-C", self.target.as_ref()];
new_args.extend_from_slice(args); new_args.extend_from_slice(args);
self.command_runner.get_output("git", &new_args) self.command_runner.get_output("git", &new_args)
@ -37,7 +37,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> {
} }
impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> { impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if let Err(e) = metadata(self.target.as_ref()) { if let Err(e) = metadata(self.target.as_ref()) {
return if e.kind() == io::ErrorKind::NotFound { return if e.kind() == io::ErrorKind::NotFound {
Ok(false) Ok(false)
@ -52,7 +52,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
Ok(fetch_head == head) Ok(fetch_head == head)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
if !Path::new(self.target.as_ref()).exists() { if !Path::new(self.target.as_ref()).exists() {
return self.command_runner.run_successfully("git", &["clone", "--depth", "1", "-b", self.branch, self.source, self.target.as_ref()]); return self.command_runner.run_successfully("git", &["clone", "--depth", "1", "-b", self.branch, self.source, self.target.as_ref()]);
} }
@ -69,11 +69,11 @@ impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
Some(vec![ Resource::new("dir", self.target.as_ref().to_string()) ]) Some(vec![ Resource::new("dir", self.target.as_ref().to_string()) ])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/git/submodules.rs

@ -23,7 +23,7 @@ impl<'a, C: CommandRunner> fmt::Display for GitSubmodules<'a, C> {
} }
impl<'a, C: CommandRunner> GitSubmodules<'a, C> { impl<'a, C: CommandRunner> GitSubmodules<'a, C> {
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<dyn Error>> {
let mut new_args = vec!["-C", self.target]; let mut new_args = vec!["-C", self.target];
new_args.extend_from_slice(args); new_args.extend_from_slice(args);
self.command_runner.get_output("git", &new_args) self.command_runner.get_output("git", &new_args)
@ -31,7 +31,7 @@ impl<'a, C: CommandRunner> GitSubmodules<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> { impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(self.target).exists() { if !Path::new(self.target).exists() {
return Ok(false); return Ok(false);
} }
@ -39,16 +39,16 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
Ok(output.lines().all(|line| line.is_empty() || line.starts_with(' '))) Ok(output.lines().all(|line| line.is_empty() || line.starts_with(' ')))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self._run_in_target_repo(&["submodule", "update", "--init"])); try!(self._run_in_target_repo(&["submodule", "update", "--init"]));
Ok(()) Ok(())
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

24
src/symbols/hook.rs

@ -17,11 +17,11 @@ impl<A, B> Hook<A, B> where A: Symbol, B: Symbol {
} }
impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol { impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
self.a.target_reached().and_then(|reached| if reached { self.b.target_reached() } else { Ok(reached) }) self.a.target_reached().and_then(|reached| if reached { self.b.target_reached() } else { Ok(reached) })
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.a.execute()); try!(self.a.execute());
self.b.execute() self.b.execute()
} }
@ -44,11 +44,11 @@ impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol {
if r.is_empty() { None } else { Some(r) } if r.is_empty() { None } else { Some(r) }
} }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }
@ -69,13 +69,13 @@ mod test {
struct ErrSymbol(String); struct ErrSymbol(String);
impl Symbol for ErrSymbol { impl Symbol for ErrSymbol {
fn target_reached(&self) -> Result<bool, Box<Error>> { Err(self.0.clone().into()) }
fn execute(&self) -> Result<(), Box<Error>> { Err(self.0.clone().into()) }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { Err(self.0.clone().into()) }
fn execute(&self) -> Result<(), Box<dyn Error>> { Err(self.0.clone().into()) }
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }
@ -83,13 +83,13 @@ mod test {
struct OkSymbol(bool); struct OkSymbol(bool);
impl Symbol for OkSymbol { impl Symbol for OkSymbol {
fn target_reached(&self) -> Result<bool, Box<Error>> { Ok(self.0) }
fn execute(&self) -> Result<(), Box<Error>> { Ok(()) }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { Ok(self.0) }
fn execute(&self) -> Result<(), Box<dyn Error>> { Ok(()) }
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

26
src/symbols/list.rs

@ -5,17 +5,17 @@ use resources::Resource;
use symbols::{Action, Symbol, SymbolRunner}; use symbols::{Action, Symbol, SymbolRunner};
pub struct List<'a> { pub struct List<'a> {
symbols: Vec<Box<Symbol + 'a>>
symbols: Vec<Box<dyn Symbol + 'a>>
} }
impl<'a> List<'a> { impl<'a> List<'a> {
pub fn new(symbols: Vec<Box<Symbol + 'a>>) -> Self {
pub fn new(symbols: Vec<Box<dyn Symbol + 'a>>) -> Self {
List { symbols } List { symbols }
} }
} }
impl<'a> Symbol for List<'a> { impl<'a> Symbol for List<'a> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
for symbol in &self.symbols { for symbol in &self.symbols {
if !try!(symbol.target_reached()) { if !try!(symbol.target_reached()) {
return Ok(false); return Ok(false);
@ -24,7 +24,7 @@ impl<'a> Symbol for List<'a> {
Ok(true) Ok(true)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
for symbol in &self.symbols { for symbol in &self.symbols {
try!(symbol.execute()); try!(symbol.execute());
} }
@ -51,28 +51,28 @@ impl<'a> Symbol for List<'a> {
if r.is_empty() { None } else { Some(r) } if r.is_empty() { None } else { Some(r) }
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolListAction::new(runner, &self.symbols)) Box::new(SymbolListAction::new(runner, &self.symbols))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(ListAction::new(self.symbols.into_iter().map(|s| s.into_action(runner)).collect())) Box::new(ListAction::new(self.symbols.into_iter().map(|s| s.into_action(runner)).collect()))
} }
} }
struct SymbolListAction<'a> { struct SymbolListAction<'a> {
runner: &'a SymbolRunner,
symbols: &'a [Box<Symbol + 'a>]
runner: &'a dyn SymbolRunner,
symbols: &'a [Box<dyn Symbol + 'a>]
} }
impl<'a> SymbolListAction<'a> { impl<'a> SymbolListAction<'a> {
fn new(runner: &'a SymbolRunner, symbols: &'a [Box<Symbol + 'a>]) -> Self {
fn new(runner: &'a dyn SymbolRunner, symbols: &'a [Box<dyn Symbol + 'a>]) -> Self {
Self { runner, symbols } Self { runner, symbols }
} }
} }
impl<'a> Action for SymbolListAction<'a> { impl<'a> Action for SymbolListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
for symbol in self.symbols { for symbol in self.symbols {
try!(symbol.as_action(self.runner).run()); try!(symbol.as_action(self.runner).run());
} }
@ -81,17 +81,17 @@ impl<'a> Action for SymbolListAction<'a> {
} }
pub struct ListAction<'a> { pub struct ListAction<'a> {
actions: Vec<Box<Action + 'a>>
actions: Vec<Box<dyn Action + 'a>>
} }
impl<'a> ListAction<'a> { impl<'a> ListAction<'a> {
pub fn new(actions: Vec<Box<Action + 'a>>) -> Self {
pub fn new(actions: Vec<Box<dyn Action + 'a>>) -> Self {
Self { actions } Self { actions }
} }
} }
impl<'a> Action for ListAction<'a> { impl<'a> Action for ListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
for action in &self.actions { for action in &self.actions {
try!(action.run()); try!(action.run());
} }

12
src/symbols/mariadb/database.rs

@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> {
MariaDBDatabase { db_name, seed_file, command_runner } MariaDBDatabase { db_name, seed_file, command_runner }
} }
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b))) Ok(try!(String::from_utf8(b)))
} }
@ -29,20 +29,20 @@ impl<'a, C: CommandRunner> fmt::Display for MariaDBDatabase<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for MariaDBDatabase<'a, C> { impl<'a, C: CommandRunner> Symbol for MariaDBDatabase<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
Ok(try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_right() == self.db_name)
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_end() == self.db_name)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name))); 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)]) 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> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

14
src/symbols/mariadb/database_dump.rs

@ -17,7 +17,7 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
DatabaseDump { db_name, storage, command_runner } DatabaseDump { db_name, storage, command_runner }
} }
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b))) Ok(try!(String::from_utf8(b)))
} }
@ -30,22 +30,22 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseD
} }
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let dump_date = try!(self.storage.recent_date()); let dump_date = try!(self.storage.recent_date());
let modified_date = try!(self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))); let modified_date = try!(self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref())));
if modified_date.trim_right() == "NULL" { return Ok(false); }
Ok(try!(u64::from_str(modified_date.trim_right())) <= dump_date)
if modified_date.trim_end() == "NULL" { return Ok(false); }
Ok(try!(u64::from_str(modified_date.trim_end())) <= dump_date)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("sh", &["-c", &format!("mysqldump '{}' > {}", self.db_name.as_ref(), self.storage.write_filename())]) self.command_runner.run_successfully("sh", &["-c", &format!("mysqldump '{}' > {}", self.db_name.as_ref(), self.storage.write_filename())])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

12
src/symbols/mariadb/user.rs

@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> MariaDBUser<'a, C> {
MariaDBUser { user_name, command_runner } MariaDBUser { user_name, command_runner }
} }
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b))) Ok(try!(String::from_utf8(b)))
} }
@ -29,11 +29,11 @@ impl<'a, C: CommandRunner> fmt::Display for MariaDBUser<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for MariaDBUser<'a, C> { impl<'a, C: CommandRunner> Symbol for MariaDBUser<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
Ok(try!(self.run_sql(&format!("SELECT User FROM mysql.user WHERE User = '{}' AND plugin = 'unix_socket'", self.user_name))).trim_right() == self.user_name)
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(try!(self.run_sql(&format!("SELECT User FROM mysql.user WHERE User = '{}' AND plugin = 'unix_socket'", self.user_name))).trim_end() == self.user_name)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.run_sql(&format!("GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket", self.user_name))); try!(self.run_sql(&format!("GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket", self.user_name)));
Ok(()) Ok(())
} }
@ -42,11 +42,11 @@ impl<'a, C: CommandRunner> Symbol for MariaDBUser<'a, C> {
vec![ Resource::new("user", self.user_name.to_string()) ] vec![ Resource::new("user", self.user_name.to_string()) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

26
src/symbols/mod.rs

@ -3,64 +3,64 @@ use std::fmt::Display;
use resources::Resource; use resources::Resource;
pub trait Action { pub trait Action {
fn run(&self) -> Result<(), Box<Error>>;
fn run(&self) -> Result<(), Box<dyn Error>>;
} }
pub trait SymbolRunner { pub trait SymbolRunner {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>;
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>;
} }
impl<R: SymbolRunner + ?Sized> SymbolRunner for Box<R> { impl<R: SymbolRunner + ?Sized> SymbolRunner for Box<R> {
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>> {
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>> {
(**self).run_symbol(symbol) (**self).run_symbol(symbol)
} }
} }
// Symbol // Symbol
pub trait Symbol: Display { pub trait Symbol: Display {
fn target_reached(&self) -> Result<bool, Box<Error>>;
fn execute(&self) -> Result<(), Box<Error>>;
fn target_reached(&self) -> Result<bool, Box<dyn Error>>;
fn execute(&self) -> Result<(), Box<dyn Error>>;
fn get_prerequisites(&self) -> Vec<Resource> { fn get_prerequisites(&self) -> Vec<Resource> {
vec![] vec![]
} }
fn provides(&self) -> Option<Vec<Resource>> { fn provides(&self) -> Option<Vec<Resource>> {
None 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;
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a>;
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a;
} }
// SymbolAction // SymbolAction
pub struct SymbolAction<'a, S: Symbol + 'a> { pub struct SymbolAction<'a, S: Symbol + 'a> {
runner: &'a SymbolRunner,
runner: &'a dyn SymbolRunner,
symbol: &'a S symbol: &'a S
} }
impl<'a, S: Symbol> SymbolAction<'a, S> { impl<'a, S: Symbol> SymbolAction<'a, S> {
pub fn new(runner: &'a SymbolRunner, symbol: &'a S) -> Self {
pub fn new(runner: &'a dyn SymbolRunner, symbol: &'a S) -> Self {
Self { runner, symbol } Self { runner, symbol }
} }
} }
impl<'a, S: Symbol> Action for SymbolAction<'a, S> { impl<'a, S: Symbol> Action for SymbolAction<'a, S> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
self.runner.run_symbol(self.symbol) self.runner.run_symbol(self.symbol)
} }
} }
pub struct OwnedSymbolAction<'a, S: Symbol + 'a> { pub struct OwnedSymbolAction<'a, S: Symbol + 'a> {
runner: &'a SymbolRunner,
runner: &'a dyn SymbolRunner,
symbol: S symbol: S
} }
impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> { impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> {
pub fn new(runner: &'a SymbolRunner, symbol: S) -> Self {
pub fn new(runner: &'a dyn SymbolRunner, symbol: S) -> Self {
Self { runner, symbol } Self { runner, symbol }
} }
} }
impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> { impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
self.runner.run_symbol(&self.symbol) self.runner.run_symbol(&self.symbol)
} }
} }

10
src/symbols/nginx/server.rs

@ -27,7 +27,7 @@ impl<E: Error> Error for NginxServerError<E> {
NginxServerError::GenericError => "Generic error" NginxServerError::GenericError => "Generic error"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
NginxServerError::ExecError(ref e) => Some(e), NginxServerError::ExecError(ref e) => Some(e),
_ => None _ => None
@ -157,7 +157,7 @@ location @proxy {{
} }
impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref<Target=str> { impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref<Target=str> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !try!(self.file.target_reached()) { if !try!(self.file.target_reached()) {
return Ok(false); return Ok(false);
} }
@ -165,7 +165,7 @@ impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref<Ta
Ok(true) Ok(true)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.file.execute()); try!(self.file.execute());
self.command_runner.run_successfully("systemctl", &["reload-or-restart", "nginx"]) self.command_runner.run_successfully("systemctl", &["reload-or-restart", "nginx"])
} }
@ -174,11 +174,11 @@ impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref<Ta
self.file.get_prerequisites() self.file.get_prerequisites()
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/noop.rs

@ -6,17 +6,17 @@ use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct NoopSymbol; pub struct NoopSymbol;
impl Symbol for NoopSymbol { impl Symbol for NoopSymbol {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(true) Ok(true)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {
fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a {
fn into_action<'a>(self: Box<Self>, runner: &'a dyn SymbolRunner) -> Box<dyn Action + 'a> where Self: 'a {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/npm.rs

@ -23,7 +23,7 @@ impl<'a, C: CommandRunner> fmt::Display for NpmInstall<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> { impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(self.target).exists() { if !Path::new(self.target).exists() {
return Ok(false); return Ok(false);
} }
@ -31,15 +31,15 @@ impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> {
Ok(result.status.success() && !String::from_utf8(result.stdout).unwrap().contains("(empty)")) Ok(result.status.success() && !String::from_utf8(result.stdout).unwrap().contains("(empty)"))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("sh", &["-c", &format!("cd '{}' && npm install --production --unsafe-perm", self.target)]) 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> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/owner.rs

@ -24,7 +24,7 @@ impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef<str> {
} }
impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> { impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(self.path.as_ref()).exists() { if !Path::new(self.path.as_ref()).exists() {
return Ok(false); return Ok(false);
} }
@ -33,7 +33,7 @@ impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> {
Ok(actual_uid == target_uid) Ok(actual_uid == target_uid)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("chown", &["-R", self.user_name.borrow(), self.path.as_ref()]) self.command_runner.run_successfully("chown", &["-R", self.user_name.borrow(), self.path.as_ref()])
} }
@ -41,11 +41,11 @@ impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> {
vec![ Resource::new("user", self.user_name.to_string()) ] vec![ Resource::new("user", self.user_name.to_string()) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/postgresql/database.rs

@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> PostgreSQLDatabase<'a, C> {
PostgreSQLDatabase { name, seed_file, command_runner } PostgreSQLDatabase { name, seed_file, command_runner }
} }
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output("su", &["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)])); let b = try!(self.command_runner.get_output("su", &["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)]));
Ok(try!(String::from_utf8(b))) Ok(try!(String::from_utf8(b)))
} }
@ -29,21 +29,21 @@ impl<'a, C: CommandRunner> fmt::Display for PostgreSQLDatabase<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for PostgreSQLDatabase<'a, C> { impl<'a, C: CommandRunner> Symbol for PostgreSQLDatabase<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(try!(self.run_sql(&format!("SELECT datname FROM pg_database WHERE datname LIKE '{}'", self.name))).trim() == self.name) Ok(try!(self.run_sql(&format!("SELECT datname FROM pg_database WHERE datname LIKE '{}'", self.name))).trim() == self.name)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("createuser {}", self.name)])?; self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("createuser {}", self.name)])?;
self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("createdb -E UTF8 -T template0 -O {} {0}", self.name)])?; self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("createdb -E UTF8 -T template0 -O {} {0}", self.name)])?;
self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("psql '{}' < {}", self.name, self.seed_file)]) self.command_runner.run_successfully("su", &["-", "postgres", "-c", &format!("psql '{}' < {}", self.name, self.seed_file)])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

14
src/symbols/postgresql/database_dump.rs

@ -17,7 +17,7 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
DatabaseDump { db_name, storage, command_runner } DatabaseDump { db_name, storage, command_runner }
} }
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b))) Ok(try!(String::from_utf8(b)))
} }
@ -30,22 +30,22 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseD
} }
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let dump_date = try!(self.storage.recent_date()); let dump_date = try!(self.storage.recent_date());
let modified_date = try!(self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))); let modified_date = try!(self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref())));
if modified_date.trim_right() == "NULL" { return Ok(false); }
Ok(try!(u64::from_str(modified_date.trim_right())) <= dump_date)
if modified_date.trim_end() == "NULL" { return Ok(false); }
Ok(try!(u64::from_str(modified_date.trim_end())) <= dump_date)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("sh", &["-c", &format!("mysqldump '{}' > {}", self.db_name.as_ref(), self.storage.write_filename())]) self.command_runner.run_successfully("sh", &["-c", &format!("mysqldump '{}' > {}", self.db_name.as_ref(), self.storage.write_filename())])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/stored_directory.rs

@ -34,7 +34,7 @@ impl<'a, S, C: CommandRunner> fmt::Display for StoredDirectory<'a, S, C> where S
} }
impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Storage { impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Storage {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let metadata = fs::metadata(self.path.as_ref()); let metadata = fs::metadata(self.path.as_ref());
// Check if dir exists // Check if dir exists
if let Err(e) = metadata { if let Err(e) = metadata {
@ -50,7 +50,7 @@ impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Stor
let dump_date = try!(self.storage.recent_date()); let dump_date = try!(self.storage.recent_date());
let output = try!(self.command_runner.get_output("sh", &["-c", &format!("find {} -printf '%T@\\n' | sort -r | head -n1 | grep '^[0-9]\\+' -o", self.path)])); let output = try!(self.command_runner.get_output("sh", &["-c", &format!("find {} -printf '%T@\\n' | sort -r | head -n1 | grep '^[0-9]\\+' -o", self.path)]));
let modified_date = try!(u64::from_str(try!(String::from_utf8(output)).trim_right()));
let modified_date = try!(u64::from_str(try!(String::from_utf8(output)).trim_end()));
if if self.dir == StorageDirection::Save { modified_date > dump_date } else { dump_date > modified_date } { if if self.dir == StorageDirection::Save { modified_date > dump_date } else { dump_date > modified_date } {
let output = try!(self.command_runner.run_with_args("diff", &["-rq", &try!(self.storage.read_filename()), self.path.borrow()])); let output = try!(self.command_runner.run_with_args("diff", &["-rq", &try!(self.storage.read_filename()), self.path.borrow()]));
match output.status.code() { match output.status.code() {
@ -61,7 +61,7 @@ impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Stor
} else { Ok(true) } } else { Ok(true) }
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
if self.dir == StorageDirection::Load { if self.dir == StorageDirection::Load {
try!(self.command_runner.run_successfully("rm", &["-rf", self.path.borrow()])); try!(self.command_runner.run_successfully("rm", &["-rf", self.path.borrow()]));
self.command_runner.run_successfully("cp", &["-a", &try!(self.storage.read_filename()), self.path.borrow()]) self.command_runner.run_successfully("cp", &["-a", &try!(self.storage.read_filename()), self.path.borrow()])
@ -87,11 +87,11 @@ impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Stor
} }
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

22
src/symbols/systemd/node_js_user_service.rs

@ -33,7 +33,7 @@ impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed" NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e), NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
_ => None _ => None
@ -60,7 +60,7 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: Com
impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner { impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner {
pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self { pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), service_name);
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_end(), service_name);
let port = format!("/var/tmp/{}-{}.socket", user_name, service_name); let port = format!("/var/tmp/{}-{}.socket", user_name, service_name);
let content = format!("[Service] let content = format!("[Service]
@ -91,18 +91,18 @@ WantedBy=default.target
impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner { impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result<String, Box<Error>> {
fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result<String, Box<dyn Error>> {
let mut tries = 5; let mut tries = 5;
loop { loop {
let result = try!(self.command_runner.run_with_args("systemctl", args)); let result = try!(self.command_runner.run_with_args("systemctl", args));
if !result.status.success() { if !result.status.success() {
let raw_stderr = try!(String::from_utf8(result.stderr)); let raw_stderr = try!(String::from_utf8(result.stderr));
let stderr = raw_stderr.trim_right();
let stderr = raw_stderr.trim_end();
if stderr != "Failed to connect to bus: No such file or directory" { if stderr != "Failed to connect to bus: No such file or directory" {
return Err(stderr.into()); return Err(stderr.into());
} }
} else { } else {
return Ok(try!(String::from_utf8(result.stdout)).trim_right().to_string());
return Ok(try!(String::from_utf8(result.stdout)).trim_end().to_string());
} }
tries -= 1; tries -= 1;
if tries == 0 { if tries == 0 {
@ -112,7 +112,7 @@ impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R:
} }
} }
fn check_if_service(&self) -> Result<bool, Box<Error>> {
fn check_if_service(&self) -> Result<bool, Box<dyn Error>> {
loop { loop {
let active_state = try!(self.systemctl_wait_for_dbus(&["--user", "show", "--property", "ActiveState", self.service_name])); let active_state = try!(self.systemctl_wait_for_dbus(&["--user", "show", "--property", "ActiveState", self.service_name]));
match active_state.as_ref() { match active_state.as_ref() {
@ -126,14 +126,14 @@ impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R:
} }
impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner { impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !(try!(self.file.target_reached())) { if !(try!(self.file.target_reached())) {
return Ok(false); return Ok(false);
} }
self.check_if_service() self.check_if_service()
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.file.execute()); try!(self.file.execute());
try!(self.systemctl_wait_for_dbus(&["--user", "enable", self.service_name])); try!(self.systemctl_wait_for_dbus(&["--user", "enable", self.service_name]));
try!(self.systemctl_wait_for_dbus(&["--user", "restart", self.service_name])); try!(self.systemctl_wait_for_dbus(&["--user", "restart", self.service_name]));
@ -143,7 +143,7 @@ impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Targ
} }
let file_name = format!("/var/tmp/{}-{}.socket", self.user_name, self.service_name); let file_name = format!("/var/tmp/{}-{}.socket", self.user_name, self.service_name);
fs::metadata(&file_name).map(|_| ()).map_err(|e| Box::new(e) as Box<Error>)
fs::metadata(&file_name).map(|_| ()).map_err(|e| Box::new(e) as Box<dyn Error>)
} }
fn get_prerequisites(&self) -> Vec<Resource> { fn get_prerequisites(&self) -> Vec<Resource> {
@ -152,11 +152,11 @@ impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Targ
r r
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/systemd/reload.rs

@ -16,19 +16,19 @@ impl<'a, C: CommandRunner> ReloadService<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> { impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(true) Ok(true)
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("systemctl", &["reload-or-restart", self.service]) self.command_runner.run_successfully("systemctl", &["reload-or-restart", self.service])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

10
src/symbols/systemd/user_session.rs

@ -19,7 +19,7 @@ impl<E: Error> Error for SystemdUserSessionError<E> {
SystemdUserSessionError::GenericError => "Generic error" SystemdUserSessionError::GenericError => "Generic error"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
SystemdUserSessionError::ExecError(ref e) => Some(e), SystemdUserSessionError::ExecError(ref e) => Some(e),
_ => None _ => None
@ -45,22 +45,22 @@ impl<'a, C: CommandRunner> SystemdUserSession<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for SystemdUserSession<'a, C> { impl<'a, C: CommandRunner> Symbol for SystemdUserSession<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let mut path = PathBuf::from("/var/lib/systemd/linger"); let mut path = PathBuf::from("/var/lib/systemd/linger");
path.push(self.user_name.borrow() as &str); path.push(self.user_name.borrow() as &str);
Ok(path.exists()) Ok(path.exists())
// Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes` // Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes`
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("loginctl", &["enable-linger", self.user_name.borrow()]) self.command_runner.run_successfully("loginctl", &["enable-linger", self.user_name.borrow()])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/tls/csr.rs

@ -33,7 +33,7 @@ impl<'a, C: CommandRunner> fmt::Display for TlsCsr<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(&self.get_csr_path()).exists() { if !Path::new(&self.get_csr_path()).exists() {
return Ok(false); return Ok(false);
} }
@ -42,7 +42,7 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
Ok(output == b"verify OK\n") Ok(output == b"verify OK\n")
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.command_runner.run_successfully("openssl", &["req", "-new", "-sha256", "-key", &self.get_key_path(), "-out", &self.get_csr_path(), "-subj", &format!("/CN={}", self.domain)])); try!(self.command_runner.run_successfully("openssl", &["req", "-new", "-sha256", "-key", &self.get_key_path(), "-out", &self.get_csr_path(), "-subj", &format!("/CN={}", self.domain)]));
Ok(()) Ok(())
} }
@ -51,11 +51,11 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
vec![Resource::new("file", self.get_key_path())] vec![Resource::new("file", self.get_key_path())]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/tls/key.rs

@ -32,7 +32,7 @@ impl<'a, C: CommandRunner> fmt::Display for TlsKey<'a, C> {
} }
impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> { impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(&self.get_path()).exists() { if !Path::new(&self.get_path()).exists() {
return Ok(false); return Ok(false);
} }
@ -41,15 +41,15 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("openssl", &["genrsa", "-out", &self.get_path(), &self.get_bytes().to_string()]) 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> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

8
src/symbols/tls/self_signed_cert.rs

@ -35,7 +35,7 @@ impl<'a, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, C> {
const DAYS_IN_SECONDS: u32 = 24*60*60; const DAYS_IN_SECONDS: u32 = 24*60*60;
impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> { impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !Path::new(&self.get_cert_path()).exists() { if !Path::new(&self.get_cert_path()).exists() {
return Ok(false); return Ok(false);
} }
@ -53,7 +53,7 @@ println!("{}", output.status.code().unwrap());
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.command_runner.run_successfully("openssl", &["req", "-x509", "-sha256", "-days", "90", "-key", &self.get_key_path(), "-out", &self.get_cert_path(), "-subj", &format!("/CN={}", self.domain)]) self.command_runner.run_successfully("openssl", &["req", "-x509", "-sha256", "-days", "90", "-key", &self.get_key_path(), "-out", &self.get_cert_path(), "-subj", &format!("/CN={}", self.domain)])
} }
@ -61,11 +61,11 @@ println!("{}", output.status.code().unwrap());
vec![Resource::new("file", self.get_key_path())] vec![Resource::new("file", self.get_key_path())]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

18
src/symbols/user.rs

@ -10,7 +10,7 @@ use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub enum UserAdderError { pub enum UserAdderError {
AlreadyExists, AlreadyExists,
UnknownError, UnknownError,
ImplError(Box<Error>)
ImplError(Box<dyn Error>)
} }
impl Error for UserAdderError { impl Error for UserAdderError {
@ -21,7 +21,7 @@ impl Error for UserAdderError {
UserAdderError::ImplError(_) => "User adding error" UserAdderError::ImplError(_) => "User adding error"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
UserAdderError::ImplError(ref e) => Some(e.as_ref()), UserAdderError::ImplError(ref e) => Some(e.as_ref()),
_ => None _ => None
@ -53,7 +53,7 @@ impl Error for UserError {
UserError::GenericError => "Could not find out if user exists" UserError::GenericError => "Could not find out if user exists"
} }
} }
fn cause(&self) -> Option<&Error> {
fn cause(&self) -> Option<&dyn Error> {
match self { match self {
_ => None _ => None
} }
@ -88,7 +88,7 @@ impl<'a, C: CommandRunner, A: 'a + UserAdder> fmt::Display for User<'a, C, A> {
} }
impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> { impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let output = try!(self.command_runner.run_with_args("getent", &["passwd", &*self.user_name])); let output = try!(self.command_runner.run_with_args("getent", &["passwd", &*self.user_name]));
match output.status.code() { match output.status.code() {
Some(2) => Ok(false), Some(2) => Ok(false),
@ -97,19 +97,19 @@ impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> {
} }
} }
fn execute(&self) -> Result<(), Box<Error>> {
self.user_adder.add_user(&*self.user_name).map_err(|e| Box::new(e) as Box<Error>)
fn execute(&self) -> Result<(), Box<dyn Error>> {
self.user_adder.add_user(&*self.user_name).map_err(|e| Box::new(e) as Box<dyn Error>)
} }
fn provides(&self) -> Option<Vec<Resource>> { fn provides(&self) -> Option<Vec<Resource>> {
Some(vec![Resource::new("user", self.user_name.to_string())]) Some(vec![Resource::new("user", self.user_name.to_string())])
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }
@ -183,7 +183,7 @@ mod test {
struct DummyUserAdder; struct DummyUserAdder;
impl UserAdder for DummyUserAdder { impl UserAdder for DummyUserAdder {
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> {
fn add_user(&self, _user_name: &str) -> Result<(), UserAdderError> {
Ok(()) Ok(())
} }
} }

10
src/symbols/wordpress/plugin.rs

@ -28,7 +28,7 @@ impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandR
} }
impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner { impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !self.get_path().exists() { if !self.get_path().exists() {
return Ok(false); return Ok(false);
} }
@ -45,7 +45,7 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>,
}; };
}, },
Ok(file) => { Ok(file) => {
let mut reader = BufReader::new(file);
let reader = BufReader::new(file);
let regex = Regex::new("(?m)^(Plugin URI|Version): (.+)$")?; let regex = Regex::new("(?m)^(Plugin URI|Version): (.+)$")?;
for content in reader.lines() { for content in reader.lines() {
for matches in regex.captures_iter(&(content?)) { for matches in regex.captures_iter(&(content?)) {
@ -62,7 +62,7 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>,
Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###)) Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
let source = format!("https://downloads.wordpress.org/plugin/{}.zip", &*self.name); let source = format!("https://downloads.wordpress.org/plugin/{}.zip", &*self.name);
let zip = format!("/tmp/{}.zip", &*self.name); let zip = format!("/tmp/{}.zip", &*self.name);
try!(self.command_runner.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()])); try!(self.command_runner.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()]));
@ -77,11 +77,11 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str>,
} }
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

14
src/symbols/wordpress/translation.rs

@ -31,7 +31,7 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str>, R: Co
impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner { impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
fn get_pairs(&self) -> Vec<(String, String)> { fn get_pairs(&self) -> Vec<(String, String)> {
let version_x = self.version.trim_right_matches(|c: char| c.is_digit(10)).to_owned() + "x";
let version_x = self.version.trim_end_matches(|c: char| c.is_digit(10)).to_owned() + "x";
let locale: &str = self.locale.as_ref(); let locale: &str = self.locale.as_ref();
let path_locale = if locale == "de_DE" { "de".to_owned() } else { locale.to_lowercase().replace('_', "-") }; let path_locale = if locale == "de_DE" { "de".to_owned() } else { locale.to_lowercase().replace('_', "-") };
let mut res = vec![]; let mut res = vec![];
@ -48,7 +48,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRe
} }
impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner { impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let mut newest = String::new(); let mut newest = String::new();
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
for (_, target) in self.get_pairs() { for (_, target) in self.get_pairs() {
@ -61,8 +61,8 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
Err(Box::new(e)) Err(Box::new(e))
}; };
}, },
Ok(mut file) => if target.ends_with(".po") {
let mut reader = BufReader::new(file);
Ok(file) => if target.ends_with(".po") {
let reader = BufReader::new(file);
for content in reader.lines() { for content in reader.lines() {
if let Some(match_result) = match_date.captures(&try!(content)) { if let Some(match_result) = match_date.captures(&try!(content)) {
newest = max(newest, match_result[1].to_string()); newest = max(newest, match_result[1].to_string());
@ -76,7 +76,7 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale.as_ref(), self.version, newest))) Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale.as_ref(), self.version, newest)))
} }
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
for (source, target) in self.get_pairs() { for (source, target) in self.get_pairs() {
try!(self.command_runner.run_successfully("curl", &["--compressed", "-o", &target, &source])); try!(self.command_runner.run_successfully("curl", &["--compressed", "-o", &target, &source]));
} }
@ -87,11 +87,11 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st
vec![ Resource::new("dir", self.path.as_ref()) ] vec![ Resource::new("dir", self.path.as_ref()) ]
} }
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolAction::new(runner, self)) Box::new(SymbolAction::new(runner, self))
} }
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self)) Box::new(OwnedSymbolAction::new(runner, *self))
} }
} }

Loading…
Cancel
Save