Browse Source

Update rustfmt

master
Adrian Heine 2 years ago
parent
commit
64e20b371b
  1. 2
      rustfmt.toml
  2. 12
      src/command_runner.rs
  3. 10
      src/schema.rs
  4. 4
      src/storage.rs
  5. 8
      src/symbols/acme/account_key.rs
  6. 22
      src/symbols/acme/cert.rs
  7. 20
      src/symbols/acme/chain.rs
  8. 16
      src/symbols/acme/user.rs
  9. 4
      src/symbols/cron.rs
  10. 4
      src/symbols/file.rs
  11. 10
      src/symbols/git/checkout.rs
  12. 6
      src/symbols/git/submodules.rs
  13. 2
      src/symbols/hook.rs
  14. 57
      src/symbols/list.rs
  15. 12
      src/symbols/mariadb/database.rs
  16. 10
      src/symbols/mariadb/database_dump.rs
  17. 21
      src/symbols/mariadb/user.rs
  18. 4
      src/symbols/nginx/server.rs
  19. 4
      src/symbols/npm.rs
  20. 19
      src/symbols/postgresql/database.rs
  21. 10
      src/symbols/postgresql/database_dump.rs
  22. 34
      src/symbols/stored_directory.rs
  23. 30
      src/symbols/systemd/user_service.rs
  24. 14
      src/symbols/tls/csr.rs
  25. 6
      src/symbols/tls/key.rs
  26. 8
      src/symbols/tls/self_signed_cert.rs
  27. 4
      src/symbols/user.rs
  28. 18
      src/symbols/wordpress/plugin.rs
  29. 14
      src/symbols/wordpress/translation.rs

2
rustfmt.toml

@ -1 +1,3 @@
tab_spaces = 2
use_try_shorthand = true
use_field_init_shorthand = true

12
src/command_runner.rs

@ -24,9 +24,9 @@ pub trait CommandRunner {
program: &str,
args: &[&S],
) -> Result<Vec<u8>, Box<dyn Error>> {
let output = try!(self.run_with_args(program, args));
let output = self.run_with_args(program, args)?;
if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into());
return Err(String::from_utf8(output.stderr)?.into());
}
Ok(output.stdout)
}
@ -35,9 +35,9 @@ pub trait CommandRunner {
program: &str,
args: &[&S],
) -> Result<Vec<u8>, Box<dyn Error>> {
let output = try!(self.run_with_args(program, args));
let output = self.run_with_args(program, args)?;
if !output.status.success() {
return Err(try!(String::from_utf8(output.stderr)).into());
return Err(String::from_utf8(output.stderr)?.into());
}
Ok(output.stderr)
}
@ -46,11 +46,11 @@ pub trait CommandRunner {
program: &str,
args: &[&S],
) -> Result<(), Box<dyn Error>> {
let output = try!(self.run_with_args(program, args));
let output = self.run_with_args(program, args)?;
if output.status.success() {
Ok(())
} else {
Err(try!(String::from_utf8(output.stderr)).into())
Err(String::from_utf8(output.stderr)?.into())
}
}
}

10
src/schema.rs

