Browse Source

Cargo fix

master
Adrian Heine 3 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::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 dry_run = match args.len() {
1 => false,

6
src/command_runner.rs

@ -6,21 +6,21 @@ use std::process::Output;
pub trait CommandRunner {
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));
if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into());
}
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));
if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into());
}
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));
if output.status.success() {
Ok(())

16
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<dyn 'a + SymbolRunner> {
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<Box<Symbol + 'a>> {
fn get_symbol(&'a self, resource: &Resource) -> Option<Box<dyn Symbol + 'a>> {
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<Symbol>
])) as Box<dyn Symbol>
} 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<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" => {
@ -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<Symbol>)
)) as Box<dyn Symbol>)
} 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<Symbol>)
)) as Box<dyn Symbol>)
} 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<Symbol>)
)) as Box<dyn Symbol>)
} else { None }
},
_ => None

6
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) {

12
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<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)
}
}
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> {
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 }
}
}
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))
}
}

30
src/schema.rs

@ -8,7 +8,7 @@ use symbols::{Symbol, SymbolRunner};
#[derive(Debug)]
pub enum SymbolRunError {
Symbol(Box<Error>),
Symbol(Box<dyn Error>),
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<L: Logger> 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 target_reached = try!(symbol.target_reached());
@ -78,7 +78,7 @@ impl<L: Logger> 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 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<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{
let mut logger = self.1.borrow_mut();
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> {
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() {
let mut done = self.done.borrow_mut();
@ -151,7 +151,7 @@ impl<R: SymbolRunner> SymbolRunner for NonRepeatingSymbolRunner<R> {
}
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> {
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<Error>>
fn run_symbol(&self, symbol: &dyn Symbol) -> Result<(), Box<dyn Error>>
{
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<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> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
(self._target_reached)()
}
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
(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))
}
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))
}
}
@ -230,7 +230,7 @@ mod test {
}
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 }
}
}

8
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<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)]
@ -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<String, Box<Error>> {
fn read_filename(&self) -> Result<String, Box<dyn Error>> {
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);
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()))

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> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
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<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()])
}
@ -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<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
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))
}
}

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;
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() {
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 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<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
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))
}
}

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;
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() {
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<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 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<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
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))
}
}

10
src/symbols/acme/user.rs

@ -22,10 +22,10 @@ impl<'a> 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)
}
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn get_prerequisites(&self) -> Vec<Resource> {
@ -34,11 +34,11 @@ impl<'a> Symbol for AcmeUser<'a> {
fn provides(&self) -> Option<Vec<Resource>> {
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))
}
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))
}
}
@ -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 account_key_file: PathBuf = ["/home", user_name_cow.borrow(), "account.key"].iter().collect();
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> {
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());
// Check if dir exists
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> {
@ -51,11 +51,11 @@ impl<D> Symbol for Dir<D> where D: AsRef<str> {
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))
}
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))
}
}

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 }
}
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(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<Action + 'a> {
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box<dyn Action + 'a> {
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<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);
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<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 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<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 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<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 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<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 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<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))
}
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))
}
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 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));
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<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)
}
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)
}
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)
}
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)
}
}

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> {
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());
// Check if file exists
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()));
try!(file.write_all(self.content.as_bytes()));
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() ) ]
}
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))
}
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))
}
}

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;
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()];
new_args.extend_from_slice(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> {
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()) {
return if e.kind() == io::ErrorKind::NotFound {
Ok(false)
@ -52,7 +52,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
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() {
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()) ])
}
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))
}
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))
}
}

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> {
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];
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<bool, Box<Error>> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
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<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self._run_in_target_repo(&["submodule", "update", "--init"]));
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))
}
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))
}
}

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 {
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) })
}
fn execute(&self) -> Result<(), Box<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.a.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) }
}
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))
}
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))
}
}
@ -69,13 +69,13 @@ mod test {
struct ErrSymbol(String);
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))
}
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))
}
}
@ -83,13 +83,13 @@ mod test {
struct OkSymbol(bool);
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))
}
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))
}
}

26
src/symbols/list.rs

@ -5,17 +5,17 @@ use resources::Resource;
use symbols::{Action, Symbol, SymbolRunner};
pub struct List<'a> {
symbols: Vec<Box<Symbol + 'a>>
symbols: Vec<Box<dyn Symbol + '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 }
}
}
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 {
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<Error>> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
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<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
Box::new(SymbolListAction::new(runner, &self.symbols))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
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()))
}
}
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> {
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 }
}
}
impl<'a> Action for SymbolListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
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<Box<Action + 'a>>
actions: Vec<Box<dyn Action + '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 }
}
}
impl<'a> Action for ListAction<'a> {
fn run(&self) -> Result<(), Box<Error>> {
fn run(&self) -> Result<(), Box<dyn Error>> {
for action in &self.actions {
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 }
}
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]));
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<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)));
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))
}
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))
}
}

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 }
}
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]));
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> {
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 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())])
}
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))
}
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))
}
}

12
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<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]));
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<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)));
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<Action + 'b> {
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
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))
}
}

26
src/symbols/mod.rs

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