From 9bab810b914f73e60d9f0c7afcafeb100dce5667 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Thu, 12 Sep 2019 22:59:22 +0200 Subject: [PATCH] Cargo fix --- src/bin.rs | 2 +- src/command_runner.rs | 6 ++--- src/factory.rs | 16 +++++------ src/loggers.rs | 6 ++--- src/repository.rs | 12 ++++----- src/schema.rs | 30 ++++++++++----------- src/storage.rs | 8 +++--- src/symbols/acme/account_key.rs | 8 +++--- src/symbols/acme/cert.rs | 8 +++--- src/symbols/acme/chain.rs | 8 +++--- src/symbols/acme/user.rs | 10 +++---- src/symbols/dir.rs | 10 +++---- src/symbols/factory.rs | 30 ++++++++++----------- src/symbols/file.rs | 8 +++--- src/symbols/git/checkout.rs | 10 +++---- src/symbols/git/submodules.rs | 10 +++---- src/symbols/hook.rs | 24 ++++++++--------- src/symbols/list.rs | 26 +++++++++--------- src/symbols/mariadb/database.rs | 12 ++++----- src/symbols/mariadb/database_dump.rs | 14 +++++----- src/symbols/mariadb/user.rs | 12 ++++----- src/symbols/mod.rs | 26 +++++++++--------- src/symbols/nginx/server.rs | 10 +++---- src/symbols/noop.rs | 8 +++--- src/symbols/npm.rs | 8 +++--- src/symbols/owner.rs | 8 +++--- src/symbols/postgresql/database.rs | 10 +++---- src/symbols/postgresql/database_dump.rs | 14 +++++----- src/symbols/stored_directory.rs | 10 +++---- src/symbols/systemd/node_js_user_service.rs | 22 +++++++-------- src/symbols/systemd/reload.rs | 8 +++--- src/symbols/systemd/user_session.rs | 10 +++---- src/symbols/tls/csr.rs | 8 +++--- src/symbols/tls/key.rs | 8 +++--- src/symbols/tls/self_signed_cert.rs | 8 +++--- src/symbols/user.rs | 18 ++++++------- src/symbols/wordpress/plugin.rs | 10 +++---- src/symbols/wordpress/translation.rs | 14 +++++----- 38 files changed, 235 insertions(+), 235 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 6ab956b..97f5bcb 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,7 +1,7 @@ use std::process::exit; use std::env; -pub fn schematics_main(run: &Fn (bool) -> Result<(), ()>) { +pub fn schematics_main(run: &dyn Fn (bool) -> Result<(), ()>) { let args: Vec = env::args().collect(); let dry_run = match args.len() { 1 => false, diff --git a/src/command_runner.rs b/src/command_runner.rs index 30ca60f..39a7250 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -6,21 +6,21 @@ use std::process::Output; pub trait CommandRunner { fn run_with_args + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult; - fn get_output + ?Sized>(&self, program: &str, args: &[&S]) -> Result, Box> { + fn get_output + ?Sized>(&self, program: &str, args: &[&S]) -> Result, Box> { let output = try!(self.run_with_args(program, args)); if !output.status.success() { return Err(try!(String::from_utf8(output.stderr)).into()); } Ok(output.stdout) } - fn get_stderr + ?Sized>(&self, program: &str, args: &[&S]) -> Result, Box> { + fn get_stderr + ?Sized>(&self, program: &str, args: &[&S]) -> Result, Box> { let output = try!(self.run_with_args(program, args)); if !output.status.success() { return Err(try!(String::from_utf8(output.stderr)).into()); } Ok(output.stderr) } - fn run_successfully + ?Sized>(&self, program: &str, args: &[&S]) -> Result<(), Box> { + fn run_successfully + ?Sized>(&self, program: &str, args: &[&S]) -> Result<(), Box> { let output = try!(self.run_with_args(program, args)); if output.status.success() { Ok(()) diff --git a/src/factory.rs b/src/factory.rs index 99452db..b09bdf2 100644 --- a/src/factory.rs +++ b/src/factory.rs @@ -27,7 +27,7 @@ impl Factory { 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 { let runner1 = ReportingSymbolRunner::new(symbol_runner, StdErrLogger); let runner2 = NonRepeatingSymbolRunner::new(runner1); 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> { - fn get_symbol(&'a self, resource: &Resource) -> Option> { + fn get_symbol(&'a self, resource: &Resource) -> Option> { match resource.get_type() { "user" => Some(Box::new(User::new( 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(Dir::new(value.to_string())), Box::new(Owner::new(value.to_string(), matches[1].to_string().into(), self.command_runner)) - ])) as Box + ])) as Box } else if let Some(matches) = self.home.captures(value) { Box::new( User::new(matches[1].to_string().into(), self.command_runner, &self.user_adder) - ) as Box - } else { Box::new(Dir::new(value.to_string())) as Box } + ) as Box + } else { Box::new(Dir::new(value.to_string())) as Box } ) }, "file" => { @@ -88,17 +88,17 @@ impl<'a, C: CommandRunner> SymbolRepository<'a> for DefaultSymbolRepository<'a, Some(Box::new(TlsCsr::new( matches[1].to_string().into(), self.command_runner - )) as Box) + )) as Box) } else if let Some(matches) = self.private_key.captures(value) { Some(Box::new(TlsKey::new( matches[1].to_string().into(), self.command_runner - )) as Box) + )) as Box) } else if let Some(matches) = self.systemd_linger.captures(value) { Some(Box::new(SystemdUserSession::new( matches[1].to_string().into(), self.command_runner - )) as Box) + )) as Box) } else { None } }, _ => None diff --git a/src/loggers.rs b/src/loggers.rs index 33eeb87..99994ff 100644 --- a/src/loggers.rs +++ b/src/loggers.rs @@ -18,17 +18,17 @@ impl Logger for StdErrLogger { } pub struct FilteringLogger<'a> { - logger: &'a mut Logger + logger: &'a mut dyn Logger } impl<'a> FilteringLogger<'a> { - pub fn new(logger: &'a mut Logger) -> Self { + pub fn new(logger: &'a mut dyn Logger) -> Self { FilteringLogger { logger } } } impl<'a> Logger for FilteringLogger<'a> { - fn debug(&mut self, str: &str) { + fn debug(&mut self, _str: &str) { return } fn write(&mut self, str: &str) { diff --git a/src/repository.rs b/src/repository.rs index 4429f89..752bb28 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -4,27 +4,27 @@ use symbols::Symbol; use resources::Resource; pub trait SymbolRepository<'a> { - fn get_symbol(&'a self, resource: &Resource) -> Option>; + fn get_symbol(&'a self, resource: &Resource) -> Option>; } -impl<'a, C> SymbolRepository<'a> for C where C: Fn(&Resource) -> Option> { - fn get_symbol(&'a self, resource: &Resource) -> Option> { +impl<'a, C> SymbolRepository<'a> for C where C: Fn(&Resource) -> Option> { + fn get_symbol(&'a self, resource: &Resource) -> Option> { self(resource) } } pub struct DispatchingSymbolRepository<'a> { - repositories: HashMap<&'a str, Box + 'a>> + repositories: HashMap<&'a str, Box + 'a>> } impl<'a> DispatchingSymbolRepository<'a> { - pub fn new(repositories: HashMap<&'a str, Box + 'a>>) -> Self { + pub fn new(repositories: HashMap<&'a str, Box + 'a>>) -> Self { DispatchingSymbolRepository { repositories } } } impl<'a> SymbolRepository<'a> for DispatchingSymbolRepository<'a> { - fn get_symbol(&'a self, resource: &Resource) -> Option> { + fn get_symbol(&'a self, resource: &Resource) -> Option> { self.repositories.get(resource.get_type()).and_then(|repo| repo.get_symbol(resource)) } } diff --git a/src/schema.rs b/src/schema.rs index 7cc8619..46901a7 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -8,7 +8,7 @@ use symbols::{Symbol, SymbolRunner}; #[derive(Debug)] pub enum SymbolRunError { - Symbol(Box), + Symbol(Box), ExecuteDidNotReach(()) } @@ -19,7 +19,7 @@ impl Error for SymbolRunError { SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { SymbolRunError::Symbol(ref e) => Some(&**e), SymbolRunError::ExecuteDidNotReach(_) => None @@ -47,7 +47,7 @@ impl InitializingSymbolRunner { } impl SymbolRunner for InitializingSymbolRunner { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { let mut logger = self.logger.borrow_mut(); let target_reached = try!(symbol.target_reached()); @@ -78,7 +78,7 @@ impl DrySymbolRunner { } impl SymbolRunner for DrySymbolRunner { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { let mut logger = self.logger.borrow_mut(); 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 { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { let mut logger = self.1.borrow_mut(); logger.debug(format!("Running symbol {}", symbol).as_str()); @@ -131,7 +131,7 @@ impl NonRepeatingSymbolRunner where R: SymbolRunner { } impl SymbolRunner for NonRepeatingSymbolRunner { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { if let Some(resources) = symbol.provides() { let mut done = self.done.borrow_mut(); @@ -151,7 +151,7 @@ impl SymbolRunner for NonRepeatingSymbolRunner { } use std::marker::PhantomData; -pub struct RequirementsResolvingSymbolRunner<'a, 's, R: 'a + SymbolRunner, G: 'a + SymbolRepository<'s>>(R, &'a G, PhantomData>); +pub struct RequirementsResolvingSymbolRunner<'a, 's, R: 'a + SymbolRunner, G: 'a + SymbolRepository<'s>>(R, &'a G, PhantomData>); 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 { @@ -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> { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { for resource in symbol.get_prerequisites() { if let Some(dep) = self.1.get_symbol(&resource) { @@ -202,23 +202,23 @@ mod test { } struct DummySymbol<'a> { - _execute: &'a Fn() -> Result<(), Box>, - _target_reached: &'a Fn() -> Result> + _execute: &'a dyn Fn() -> Result<(), Box>, + _target_reached: &'a dyn Fn() -> Result> } impl<'b> Symbol for DummySymbol<'b> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { (self._target_reached)() } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { (self._execute)() } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } @@ -230,7 +230,7 @@ mod test { } impl<'a> DummySymbol<'a> { - fn new(target_reached: &'a Fn() -> Result>, execute: &'a Fn() -> Result<(), Box>) -> DummySymbol<'a> { + fn new(target_reached: &'a dyn Fn() -> Result>, execute: &'a dyn Fn() -> Result<(), Box>) -> DummySymbol<'a> { DummySymbol { _target_reached: target_reached, _execute: execute } } } diff --git a/src/storage.rs b/src/storage.rs index 18fa6c2..7c93bfd 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -5,8 +5,8 @@ use std::time::{SystemTime, UNIX_EPOCH}; pub trait Storage { fn write_filename(&self) -> String; - fn read_filename(&self) -> Result>; - fn recent_date(&self) -> Result>; + fn read_filename(&self) -> Result>; + fn recent_date(&self) -> Result>; } #[derive(Clone)] @@ -30,11 +30,11 @@ impl Storage for SimpleStorage { self.get_path(Some(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs())) } - fn read_filename(&self) -> Result> { + fn read_filename(&self) -> Result> { Ok(self.get_path(Some(try!(self.recent_date())))) } - fn recent_date(&self) -> Result> { + fn recent_date(&self) -> Result> { let dir = self.get_path(None); 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())) diff --git a/src/symbols/acme/account_key.rs b/src/symbols/acme/account_key.rs index 5eda75e..2c06288 100644 --- a/src/symbols/acme/account_key.rs +++ b/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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !self.path.exists() { 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())) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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() ) ] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/acme/cert.rs b/src/symbols/acme/cert.rs index a01eae5..895a8e6 100644 --- a/src/symbols/acme/cert.rs +++ b/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; impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(&self.get_cert_path()).exists() { return Ok(false); } @@ -52,7 +52,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> { } } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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())); 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()) ] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/acme/chain.rs b/src/symbols/acme/chain.rs index 5f4c3d9..a5ba0fe 100644 --- a/src/symbols/acme/chain.rs +++ b/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; impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(&self.get_cert_chain_path()).exists() { 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()) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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())); 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()) ] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/acme/user.rs b/src/symbols/acme/user.rs index 6181907..ad4fcad 100644 --- a/src/symbols/acme/user.rs +++ b/src/symbols/acme/user.rs @@ -22,10 +22,10 @@ impl<'a> AcmeUser<'a> { } impl<'a> Symbol for AcmeUser<'a> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { Ok(false) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { Ok(()) } fn get_prerequisites(&self) -> Vec { @@ -34,11 +34,11 @@ impl<'a> Symbol for AcmeUser<'a> { fn provides(&self) -> Option> { None } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } @@ -49,7 +49,7 @@ impl<'a> fmt::Display for AcmeUser<'a> { } } -pub fn new<'a, S: Into>, C: CommandRunner, P: 'a + Deref>(command_runner: &'a C, cert: P, user_name: S) -> Box { // impl trait +pub fn new<'a, S: Into>, C: CommandRunner, P: 'a + Deref>(command_runner: &'a C, cert: P, user_name: S) -> Box { // impl trait let user_name_cow = user_name.into(); let account_key_file: PathBuf = ["/home", user_name_cow.borrow(), "account.key"].iter().collect(); Box::new(List::new(vec![ diff --git a/src/symbols/dir.rs b/src/symbols/dir.rs index 8d17693..2fac061 100644 --- a/src/symbols/dir.rs +++ b/src/symbols/dir.rs @@ -18,7 +18,7 @@ impl Dir where D: AsRef { } impl Symbol for Dir where D: AsRef { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let metadata = fs::metadata(self.path.as_ref()); // Check if dir exists if let Err(e) = metadata { @@ -35,8 +35,8 @@ impl Symbol for Dir where D: AsRef { } } - fn execute(&self) -> Result<(), Box> { - fs::create_dir(self.path.as_ref()).map_err(|e| Box::new(e) as Box) + fn execute(&self) -> Result<(), Box> { + fs::create_dir(self.path.as_ref()).map_err(|e| Box::new(e) as Box) } fn get_prerequisites(&self) -> Vec { @@ -51,11 +51,11 @@ impl Symbol for Dir where D: AsRef { Some(vec![ Resource::new("dir", self.path.as_ref()) ]) } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs index 6c00800..e586356 100644 --- a/src/symbols/factory.rs +++ b/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 } } - pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box { + pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box { Box::new(ListAction::new(vec![ Box::new(SelfSignedTlsCert::new( host.into(), @@ -70,7 +70,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact )).into_action(self.symbol_runner) ])) } - pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box { + pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box { Box::new(File::new( "/etc/nginx/snippets/acme-challenge.conf", "location ^~ /.well-known/acme-challenge/ { 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) } - fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> Box { + fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> Box { let socket = self.get_php_fpm_pool_socket_path(user_name); Box::new(Hook::new( File::new( @@ -105,7 +105,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin )).into_action(self.symbol_runner) } - pub fn serve_php<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box { + pub fn serve_php<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box { let user_name = self.policy.user_name_for_host(host_name); let socket = self.get_php_fpm_pool_socket_path(&user_name); 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 { + pub fn serve_wordpress<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box { let user_name = self.policy.user_name_for_host(host_name); let socket = self.get_php_fpm_pool_socket_path(&user_name); 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 { + pub fn serve_dokuwiki<'a>(&'a self, host_name: &'static str, root_dir: &'static str) -> Box { let user_name = self.policy.user_name_for_host(host_name); let socket = self.get_php_fpm_pool_socket_path(&user_name); 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 { + pub fn serve_nextcloud<'a>(&'a self, host_name: &'static str, root_dir: Cow<'a, str>) -> Box { let user_name = self.policy.user_name_for_host(host_name); let socket = self.get_php_fpm_pool_socket_path(&user_name); 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 { + pub fn serve_redir<'a>(&'a self, host_name: &'static str, target: &'static str) -> Box { 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 { + pub fn serve_static<'a>(&'a self, host_name: &'static str, dir: &'a str) -> Box { self.get_nginx_acme_server(host_name, NginxServer::new_static(host_name, dir, self.command_runner)) } - pub fn get_stored_directory<'a, T: Into>(&'a self, storage_name: &'static str, target: T) -> (Box, Box) { + pub fn get_stored_directory<'a, T: Into>(&'a self, storage_name: &'static str, target: T) -> (Box, Box) { let data = SimpleStorage::new("/root/data".to_string(), storage_name.to_string()); 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 { + pub fn get_mariadb_database<'a>(&'a self, name: &'static str) -> Box { let db_dump = SimpleStorage::new("/root/data".to_string(), format!("{}.sql", name)); 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), @@ -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 { + pub fn get_mariadb_user<'a>(&'a self, user_name: &'static str) -> Box { Box::new(MariaDBUser::new(user_name.into(), self.command_runner)).into_action(self.symbol_runner) } - pub fn get_git_checkout<'a, T: 'a + AsRef>(&'a self, target: T, source: &'a str, branch: &'a str) -> Box { + pub fn get_git_checkout<'a, T: 'a + AsRef>(&'a self, target: T, source: &'a str, branch: &'a str) -> Box { Box::new(GitCheckout::new(target, source, branch, self.command_runner)).into_action(self.symbol_runner) } - pub fn get_owner<'a, F: 'a + AsRef>(&'a self, file: F, user: &'a str) -> Box { + pub fn get_owner<'a, F: 'a + AsRef>(&'a self, file: F, user: &'a str) -> Box { Box::new(Owner::new(file, user.into(), self.command_runner)).into_action(self.symbol_runner) } - pub fn get_file<'a, F: 'a + Deref, Q: 'a + AsRef>(&'a self, path: Q, content: F) -> Box { + pub fn get_file<'a, F: 'a + Deref, Q: 'a + AsRef>(&'a self, path: Q, content: F) -> Box { Box::new(File::new(path, content)).into_action(self.symbol_runner) } } diff --git a/src/symbols/file.rs b/src/symbols/file.rs index 7639a9e..db9f692 100644 --- a/src/symbols/file.rs +++ b/src/symbols/file.rs @@ -21,7 +21,7 @@ impl File where C: Deref, D: AsRef { } impl Symbol for File where C: Deref, D: AsRef { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let file = FsFile::open(self.path.as_ref()); // Check if file exists if let Err(e) = file { @@ -44,7 +44,7 @@ impl Symbol for File where C: Deref, D: AsRef { } } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { let mut file = try!(FsFile::create(self.path.as_ref())); try!(file.write_all(self.content.as_bytes())); Ok(()) @@ -54,11 +54,11 @@ impl Symbol for File where C: Deref, D: AsRef { 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 { + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index 503c352..52c71df 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -29,7 +29,7 @@ impl<'a, C: CommandRunner, T: AsRef> fmt::Display for GitCheckout<'a, C, T> use std::fs::metadata; impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { - fn _run_in_target_repo(&self, args: &[&str]) -> Result, Box> { + fn _run_in_target_repo(&self, args: &[&str]) -> Result, Box> { let mut new_args = vec!["-C", self.target.as_ref()]; new_args.extend_from_slice(args); self.command_runner.get_output("git", &new_args) @@ -37,7 +37,7 @@ impl<'a, C: CommandRunner, T: AsRef> GitCheckout<'a, C, T> { } impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if let Err(e) = metadata(self.target.as_ref()) { return if e.kind() == io::ErrorKind::NotFound { Ok(false) @@ -52,7 +52,7 @@ impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { Ok(fetch_head == head) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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()]); } @@ -69,11 +69,11 @@ impl<'a, C: CommandRunner, T: AsRef> Symbol for GitCheckout<'a, C, T> { Some(vec![ Resource::new("dir", self.target.as_ref().to_string()) ]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/git/submodules.rs b/src/symbols/git/submodules.rs index 8b4bbe1..a044e01 100644 --- a/src/symbols/git/submodules.rs +++ b/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> { - fn _run_in_target_repo(&self, args: &[&str]) -> Result, Box> { + fn _run_in_target_repo(&self, args: &[&str]) -> Result, Box> { let mut new_args = vec!["-C", self.target]; new_args.extend_from_slice(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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(self.target).exists() { 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(' '))) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { try!(self._run_in_target_repo(&["submodule", "update", "--init"])); Ok(()) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/hook.rs b/src/symbols/hook.rs index bd0b17a..2387563 100644 --- a/src/symbols/hook.rs +++ b/src/symbols/hook.rs @@ -17,11 +17,11 @@ impl Hook where A: Symbol, B: Symbol { } impl Symbol for Hook where A: Symbol, B: Symbol { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { self.a.target_reached().and_then(|reached| if reached { self.b.target_reached() } else { Ok(reached) }) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { try!(self.a.execute()); self.b.execute() } @@ -44,11 +44,11 @@ impl Symbol for Hook where A: Symbol, B: Symbol { if r.is_empty() { None } else { Some(r) } } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } @@ -69,13 +69,13 @@ mod test { struct ErrSymbol(String); impl Symbol for ErrSymbol { - fn target_reached(&self) -> Result> { Err(self.0.clone().into()) } - fn execute(&self) -> Result<(), Box> { Err(self.0.clone().into()) } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn target_reached(&self) -> Result> { Err(self.0.clone().into()) } + fn execute(&self) -> Result<(), Box> { Err(self.0.clone().into()) } + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } @@ -83,13 +83,13 @@ mod test { struct OkSymbol(bool); impl Symbol for OkSymbol { - fn target_reached(&self) -> Result> { Ok(self.0) } - fn execute(&self) -> Result<(), Box> { Ok(()) } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn target_reached(&self) -> Result> { Ok(self.0) } + fn execute(&self) -> Result<(), Box> { Ok(()) } + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/list.rs b/src/symbols/list.rs index c079a6b..17e3c20 100644 --- a/src/symbols/list.rs +++ b/src/symbols/list.rs @@ -5,17 +5,17 @@ use resources::Resource; use symbols::{Action, Symbol, SymbolRunner}; pub struct List<'a> { - symbols: Vec> + symbols: Vec> } impl<'a> List<'a> { - pub fn new(symbols: Vec>) -> Self { + pub fn new(symbols: Vec>) -> Self { List { symbols } } } impl<'a> Symbol for List<'a> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { for symbol in &self.symbols { if !try!(symbol.target_reached()) { return Ok(false); @@ -24,7 +24,7 @@ impl<'a> Symbol for List<'a> { Ok(true) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { for symbol in &self.symbols { try!(symbol.execute()); } @@ -51,28 +51,28 @@ impl<'a> Symbol for List<'a> { if r.is_empty() { None } else { Some(r) } } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolListAction::new(runner, &self.symbols)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(ListAction::new(self.symbols.into_iter().map(|s| s.into_action(runner)).collect())) } } struct SymbolListAction<'a> { - runner: &'a SymbolRunner, - symbols: &'a [Box] + runner: &'a dyn SymbolRunner, + symbols: &'a [Box] } impl<'a> SymbolListAction<'a> { - fn new(runner: &'a SymbolRunner, symbols: &'a [Box]) -> Self { + fn new(runner: &'a dyn SymbolRunner, symbols: &'a [Box]) -> Self { Self { runner, symbols } } } impl<'a> Action for SymbolListAction<'a> { - fn run(&self) -> Result<(), Box> { + fn run(&self) -> Result<(), Box> { for symbol in self.symbols { try!(symbol.as_action(self.runner).run()); } @@ -81,17 +81,17 @@ impl<'a> Action for SymbolListAction<'a> { } pub struct ListAction<'a> { - actions: Vec> + actions: Vec> } impl<'a> ListAction<'a> { - pub fn new(actions: Vec>) -> Self { + pub fn new(actions: Vec>) -> Self { Self { actions } } } impl<'a> Action for ListAction<'a> { - fn run(&self) -> Result<(), Box> { + fn run(&self) -> Result<(), Box> { for action in &self.actions { try!(action.run()); } diff --git a/src/symbols/mariadb/database.rs b/src/symbols/mariadb/database.rs index 744c898..38569eb 100644 --- a/src/symbols/mariadb/database.rs +++ b/src/symbols/mariadb/database.rs @@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> { MariaDBDatabase { db_name, seed_file, command_runner } } - fn run_sql(&self, sql: &str) -> Result> { + fn run_sql(&self, sql: &str) -> Result> { let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); 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> { - fn target_reached(&self) -> Result> { - Ok(try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_right() == self.db_name) + fn target_reached(&self) -> Result> { + Ok(try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_end() == self.db_name) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name))); self.command_runner.run_successfully("sh", &["-c", &format!("mariadb '{}' < {}", self.db_name, self.seed_file)]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/mariadb/database_dump.rs b/src/symbols/mariadb/database_dump.rs index 9098f6d..14b2e8b 100644 --- a/src/symbols/mariadb/database_dump.rs +++ b/src/symbols/mariadb/database_dump.rs @@ -17,7 +17,7 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> DatabaseDump { db_name, storage, command_runner } } - fn run_sql(&self, sql: &str) -> Result> { + fn run_sql(&self, sql: &str) -> Result> { let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); Ok(try!(String::from_utf8(b))) } @@ -30,22 +30,22 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseD } impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { 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()))); - 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> { + fn execute(&self) -> Result<(), Box> { 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 { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/mariadb/user.rs b/src/symbols/mariadb/user.rs index 803f391..566aaa2 100644 --- a/src/symbols/mariadb/user.rs +++ b/src/symbols/mariadb/user.rs @@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> MariaDBUser<'a, C> { MariaDBUser { user_name, command_runner } } - fn run_sql(&self, sql: &str) -> Result> { + fn run_sql(&self, sql: &str) -> Result> { let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); 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> { - fn target_reached(&self) -> Result> { - 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> { + 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> { + fn execute(&self) -> Result<(), Box> { try!(self.run_sql(&format!("GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket", self.user_name))); Ok(()) } @@ -42,11 +42,11 @@ impl<'a, C: CommandRunner> Symbol for MariaDBUser<'a, C> { vec![ Resource::new("user", self.user_name.to_string()) ] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/mod.rs b/src/symbols/mod.rs index 44d79a2..3796cb2 100644 --- a/src/symbols/mod.rs +++ b/src/symbols/mod.rs @@ -3,64 +3,64 @@ use std::fmt::Display; use resources::Resource; pub trait Action { - fn run(&self) -> Result<(), Box>; + fn run(&self) -> Result<(), Box>; } pub trait SymbolRunner { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box>; + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box>; } impl SymbolRunner for Box { - fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box> { + fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box> { (**self).run_symbol(symbol) } } // Symbol pub trait Symbol: Display { - fn target_reached(&self) -> Result>; - fn execute(&self) -> Result<(), Box>; + fn target_reached(&self) -> Result>; + fn execute(&self) -> Result<(), Box>; fn get_prerequisites(&self) -> Vec { vec![] } fn provides(&self) -> Option> { None } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box; - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a; + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box; + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a; } // SymbolAction pub struct SymbolAction<'a, S: Symbol + 'a> { - runner: &'a SymbolRunner, + runner: &'a dyn SymbolRunner, symbol: &'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 } } } impl<'a, S: Symbol> Action for SymbolAction<'a, S> { - fn run(&self) -> Result<(), Box> { + fn run(&self) -> Result<(), Box> { self.runner.run_symbol(self.symbol) } } pub struct OwnedSymbolAction<'a, S: Symbol + 'a> { - runner: &'a SymbolRunner, + runner: &'a dyn SymbolRunner, symbol: 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 } } } impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> { - fn run(&self) -> Result<(), Box> { + fn run(&self) -> Result<(), Box> { self.runner.run_symbol(&self.symbol) } } diff --git a/src/symbols/nginx/server.rs b/src/symbols/nginx/server.rs index babb69a..f2fa645 100644 --- a/src/symbols/nginx/server.rs +++ b/src/symbols/nginx/server.rs @@ -27,7 +27,7 @@ impl Error for NginxServerError { NginxServerError::GenericError => "Generic error" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { NginxServerError::ExecError(ref e) => Some(e), _ => None @@ -157,7 +157,7 @@ location @proxy {{ } impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !try!(self.file.target_reached()) { return Ok(false); } @@ -165,7 +165,7 @@ impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref Result<(), Box> { + fn execute(&self) -> Result<(), Box> { try!(self.file.execute()); 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(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/noop.rs b/src/symbols/noop.rs index 62a07f1..b76e1e8 100644 --- a/src/symbols/noop.rs +++ b/src/symbols/noop.rs @@ -6,17 +6,17 @@ use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; pub struct NoopSymbol; impl Symbol for NoopSymbol { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { Ok(true) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { Ok(()) } - fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box { + fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'a>(self: Box, runner: &'a SymbolRunner) -> Box where Self: 'a { + fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box where Self: 'a { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/npm.rs b/src/symbols/npm.rs index f54dc3b..7f90582 100644 --- a/src/symbols/npm.rs +++ b/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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(self.target).exists() { 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)")) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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 { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/owner.rs b/src/symbols/owner.rs index f1ea0c5..90d6394 100644 --- a/src/symbols/owner.rs +++ b/src/symbols/owner.rs @@ -24,7 +24,7 @@ impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef { } impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(self.path.as_ref()).exists() { return Ok(false); } @@ -33,7 +33,7 @@ impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef { Ok(actual_uid == target_uid) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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 { vec![ Resource::new("user", self.user_name.to_string()) ] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/postgresql/database.rs b/src/symbols/postgresql/database.rs index 9ed8535..2ed22d5 100644 --- a/src/symbols/postgresql/database.rs +++ b/src/symbols/postgresql/database.rs @@ -16,7 +16,7 @@ impl<'a, C: CommandRunner> PostgreSQLDatabase<'a, C> { PostgreSQLDatabase { name, seed_file, command_runner } } - fn run_sql(&self, sql: &str) -> Result> { + fn run_sql(&self, sql: &str) -> Result> { let b = try!(self.command_runner.get_output("su", &["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)])); 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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { Ok(try!(self.run_sql(&format!("SELECT datname FROM pg_database WHERE datname LIKE '{}'", self.name))).trim() == self.name) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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!("psql '{}' < {}", self.name, self.seed_file)]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/postgresql/database_dump.rs b/src/symbols/postgresql/database_dump.rs index 9098f6d..14b2e8b 100644 --- a/src/symbols/postgresql/database_dump.rs +++ b/src/symbols/postgresql/database_dump.rs @@ -17,7 +17,7 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> DatabaseDump { db_name, storage, command_runner } } - fn run_sql(&self, sql: &str) -> Result> { + fn run_sql(&self, sql: &str) -> Result> { let b = try!(self.command_runner.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])); Ok(try!(String::from_utf8(b))) } @@ -30,22 +30,22 @@ impl<'a, N: AsRef, C: CommandRunner, S: Storage> fmt::Display for DatabaseD } impl<'a, N: AsRef, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { 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()))); - 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> { + fn execute(&self) -> Result<(), Box> { 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 { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/stored_directory.rs b/src/symbols/stored_directory.rs index 121cc3b..046fb1b 100644 --- a/src/symbols/stored_directory.rs +++ b/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 { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let metadata = fs::metadata(self.path.as_ref()); // Check if dir exists 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 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 } { let output = try!(self.command_runner.run_with_args("diff", &["-rq", &try!(self.storage.read_filename()), self.path.borrow()])); 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) } } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { if self.dir == StorageDirection::Load { 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()]) @@ -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 { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/systemd/node_js_user_service.rs b/src/symbols/systemd/node_js_user_service.rs index e7ecff3..50aa02b 100644 --- a/src/symbols/systemd/node_js_user_service.rs +++ b/src/symbols/systemd/node_js_user_service.rs @@ -33,7 +33,7 @@ impl Error for NodeJsSystemdUserServiceError { NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e), _ => None @@ -60,7 +60,7 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref, R: Com 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 { - 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 content = format!("[Service] @@ -91,18 +91,18 @@ WantedBy=default.target impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref, R: CommandRunner { - fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result> { + fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result> { let mut tries = 5; loop { let result = try!(self.command_runner.run_with_args("systemctl", args)); if !result.status.success() { 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" { return Err(stderr.into()); } } 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; if tries == 0 { @@ -112,7 +112,7 @@ impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref, R: } } - fn check_if_service(&self) -> Result> { + fn check_if_service(&self) -> Result> { loop { let active_state = try!(self.systemctl_wait_for_dbus(&["--user", "show", "--property", "ActiveState", self.service_name])); match active_state.as_ref() { @@ -126,14 +126,14 @@ impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref, R: } impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref, R: CommandRunner { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !(try!(self.file.target_reached())) { return Ok(false); } self.check_if_service() } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { try!(self.file.execute()); try!(self.systemctl_wait_for_dbus(&["--user", "enable", 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) + fs::metadata(&file_name).map(|_| ()).map_err(|e| Box::new(e) as Box) } fn get_prerequisites(&self) -> Vec { @@ -152,11 +152,11 @@ impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/systemd/reload.rs b/src/symbols/systemd/reload.rs index 7ea5e29..039350f 100644 --- a/src/symbols/systemd/reload.rs +++ b/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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { Ok(true) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { self.command_runner.run_successfully("systemctl", &["reload-or-restart", self.service]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/systemd/user_session.rs b/src/symbols/systemd/user_session.rs index fced756..4278aba 100644 --- a/src/symbols/systemd/user_session.rs +++ b/src/symbols/systemd/user_session.rs @@ -19,7 +19,7 @@ impl Error for SystemdUserSessionError { SystemdUserSessionError::GenericError => "Generic error" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { SystemdUserSessionError::ExecError(ref e) => Some(e), _ => None @@ -45,22 +45,22 @@ impl<'a, C: CommandRunner> SystemdUserSession<'a, C> { } impl<'a, C: CommandRunner> Symbol for SystemdUserSession<'a, C> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let mut path = PathBuf::from("/var/lib/systemd/linger"); path.push(self.user_name.borrow() as &str); Ok(path.exists()) // Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes` } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { self.command_runner.run_successfully("loginctl", &["enable-linger", self.user_name.borrow()]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/tls/csr.rs b/src/symbols/tls/csr.rs index 0fcd700..a761496 100644 --- a/src/symbols/tls/csr.rs +++ b/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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(&self.get_csr_path()).exists() { return Ok(false); } @@ -42,7 +42,7 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { Ok(output == b"verify OK\n") } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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(()) } @@ -51,11 +51,11 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> { vec![Resource::new("file", self.get_key_path())] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/tls/key.rs b/src/symbols/tls/key.rs index 4166d28..3ba01b6 100644 --- a/src/symbols/tls/key.rs +++ b/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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(&self.get_path()).exists() { 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())) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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 { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/tls/self_signed_cert.rs b/src/symbols/tls/self_signed_cert.rs index f35a9d3..a5e4e1e 100644 --- a/src/symbols/tls/self_signed_cert.rs +++ b/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; impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !Path::new(&self.get_cert_path()).exists() { return Ok(false); } @@ -53,7 +53,7 @@ println!("{}", output.status.code().unwrap()); } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { 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())] } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/user.rs b/src/symbols/user.rs index ca26142..e8f7cde 100644 --- a/src/symbols/user.rs +++ b/src/symbols/user.rs @@ -10,7 +10,7 @@ use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; pub enum UserAdderError { AlreadyExists, UnknownError, - ImplError(Box) + ImplError(Box) } impl Error for UserAdderError { @@ -21,7 +21,7 @@ impl Error for UserAdderError { UserAdderError::ImplError(_) => "User adding error" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { UserAdderError::ImplError(ref e) => Some(e.as_ref()), _ => None @@ -53,7 +53,7 @@ impl Error for UserError { UserError::GenericError => "Could not find out if user exists" } } - fn cause(&self) -> Option<&Error> { + fn cause(&self) -> Option<&dyn Error> { match self { _ => 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> { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let output = try!(self.command_runner.run_with_args("getent", &["passwd", &*self.user_name])); match output.status.code() { 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> { - self.user_adder.add_user(&*self.user_name).map_err(|e| Box::new(e) as Box) + fn execute(&self) -> Result<(), Box> { + self.user_adder.add_user(&*self.user_name).map_err(|e| Box::new(e) as Box) } fn provides(&self) -> Option> { Some(vec![Resource::new("user", self.user_name.to_string())]) } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } @@ -183,7 +183,7 @@ mod test { struct DummyUserAdder; impl UserAdder for DummyUserAdder { - fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> { + fn add_user(&self, _user_name: &str) -> Result<(), UserAdderError> { Ok(()) } } diff --git a/src/symbols/wordpress/plugin.rs b/src/symbols/wordpress/plugin.rs index f71b5ea..8220086 100644 --- a/src/symbols/wordpress/plugin.rs +++ b/src/symbols/wordpress/plugin.rs @@ -28,7 +28,7 @@ impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref, R: CommandR } impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref, R: CommandRunner { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { if !self.get_path().exists() { return Ok(false); } @@ -45,7 +45,7 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref, }; }, Ok(file) => { - let mut reader = BufReader::new(file); + let reader = BufReader::new(file); let regex = Regex::new("(?m)^(Plugin URI|Version): (.+)$")?; for content in reader.lines() { for matches in regex.captures_iter(&(content?)) { @@ -62,7 +62,7 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref, Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###)) } - fn execute(&self) -> Result<(), Box> { + fn execute(&self) -> Result<(), Box> { let source = format!("https://downloads.wordpress.org/plugin/{}.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()])); @@ -77,11 +77,11 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref, } } - fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } } diff --git a/src/symbols/wordpress/translation.rs b/src/symbols/wordpress/translation.rs index 5ca2283..9186268 100644 --- a/src/symbols/wordpress/translation.rs +++ b/src/symbols/wordpress/translation.rs @@ -31,7 +31,7 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef, R: Co impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef, D: AsRef, R: CommandRunner { 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 path_locale = if locale == "de_DE" { "de".to_owned() } else { locale.to_lowercase().replace('_', "-") }; let mut res = vec![]; @@ -48,7 +48,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef, D: AsRe } impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef, D: AsRef, R: CommandRunner { - fn target_reached(&self) -> Result> { + fn target_reached(&self) -> Result> { let mut newest = String::new(); let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap(); 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 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() { if let Some(match_result) = match_date.captures(&try!(content)) { 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 Result<(), Box> { + fn execute(&self) -> Result<(), Box> { for (source, target) in self.get_pairs() { 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(&'b self, runner: &'b SymbolRunner) -> Box { + fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box { Box::new(SymbolAction::new(runner, self)) } - fn into_action<'b>(self: Box, runner: &'b SymbolRunner) -> Box where Self: 'b { + fn into_action<'b>(self: Box, runner: &'b dyn SymbolRunner) -> Box where Self: 'b { Box::new(OwnedSymbolAction::new(runner, *self)) } }