@ -51,14 +51,14 @@ impl<L: Logger> InitializingSymbolRunner<L> {
impl<L: Logger> SymbolRunner for InitializingSymbolRunner<L> {
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());
let target_reached = symbol.target_reached()?;
if target_reached {
logger.write(format!("{} already reached", symbol).as_str());
} else {
logger.debug(format!("Symbol reports target_reached: {:?}", target_reached).as_str());
logger.write(format!("Executing {}", symbol).as_str());
try!(symbol.execute());
let target_reached = try!(symbol.target_reached());
symbol.execute()?;
let target_reached = symbol.target_reached()?;
logger.debug(
format!(
"Symbol reports target_reached: {:?} (should be true)",
@ -89,7 +89,7 @@ impl<L: Logger> DrySymbolRunner<L> {
impl<L: Logger> SymbolRunner for DrySymbolRunner<L> {
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());
let target_reached = symbol.target_reached()?;
logger.debug(format!("Symbol reports target_reached: {:?}", target_reached).as_str());
if !target_reached {
logger.write(format!("Would execute {}", symbol).as_str());
@ -196,7 +196,7 @@ where
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) {
try!(dep.as_action(self).run());
dep.as_action(self).run()?;
}
}
self.0.run_symbol(&*symbol)

4
src/storage.rs

@ -36,12 +36,12 @@ impl Storage for SimpleStorage {
}
fn read_filename(&self) -> Result<String, Box<dyn Error>> {
Ok(self.get_path(Some(try!(self.recent_date()))))
Ok(self.get_path(Some(self.recent_date()?)))
}
fn recent_date(&self) -> Result<u64, Box<dyn Error>> {
let dir = self.get_path(None);
try!(read_dir(dir))
read_dir(dir)?
.map(|entry| {
entry
.ok()

8
src/symbols/acme/account_key.rs

@ -36,7 +36,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
if !self.path.exists() {
return Ok(false);
}
let stdout = try!(self.command_runner.get_output(
let stdout = self.command_runner.get_output(
"openssl",
&[
"rsa".as_ref(),
@ -44,9 +44,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
self.path.as_os_str(),
"-noout".as_ref(),
"-check".as_ref(),
"-text".as_ref()
]
));
"-text".as_ref(),
],
)?;
Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
}

22
src/symbols/acme/cert.rs

@ -45,7 +45,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
return Ok(false);
}
let output = try!(self.command_runner.run_with_args(
let output = self.command_runner.run_with_args(
"openssl",
&[
"x509",
@ -54,9 +54,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
"-noout",
"-subject",
"-checkend",
&(30 * DAYS_IN_SECONDS).to_string()
]
));
&(30 * DAYS_IN_SECONDS).to_string(),
],
)?;
if output.status.success()
&& output.stdout
== format!(
@ -85,12 +85,12 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
{
Ok(false)
} else {
Err(try!(String::from_utf8(output.stderr)).into())
Err(String::from_utf8(output.stderr)?.into())
}
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
let output = try!(self.command_runner.get_output(
let output = self.command_runner.get_output(
"acme-tiny",
&[
"--account-key",
@ -98,11 +98,11 @@ impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
"--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));
"/home/acme/challenges/",
],
)?;
let mut file = FsFile::create(self.get_cert_path())?;
file.write_all(&output)?;
Ok(())
}

20
src/symbols/acme/chain.rs

@ -45,7 +45,7 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
return Ok(false);
}
let stdout = try!(self.command_runner.get_output(
let stdout = self.command_runner.get_output(
"openssl",
&[
"x509",
@ -54,9 +54,9 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
"-noout",
"-subject",
"-checkend",
&(30 * DAYS_IN_SECONDS).to_string()
]
));
&(30 * DAYS_IN_SECONDS).to_string(),
],
)?;
if stdout
!= format!(
"subject=CN = {}\nCertificate will not expire\n",
@ -84,15 +84,15 @@ impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
let output = try!(self.command_runner.get_output(
let output = 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));
"/home/acme/lets_encrypt_x3_cross_signed.pem",
],
)?;
let mut file = FsFile::create(self.get_cert_chain_path())?;
file.write_all(&output)?;
Ok(())
}

16
src/symbols/acme/user.rs

@ -63,10 +63,7 @@ pub fn new<'a, S: Into<Cow<'a, str>>, C: CommandRunner, P: 'a + Deref<Target = s
.iter()
.collect();
List::from((
AcmeAccountKey::new(
account_key_file.clone().into(),
command_runner,
),
AcmeAccountKey::new(account_key_file.clone().into(), command_runner),
Owner::new(
account_key_file.to_string_lossy().into_owned(),
user_name_cow.clone(),
@ -79,14 +76,7 @@ pub fn new<'a, S: Into<Cow<'a, str>>, C: CommandRunner, P: 'a + Deref<Target = s
command_runner,
),
Dir::new("/etc/ssl/local_certs"),
Owner::new(
"/etc/ssl/local_certs",
user_name_cow,
command_runner,
),
File::new(
"/home/acme/lets_encrypt_x3_cross_signed.pem",
cert,
),
Owner::new("/etc/ssl/local_certs", user_name_cow, command_runner),
File::new("/home/acme/lets_encrypt_x3_cross_signed.pem", cert),
))
}

4
src/symbols/cron.rs

@ -35,9 +35,9 @@ where
U: Deref<Target = str>,
{
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
let tab = try!(self
let tab = self
.command_runner
.get_output("crontab", &["-l", "-u", &self.user]));
.get_output("crontab", &["-l", "-u", &self.user])?;
return Ok(tab == self.content.bytes().collect::<Vec<u8>>());
}

4
src/symbols/file.rs

@ -57,8 +57,8 @@ where
}
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()));
let mut file = FsFile::create(self.path.as_ref())?;
file.write_all(self.content.as_bytes())?;
Ok(())
}

10
src/symbols/git/checkout.rs

@ -56,10 +56,10 @@ impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
Err(Box::new(e))
};
}
try!(self._run_in_target_repo(&["fetch", self.source, self.branch]));
self._run_in_target_repo(&["fetch", self.source, self.branch])?;
// git rev-list resolves tag objects
let fetch_head = try!(self._run_in_target_repo(&["rev-list", "-1", "FETCH_HEAD"]));
let head = try!(self._run_in_target_repo(&["rev-list", "-1", "HEAD"]));
let fetch_head = self._run_in_target_repo(&["rev-list", "-1", "FETCH_HEAD"])?;
let head = self._run_in_target_repo(&["rev-list", "-1", "HEAD"])?;
Ok(fetch_head == head)
}
@ -78,8 +78,8 @@ impl<'a, C: CommandRunner, T: AsRef<str>> Symbol for GitCheckout<'a, C, T> {
],
);
}
try!(self._run_in_target_repo(&["fetch", self.source, self.branch]));
try!(self._run_in_target_repo(&["merge", "FETCH_HEAD"]));
self._run_in_target_repo(&["fetch", self.source, self.branch])?;
self._run_in_target_repo(&["merge", "FETCH_HEAD"])?;
Ok(())
}

6
src/symbols/git/submodules.rs

@ -38,9 +38,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
if !Path::new(self.target).exists() {
return Ok(false);
}
let output = try!(String::from_utf8(try!(
self._run_in_target_repo(&["submodule", "status"])
)));
let output = String::from_utf8(self._run_in_target_repo(&["submodule", "status"])?)?;
Ok(
output
.lines()
@ -49,7 +47,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self._run_in_target_repo(&["submodule", "update", "--init"]));
self._run_in_target_repo(&["submodule", "update", "--init"])?;
Ok(())
}

2
src/symbols/hook.rs

@ -40,7 +40,7 @@ where
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.a.execute());
self.a.execute()?;
self.b.execute()
}

57
src/symbols/list.rs

@ -17,7 +17,7 @@ impl<'a> List<'a> {
impl<'a> Symbol for List<'a> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
for symbol in &self.symbols {
if !try!(symbol.target_reached()) {
if !symbol.target_reached()? {
return Ok(false);
}
}
@ -26,7 +26,7 @@ impl<'a> Symbol for List<'a> {
fn execute(&self) -> Result<(), Box<dyn Error>> {
for symbol in &self.symbols {
try!(symbol.execute());
symbol.execute()?;
}
Ok(())
}
@ -87,73 +87,64 @@ impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol> From<(A, B, C)> for Lis
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol> From<(A, B, C, D)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol> From<(A, B, C, D)> for List<'a> {
fn from((a, b, c, d): (A, B, C, D)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol> From<(A, B, C, D, E)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol> From<(A, B, C, D, E)> for List<'a> {
fn from((a, b, c, d, e): (A, B, C, D, E)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol> From<(A, B, C, D, E, F)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol> From<(A, B, C, D, E, F)> for List<'a> {
fn from((a, b, c, d, e, f): (A, B, C, D, E, F)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol> From<(A, B, C, D, E, F, G)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol> From<(A, B, C, D, E, F, G)> for List<'a> {
fn from((a, b, c, d, e, f, g): (A, B, C, D, E, F, G)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol> From<(A, B, C, D, E, F, G, H)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol> From<(A, B, C, D, E, F, G, H)> for List<'a> {
fn from((a, b, c, d, e, f, g, h): (A, B, C, D, E, F, G, H)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k): (A, B, C, D, E, F, G, H, I, J, K)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l): (A, B, C, D, E, F, G, H, I, J, K, L)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l, m): (A, B, C, D, E, F, G, H, I, J, K, L, M)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m)])
}
}
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol, N: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)>
for List<'a>
{
#[rustfmt::skip]
impl<'a, A: 'a + Symbol, B: 'a + Symbol, C: 'a + Symbol, D: 'a + Symbol, E: 'a + Symbol, F: 'a + Symbol, G: 'a + Symbol, H: 'a + Symbol, I: 'a + Symbol, J: 'a + Symbol, K: 'a + Symbol, L: 'a + Symbol, M: 'a + Symbol, N: 'a + Symbol> From<(A, B, C, D, E, F, G, H, I, J, K, L, M, N)> for List<'a> {
fn from((a, b, c, d, e, f, g, h, i, j, k, l, m, n): (A, B, C, D, E, F, G, H, I, J, K, L, M, N)) -> Self {
Self::new(vec![Box::new(a), Box::new(b), Box::new(c), Box::new(d), Box::new(e), Box::new(f), Box::new(g), Box::new(h), Box::new(i), Box::new(j), Box::new(k), Box::new(l), Box::new(m), Box::new(n)])
}
@ -173,7 +164,7 @@ impl<'a> SymbolListAction<'a> {
impl<'a> Action for SymbolListAction<'a> {
fn run(&self) -> Result<(), Box<dyn Error>> {
for symbol in self.symbols {
try!(symbol.as_action(self.runner).run());
symbol.as_action(self.runner).run()?;
}
Ok(())
}
@ -192,7 +183,7 @@ impl<'a> ListAction<'a> {
impl<'a> Action for ListAction<'a> {
fn run(&self) -> Result<(), Box<dyn Error>> {
for action in &self.actions {
try!(action.run());
action.run()?;
}
Ok(())
}
@ -200,9 +191,9 @@ impl<'a> Action for ListAction<'a> {
impl<'a> fmt::Display for List<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "List [ "));
write!(f, "List [ ")?;
for symbol in &self.symbols {
try!(write!(f, "{} ", symbol));
write!(f, "{} ", symbol)?;
}
write!(f, "]")
}

12
src/symbols/mariadb/database.rs

@ -21,10 +21,10 @@ impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> {
}
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self
let b = self
.command_runner
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b)))
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?;
Ok(String::from_utf8(b)?)
}
}
@ -37,13 +37,15 @@ 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<dyn Error>> {
Ok(
try!(self.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))).trim_end()
self
.run_sql(&format!("SHOW DATABASES LIKE '{}'", self.db_name))?
.trim_end()
== self.db_name,
)
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.run_sql(&format!("CREATE DATABASE {}", self.db_name)));
self.run_sql(&format!("CREATE DATABASE {}", self.db_name))?;
self.command_runner.run_successfully(
"sh",
&[

10
src/symbols/mariadb/database_dump.rs

@ -27,10 +27,10 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
}
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self
let b = self
.command_runner
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b)))
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?;
Ok(String::from_utf8(b)?)
}
}
@ -42,12 +42,12 @@ 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<dyn Error>> {
let dump_date = try!(self.storage.recent_date());
let dump_date = 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_end() == "NULL" {
return Ok(false);
}
Ok(try!(u64::from_str(modified_date.trim_end())) <= dump_date)
Ok(u64::from_str(modified_date.trim_end())? <= dump_date)
}
fn execute(&self) -> Result<(), Box<dyn Error>> {

21
src/symbols/mariadb/user.rs

@ -20,10 +20,10 @@ impl<'a, C: CommandRunner> MariaDBUser<'a, C> {
}
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self
let b = self
.command_runner
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b)))
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?;
Ok(String::from_utf8(b)?)
}
}
@ -36,20 +36,21 @@ 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<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
.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<dyn Error>> {
try!(self.run_sql(&format!(
self.run_sql(&format!(
"GRANT ALL ON {0}.* TO {0} IDENTIFIED VIA unix_socket",
self.user_name
)));
))?;
Ok(())
}

4
src/symbols/nginx/server.rs

@ -208,7 +208,7 @@ where
T: Deref<Target = str>,
{
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !try!(self.file.target_reached()) {
if !self.file.target_reached()? {
return Ok(false);
}
// TODO: Could try to find out if the server is in the live config
@ -216,7 +216,7 @@ where
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.file.execute());
self.file.execute()?;
self
.command_runner
.run_successfully("systemctl", &["reload-or-restart", "nginx"])

4
src/symbols/npm.rs

@ -30,9 +30,9 @@ impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> {
if !Path::new(self.target).exists() {
return Ok(false);
}
let result = try!(self
let result = self
.command_runner
.run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)]));
.run_with_args("sh", &["-c", &format!("cd '{}' && npm ls", self.target)])?;
Ok(
result.status.success()
&& !String::from_utf8(result.stdout)

19
src/symbols/postgresql/database.rs

@ -21,11 +21,11 @@ impl<'a, C: CommandRunner> PostgreSQLDatabase<'a, C> {
}
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self.command_runner.get_output(
let b = self.command_runner.get_output(
"su",
&["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)]
));
Ok(try!(String::from_utf8(b)))
&["-", "postgres", "-c", &format!("psql -t -c \"{}\"", sql)],
)?;
Ok(String::from_utf8(b)?)
}
}
@ -38,11 +38,12 @@ impl<'a, C: CommandRunner> fmt::Display for PostgreSQLDatabase<'a, C> {
impl<'a, C: CommandRunner> Symbol for PostgreSQLDatabase<'a, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(
try!(self.run_sql(&format!(
"SELECT datname FROM pg_database WHERE datname LIKE '{}'",
self.name
)))
.trim()
self
.run_sql(&format!(
"SELECT datname FROM pg_database WHERE datname LIKE '{}'",
self.name
))?
.trim()
== self.name,
)
}

10
src/symbols/postgresql/database_dump.rs

@ -27,10 +27,10 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
}
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
let b = try!(self
let b = self
.command_runner
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql]));
Ok(try!(String::from_utf8(b)))
.get_output("mariadb", &["--skip-column-names", "-B", "-e", sql])?;
Ok(String::from_utf8(b)?)
}
}
@ -42,12 +42,12 @@ 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<dyn Error>> {
let dump_date = try!(self.storage.recent_date());
let dump_date = 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_end() == "NULL" {
return Ok(false);
}
Ok(try!(u64::from_str(modified_date.trim_end())) <= dump_date)
Ok(u64::from_str(modified_date.trim_end())? <= dump_date)
}
fn execute(&self) -> Result<(), Box<dyn Error>> {

34
src/symbols/stored_directory.rs

@ -71,35 +71,31 @@ where
)));
}
let dump_date = try!(self.storage.recent_date());
let output = try!(self.command_runner.get_output(
let dump_date = self.storage.recent_date()?;
let output = 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_end()));
),
],
)?;
let modified_date = u64::from_str(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(
let output = self.command_runner.run_with_args(
"diff",
&[
"-rq",
&try!(self.storage.read_filename()),
self.path.borrow()
]
));
&["-rq", &self.storage.read_filename()?, self.path.borrow()],
)?;
match output.status.code() {
Some(0) => Ok(true),
Some(1) => Ok(false),
_ => Err(try!(String::from_utf8(output.stderr)).into()),
_ => Err(String::from_utf8(output.stderr)?.into()),
}
} else {
Ok(true)
@ -108,16 +104,12 @@ where
fn execute(&self) -> Result<(), Box<dyn Error>> {
if self.dir == StorageDirection::Load {
try!(self
self
.command_runner
.run_successfully("rm", &["-rf", self.path.borrow()]));
.run_successfully("rm", &["-rf", self.path.borrow()])?;
self.command_runner.run_successfully(
"cp",
&[
"-a",
&try!(self.storage.read_filename()),
self.path.borrow(),
],
&["-a", &self.storage.read_filename()?, self.path.borrow()],
)
} else {
self.command_runner.run_successfully(

30
src/symbols/systemd/user_service.rs

@ -43,9 +43,9 @@ impl<E: Error> Error for UserServiceError<E> {
impl<E: Error> fmt::Display for UserServiceError<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "{}", self.description()));
write!(f, "{}", self.description())?;
if let UserServiceError::ActivationFailed(Ok(ref log)) = self {
try!(write!(f, ": {:?}", log));
write!(f, ": {:?}", log)?;
};
Ok(())
}
@ -126,19 +126,15 @@ where
fn systemctl_wait_for_dbus(&self, args: &[&str]) -> Result<String, Box<dyn Error>> {
let mut tries = 5;
loop {
let result = try!(self.command_runner.run_with_args("systemctl", args));
let result = self.command_runner.run_with_args("systemctl", args)?;
if !result.status.success() {
let raw_stderr = try!(String::from_utf8(result.stderr));
let raw_stderr = String::from_utf8(result.stderr)?;
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_end()
.to_string(),
);
return Ok(String::from_utf8(result.stdout)?.trim_end().to_string());
}
tries -= 1;
if tries == 0 {
@ -150,13 +146,13 @@ where
fn check_if_service(&self) -> Result<bool, Box<dyn Error>> {
loop {
let active_state = try!(self.systemctl_wait_for_dbus(&[
let active_state = self.systemctl_wait_for_dbus(&[
"--user",
"show",
"--property",
"ActiveState",
self.service_name
]));
self.service_name,
])?;
match active_state.as_ref() {
"ActiveState=activating" => sleep(Duration::from_millis(500)),
"ActiveState=active" => return Ok(true),
@ -180,18 +176,18 @@ where
R: CommandRunner,
{
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
if !(try!(self.file.target_reached())) {
if !(self.file.target_reached()?) {
return Ok(false);
}
self.check_if_service()
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
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]));
self.file.execute()?;
self.systemctl_wait_for_dbus(&["--user", "enable", self.service_name])?;
self.systemctl_wait_for_dbus(&["--user", "restart", self.service_name])?;
if !(try!(self.check_if_service())) {
if !(self.check_if_service()?) {
return Err(Box::new(
UserServiceError::GenericError as UserServiceError<io::Error>,
));

14
src/symbols/tls/csr.rs

@ -41,15 +41,15 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
return Ok(false);
}
let output = try!(self.command_runner.get_stderr(
let output = self.command_runner.get_stderr(
"openssl",
&["req", "-in", &self.get_csr_path(), "-noout", "-verify"]
));
&["req", "-in", &self.get_csr_path(), "-noout", "-verify"],
)?;
Ok(output == b"verify OK\n")
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
try!(self.command_runner.run_successfully(
self.command_runner.run_successfully(
"openssl",
&[
"req",
@ -60,9 +60,9 @@ impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
"-out",
&self.get_csr_path(),
"-subj",
&format!("/CN={}", self.domain)
]
));
&format!("/CN={}", self.domain),
],
)?;
Ok(())
}

6
src/symbols/tls/key.rs

@ -40,10 +40,10 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
return Ok(false);
}
let output = try!(self.command_runner.get_output(
let output = self.command_runner.get_output(
"openssl",
&["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"]
));
&["rsa", "-in", &self.get_path(), "-noout", "-check", "-text"],
)?;
Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
}

8
src/symbols/tls/self_signed_cert.rs

@ -42,7 +42,7 @@ impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> {
if !Path::new(&self.get_cert_path()).exists() {
return Ok(false);
}
let output = try!(self.command_runner.run_with_args(
let output = self.command_runner.run_with_args(
"openssl",
&[
"x509",
@ -51,9 +51,9 @@ impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> {
"-noout",
"-subject",
"-checkend",
&(30 * DAYS_IN_SECONDS).to_string()
]
));
&(30 * DAYS_IN_SECONDS).to_string(),
],
)?;
println!("{}", output.status.code().unwrap());
match output.status.code() {
Some(0) => Ok(

4
src/symbols/user.rs

@ -93,9 +93,9 @@ 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<bool, Box<dyn Error>> {
let output = try!(self
let output = self
.command_runner
.run_with_args("getent", &["passwd", &*self.user_name]));
.run_with_args("getent", &["passwd", &*self.user_name])?;
match output.status.code() {
Some(2) => Ok(false),
Some(0) => Ok(true),

18
src/symbols/wordpress/plugin.rs

@ -76,7 +76,7 @@ where
}
}
}
let upstream = try!(self.command_runner.get_output(
let upstream = self.command_runner.get_output(
"curl",
&[
"--form",
@ -84,21 +84,21 @@ where
r###"plugins={{"plugins":{{"{0}/{0}.php":{{"Version":"{1}", "PluginURI":"{2}"}}}}}}"###,
&*self.name, version, plugin_uri
),
"https://api.wordpress.org/plugins/update-check/1.1/"
]
));
Ok(try!(String::from_utf8(upstream)).contains(r###""plugins":[]"###))
"https://api.wordpress.org/plugins/update-check/1.1/",
],
)?;
Ok(String::from_utf8(upstream)?.contains(r###""plugins":[]"###))
}
fn execute(&self) -> Result<(), Box<dyn Error>> {
let source = format!("https://downloads.wordpress.org/plugin/{}.zip", &*self.name);
let zip = format!("/tmp/{}.zip", &*self.name);
try!(self
self
.command_runner
.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()]));
try!(self
.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()])?;
self
.command_runner
.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()]));
.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()])?;
self.command_runner.run_successfully(
"unzip",
&[

14
src/symbols/wordpress/translation.rs

@ -102,7 +102,7 @@ where
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)) {
if let Some(match_result) = match_date.captures(&content?) {
newest = max(newest, match_result[1].to_string());
break;
}
@ -111,15 +111,15 @@ where
}
}
}
let upstream = try!(self.command_runner.get_output(
let upstream = self.command_runner.get_output(
"curl",
&[&format!(
"https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}",
self.version,
self.locale.as_ref()
)]
));
Ok(try!(String::from_utf8(upstream)).contains(&format!(
)],
)?;
Ok(String::from_utf8(upstream)?.contains(&format!(
r###"language":"{}","version":"{}","updated":"{}"###,
self.locale.as_ref(),
self.version,
@ -129,9 +129,9 @@ where
fn execute(&self) -> Result<(), Box<dyn Error>> {
for (source, target) in self.get_pairs() {
try!(self
self
.command_runner
.run_successfully("curl", &["--compressed", "-o", &target, &source]));
.run_successfully("curl", &["--compressed", "-o", &target, &source])?;
}
Ok(())
}

Loading…
Cancel
Save