Switch CommandRunner to OsStr
This commit is contained in:
parent
b8bac1142c
commit
3b45b0f77c
22 changed files with 220 additions and 148 deletions
|
|
@ -1,25 +1,26 @@
|
|||
use std::error::Error;
|
||||
use std::ffi::OsStr;
|
||||
use std::io::Result as IoResult;
|
||||
use std::process::Command;
|
||||
use std::process::Output;
|
||||
|
||||
pub trait CommandRunner {
|
||||
fn run_with_args(&self, program: &str, args: &[&str]) -> IoResult<Output>;
|
||||
fn get_output(&self, program: &str, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
|
||||
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>> {
|
||||
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(&self, program: &str, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
|
||||
fn get_stderr<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<Vec<u8>, Box<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(&self, program: &str, args: &[&str]) -> Result<(), Box<Error>> {
|
||||
fn run_successfully<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> Result<(), Box<Error>> {
|
||||
let output = try!(self.run_with_args(program, args));
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
|
|
@ -33,9 +34,9 @@ pub trait CommandRunner {
|
|||
pub struct StdCommandRunner;
|
||||
|
||||
impl CommandRunner for StdCommandRunner {
|
||||
fn run_with_args(&self, program: &str, args: &[&str]) -> IoResult<Output> {
|
||||
fn run_with_args<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult<Output> {
|
||||
// FIXME: logger
|
||||
println!("{} {:?}", program, args);
|
||||
//println!("{} {:?}", program, args);
|
||||
let res = Command::new(program).args(args).output();
|
||||
println!("{:?}", res);
|
||||
res
|
||||
|
|
@ -81,11 +82,11 @@ impl<'a> Drop for TempSetEnv<'a> {
|
|||
}
|
||||
|
||||
impl<'a, C> CommandRunner for SetuidCommandRunner<'a, C> where C: 'a + CommandRunner {
|
||||
fn run_with_args(&self, program: &str, args: &[&str]) -> IoResult<Output> {
|
||||
fn run_with_args<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult<Output> {
|
||||
let uid = get_user_by_name(self.user_name).expect("User does not exist").uid();
|
||||
let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name));
|
||||
let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
|
||||
println!("{} {:?}", program, args);
|
||||
//println!("{} {:?}", program, args);
|
||||
let res = Command::new(program).uid(uid).gid(uid).args(args).output();
|
||||
println!("{:?}", res);
|
||||
res
|
||||
|
|
@ -110,9 +111,11 @@ impl<'a, C> SuCommandRunner<'a, C> where C: 'a + CommandRunner {
|
|||
// Su doesn't set XDG_RUNTIME_DIR
|
||||
// https://github.com/systemd/systemd/blob/master/src/login/pam_systemd.c#L439
|
||||
impl<'a, C> CommandRunner for SuCommandRunner<'a, C> where C: 'a + CommandRunner {
|
||||
fn run_with_args(&self, program: &str, args: &[&str]) -> IoResult<Output> {
|
||||
let mut new_args = vec![self.user_name, "-s", "/usr/bin/env", "--", program];
|
||||
new_args.extend_from_slice(args);
|
||||
fn run_with_args<S: AsRef<OsStr> + ?Sized>(&self, program: &str, args: &[&S]) -> IoResult<Output> {
|
||||
let raw_new_args = [self.user_name, "-s", "/usr/bin/env", "--", program];
|
||||
let mut new_args: Vec<&OsStr> = raw_new_args.iter().map(|s| s.as_ref()).collect();
|
||||
let old_args: Vec<&OsStr> = args.iter().map(|s| s.as_ref()).collect();
|
||||
new_args.extend_from_slice(&old_args);
|
||||
self.command_runner.run_with_args("su", &new_args)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct AcmeAccountKey<'a> {
|
||||
path: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
pub struct AcmeAccountKey<'a, C: 'a + CommandRunner> {
|
||||
path: Cow<'a, Path>,
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> AcmeAccountKey<'a> {
|
||||
pub fn new(path: Cow<'a, str>, command_runner: &'a CommandRunner) -> AcmeAccountKey<'a> {
|
||||
impl<'a, C: CommandRunner> AcmeAccountKey<'a, C> {
|
||||
pub fn new(path: Cow<'a, Path>, command_runner: &'a C) -> Self {
|
||||
AcmeAccountKey {
|
||||
path: path,
|
||||
command_runner: command_runner
|
||||
}
|
||||
}
|
||||
|
||||
fn get_path(&self) -> &str {
|
||||
fn get_path(&self) -> &Path {
|
||||
self.path.borrow()
|
||||
}
|
||||
|
||||
|
|
@ -29,27 +29,27 @@ impl<'a> AcmeAccountKey<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for AcmeAccountKey<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "AcmeAccountKey {}", self.path)
|
||||
write!(f, "AcmeAccountKey {}", self.get_path().display())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for AcmeAccountKey<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for AcmeAccountKey<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(self.get_path()).exists() {
|
||||
if !self.get_path().exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
let stdout = try!(self.command_runner.get_output("openssl", &["rsa", "-in", self.get_path(), "-noout", "-check", "-text"]));
|
||||
let stdout = try!(self.command_runner.get_output("openssl", &["rsa".as_ref(), "-in".as_ref(), self.get_path().as_os_str(), "-noout".as_ref(), "-check".as_ref(), "-text".as_ref()]));
|
||||
Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
self.command_runner.run_successfully("openssl", &["genrsa", "-out", self.get_path(), &self.get_bytes().to_string()])
|
||||
self.command_runner.run_successfully("openssl", &["genrsa".as_ref(), "-out".as_ref(), self.get_path().as_os_str(), self.get_bytes().to_string().as_ref()])
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Resource> {
|
||||
vec![ Resource::new("dir", Path::new(self.get_path()).parent().unwrap().to_string_lossy() ) ]
|
||||
vec![ Resource::new("dir", self.get_path().parent().unwrap().to_string_lossy() ) ]
|
||||
}
|
||||
|
||||
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ use command_runner::CommandRunner;
|
|||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
use resources::Resource;
|
||||
|
||||
pub struct AcmeCert<'a> {
|
||||
pub struct AcmeCert<'a, C: 'a + CommandRunner> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> AcmeCert<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> AcmeCert<'a> {
|
||||
impl<'a, C: CommandRunner> AcmeCert<'a, C> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
AcmeCert {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
|
|
@ -31,7 +31,7 @@ impl<'a> AcmeCert<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for AcmeCert<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for AcmeCert<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "AcmeCert {}", self.domain)
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ impl<'a> fmt::Display for AcmeCert<'a> {
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24*60*60;
|
||||
|
||||
impl<'a> Symbol for AcmeCert<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for AcmeCert<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(&self.get_cert_path()).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ use command_runner::CommandRunner;
|
|||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
use resources::Resource;
|
||||
|
||||
pub struct AcmeCertChain<'a> {
|
||||
pub struct AcmeCertChain<'a, C: 'a + CommandRunner> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> AcmeCertChain<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> AcmeCertChain<'a> {
|
||||
impl<'a, C: CommandRunner> AcmeCertChain<'a, C> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
AcmeCertChain {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
|
|
@ -31,7 +31,7 @@ impl<'a> AcmeCertChain<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for AcmeCertChain<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for AcmeCertChain<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "AcmeCertChain {}", self.domain)
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ impl<'a> fmt::Display for AcmeCertChain<'a> {
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24*60*60;
|
||||
|
||||
impl<'a> Symbol for AcmeCertChain<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for AcmeCertChain<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(&self.get_cert_chain_path()).exists() {
|
||||
return Ok(false);
|
||||
|
|
@ -54,7 +54,7 @@ impl<'a> Symbol for AcmeCertChain<'a> {
|
|||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
let output = try!(self.command_runner.get_output("cat", &[&self.get_single_cert_path(), "/home/acme/lets_encrypt_x3_cross_signed.pem"]));
|
||||
let output = try!(self.command_runner.get_output("cat", &[self.get_single_cert_path().as_ref(), "/home/acme/lets_encrypt_x3_cross_signed.pem"]));
|
||||
let mut file = try!(FsFile::create(self.get_cert_chain_path()));
|
||||
try!(file.write_all(&output));
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
mod account_key;
|
||||
mod cert;
|
||||
mod chain;
|
||||
mod user;
|
||||
|
||||
pub use self::account_key::AcmeAccountKey;
|
||||
pub use self::cert::AcmeCert;
|
||||
pub use self::chain::AcmeCertChain;
|
||||
pub use self::user::new as newAcmeUser;
|
||||
|
|
|
|||
66
src/symbols/acme/user.rs
Normal file
66
src/symbols/acme/user.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use std::borrow::{Borrow, Cow};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
use resources::Resource;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, SymbolAction, SymbolRunner, Symbol};
|
||||
use symbols::acme::AcmeAccountKey;
|
||||
use symbols::dir::Dir;
|
||||
use symbols::file::File;
|
||||
use symbols::hook::Hook;
|
||||
use symbols::list::List;
|
||||
use symbols::owner::Owner;
|
||||
|
||||
pub struct AcmeUser<'a>(Cow<'a, str>);
|
||||
|
||||
impl<'a> AcmeUser<'a> {
|
||||
pub fn new<S: Into<Cow<'a, str>>>(user_name: S) -> Self {
|
||||
AcmeUser(user_name.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for AcmeUser<'a> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
Ok(false)
|
||||
}
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
Ok(())
|
||||
}
|
||||
fn get_prerequisites(&self) -> Vec<Resource> {
|
||||
vec![]
|
||||
}
|
||||
fn provides(&self) -> Option<Vec<Resource>> {
|
||||
None
|
||||
}
|
||||
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
|
||||
Box::new(SymbolAction::new(runner, self))
|
||||
}
|
||||
|
||||
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
|
||||
Box::new(OwnedSymbolAction::new(runner, *self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for AcmeUser<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "AcmeUser {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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![
|
||||
Box::new(AcmeAccountKey::new(account_key_file.clone().into(), command_runner)),
|
||||
Box::new(Owner::new(account_key_file.to_string_lossy().into_owned(), user_name_cow.clone(), command_runner)),
|
||||
Box::new(Dir::new("/home/acme/challenges")),
|
||||
Box::new(Owner::new("/home/acme/challenges", user_name_cow.clone(), command_runner)),
|
||||
Box::new(Dir::new("/etc/ssl/local_certs")),
|
||||
Box::new(Owner::new("/etc/ssl/local_certs", user_name_cow, command_runner)),
|
||||
Box::new(File::new("/home/acme/lets_encrypt_x3_cross_signed.pem", cert))
|
||||
]))
|
||||
}
|
||||
|
||||
|
|
@ -7,15 +7,15 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct GitCheckout<'a> {
|
||||
pub struct GitCheckout<'a, C: 'a + CommandRunner> {
|
||||
target: &'a str,
|
||||
source: &'a str,
|
||||
branch: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> GitCheckout<'a> {
|
||||
pub fn new(target: &'a str, source: &'a str, branch: &'a str, command_runner: &'a CommandRunner) -> GitCheckout<'a> {
|
||||
impl<'a, C: CommandRunner> GitCheckout<'a, C> {
|
||||
pub fn new(target: &'a str, source: &'a str, branch: &'a str, command_runner: &'a C) -> Self {
|
||||
GitCheckout {
|
||||
target: target,
|
||||
source: source,
|
||||
|
|
@ -25,7 +25,7 @@ impl<'a> GitCheckout<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for GitCheckout<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for GitCheckout<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Checkout {} (branch {}) into {}", self.source, self.branch, self.target)
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ impl<'a> fmt::Display for GitCheckout<'a> {
|
|||
|
||||
use std::fs::metadata;
|
||||
|
||||
impl<'a> GitCheckout<'a> {
|
||||
impl<'a, C: CommandRunner> GitCheckout<'a, C> {
|
||||
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
|
||||
let mut new_args = vec!["-C", self.target];
|
||||
new_args.extend_from_slice(args);
|
||||
|
|
@ -41,7 +41,7 @@ impl<'a> GitCheckout<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for GitCheckout<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for GitCheckout<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if let Err(e) = metadata(self.target) {
|
||||
return if e.kind() == io::ErrorKind::NotFound {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ use std::path::Path;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct GitSubmodules<'a> {
|
||||
pub struct GitSubmodules<'a, C: 'a + CommandRunner> {
|
||||
target: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> GitSubmodules<'a> {
|
||||
pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> GitSubmodules<'a> {
|
||||
impl<'a, C: CommandRunner> GitSubmodules<'a, C> {
|
||||
pub fn new(target: &'a str, command_runner: &'a C) -> Self {
|
||||
GitSubmodules {
|
||||
target: target,
|
||||
command_runner: command_runner
|
||||
|
|
@ -19,13 +19,13 @@ impl<'a> GitSubmodules<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for GitSubmodules<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for GitSubmodules<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Submodules for {}", self.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GitSubmodules<'a> {
|
||||
impl<'a, C: CommandRunner> GitSubmodules<'a, C> {
|
||||
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, Box<Error>> {
|
||||
let mut new_args = vec!["-C", self.target];
|
||||
new_args.extend_from_slice(args);
|
||||
|
|
@ -33,7 +33,7 @@ impl<'a> GitSubmodules<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for GitSubmodules<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(self.target).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ use std::fmt;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct MariaDBDatabase<'a> {
|
||||
pub struct MariaDBDatabase<'a, C: 'a + CommandRunner> {
|
||||
db_name: Cow<'a, str>,
|
||||
seed_file: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> MariaDBDatabase<'a> {
|
||||
pub fn new(db_name: Cow<'a, str>, seed_file: Cow<'a, str>, command_runner: &'a CommandRunner) -> MariaDBDatabase<'a> {
|
||||
impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> {
|
||||
pub fn new(db_name: Cow<'a, str>, seed_file: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
MariaDBDatabase {
|
||||
db_name: db_name,
|
||||
seed_file: seed_file,
|
||||
|
|
@ -26,13 +26,13 @@ impl<'a> MariaDBDatabase<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for MariaDBDatabase<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for MariaDBDatabase<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MariaDB Database {}", self.db_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for MariaDBDatabase<'a> {
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ use command_runner::CommandRunner;
|
|||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
use storage::Storage;
|
||||
|
||||
pub struct DatabaseDump<'a, S> where S: Storage {
|
||||
pub struct DatabaseDump<'a, C, S> where C: 'a + CommandRunner, S: Storage {
|
||||
db_name: Cow<'a, str>,
|
||||
storage: S,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a, S> DatabaseDump<'a, S> where S: Storage {
|
||||
pub fn new(db_name: Cow<'a, str>, storage: S, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, C: CommandRunner, S> DatabaseDump<'a, C, S> where S: Storage {
|
||||
pub fn new(db_name: Cow<'a, str>, storage: S, command_runner: &'a C) -> Self {
|
||||
DatabaseDump {
|
||||
db_name: db_name,
|
||||
storage: storage,
|
||||
|
|
@ -28,13 +28,13 @@ impl<'a, S> DatabaseDump<'a, S> where S: Storage {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S> fmt::Display for DatabaseDump<'a, S> where S: Storage {
|
||||
impl<'a, C: CommandRunner, S> fmt::Display for DatabaseDump<'a, C, S> where S: Storage {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Dump MariaDB Database {}", self.db_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S> Symbol for DatabaseDump<'a, S> where S: Storage {
|
||||
impl<'a, C: CommandRunner, S> Symbol for DatabaseDump<'a, C, S> where S: Storage {
|
||||
fn target_reached(&self) -> Result<bool, Box<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)));
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct MariaDBUser<'a> {
|
||||
pub struct MariaDBUser<'a, C: 'a + CommandRunner> {
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> MariaDBUser<'a> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> MariaDBUser<'a> {
|
||||
impl<'a, C: CommandRunner> MariaDBUser<'a, C> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
MariaDBUser {
|
||||
user_name: user_name,
|
||||
command_runner: command_runner
|
||||
|
|
@ -25,13 +25,13 @@ impl<'a> MariaDBUser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for MariaDBUser<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for MariaDBUser<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "MariaDB User {}", self.user_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for MariaDBUser<'a> {
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,16 +41,15 @@ impl<E: Error> fmt::Display for NginxServerError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct NginxServer<'a, C> where C: Deref<Target=str> {
|
||||
command_runner: &'a CommandRunner,
|
||||
file: FileSymbol<C, Cow<'a, str>>,
|
||||
pub struct NginxServer<'a, C: 'a + CommandRunner, T> where T: Deref<Target=str> {
|
||||
command_runner: &'a C,
|
||||
file: FileSymbol<T, Cow<'a, str>>,
|
||||
}
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
impl<'a> NginxServer<'a, String> {
|
||||
pub fn server_config(domain: &str, content: &str) -> String {
|
||||
format!("server {{
|
||||
pub fn server_config(domain: &str, content: &str) -> String {
|
||||
format!("server {{
|
||||
listen 80;
|
||||
server_name {0};
|
||||
include \"snippets/acme-challenge.conf\";
|
||||
|
|
@ -73,16 +72,17 @@ server {{
|
|||
{1}
|
||||
}}
|
||||
", domain, content)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_redir(domain: &'a str, target: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
let content = NginxServer::server_config(domain, &format!("location / {{
|
||||
impl<'a, C: CommandRunner> NginxServer<'a, C, String> {
|
||||
pub fn new_redir(domain: &'a str, target: &'a str, command_runner: &'a C) -> Self {
|
||||
let content = server_config(domain, &format!("location / {{
|
||||
return 301 $scheme://{}$request_uri;
|
||||
}}", target));
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_proxy(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
pub fn new_proxy(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a C) -> Self {
|
||||
let proxy_content = format!("location / {{
|
||||
try_files $uri @proxy;
|
||||
}}
|
||||
|
|
@ -93,15 +93,15 @@ location @proxy {{
|
|||
proxy_redirect off;
|
||||
}}", socket_path);
|
||||
|
||||
let content = NginxServer::server_config(domain, &format!("
|
||||
let content = server_config(domain, &format!("
|
||||
root {};
|
||||
{}
|
||||
", static_path, proxy_content));
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_php(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
let content = NginxServer::server_config(domain, &format!("
|
||||
pub fn new_php(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a C) -> Self {
|
||||
let content = server_config(domain, &format!("
|
||||
root {};
|
||||
index index.html index.php;
|
||||
location ~ [^/]\\.php(/|$) {{
|
||||
|
|
@ -112,15 +112,15 @@ location @proxy {{
|
|||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_static(domain: &'a str, static_path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
let content = NginxServer::server_config(domain, &format!("
|
||||
pub fn new_static(domain: &'a str, static_path: &'a str, command_runner: &'a C) -> Self {
|
||||
let content = server_config(domain, &format!("
|
||||
root {};
|
||||
try_files $uri $uri/ $uri.html =404;
|
||||
", static_path));
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new(domain: &'a str, content: String, command_runner: &'a CommandRunner) -> Self {
|
||||
pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self {
|
||||
let file_path: Cow<str> = Cow::from(String::from("/etc/nginx/sites-enabled/") + domain);
|
||||
NginxServer {
|
||||
command_runner: command_runner,
|
||||
|
|
@ -129,7 +129,7 @@ location @proxy {{
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C> Symbol for NginxServer<'a, C> where C: Deref<Target=str> {
|
||||
impl<'a, C: CommandRunner, T> Symbol for NginxServer<'a, C, T> where T: Deref<Target=str> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !try!(self.file.target_reached()) {
|
||||
return Ok(false);
|
||||
|
|
@ -156,7 +156,7 @@ impl<'a, C> Symbol for NginxServer<'a, C> where C: Deref<Target=str> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C> fmt::Display for NginxServer<'a, C> where C: Deref<Target=str> {
|
||||
impl<'a, C: CommandRunner, T> fmt::Display for NginxServer<'a, C, T> where T: Deref<Target=str> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
|
||||
write!(f, "Nginx server config")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ use std::path::Path;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct NpmInstall<'a> {
|
||||
pub struct NpmInstall<'a, C: 'a + CommandRunner> {
|
||||
target: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> NpmInstall<'a> {
|
||||
pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> NpmInstall<'a> {
|
||||
impl<'a, C: CommandRunner> NpmInstall<'a, C> {
|
||||
pub fn new(target: &'a str, command_runner: &'a C) -> Self {
|
||||
NpmInstall {
|
||||
target: target,
|
||||
command_runner: command_runner
|
||||
|
|
@ -19,13 +19,13 @@ impl<'a> NpmInstall<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for NpmInstall<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for NpmInstall<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "npm install in {}", self.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for NpmInstall<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for NpmInstall<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(self.target).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct Owner<'a, D> where D: AsRef<str> + fmt::Display {
|
||||
pub struct Owner<'a, C: 'a + CommandRunner, D> where D: AsRef<str> + fmt::Display {
|
||||
path: D,
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a, D> Owner<'a, D> where D: AsRef<str> + fmt::Display {
|
||||
pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
|
||||
pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
Owner { path: path, user_name: user_name, command_runner: command_runner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, D> Symbol for Owner<'a, D> where D: AsRef<str> + fmt::Display {
|
||||
impl<'a, C: CommandRunner, D> Symbol for Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(self.path.as_ref()).exists() {
|
||||
return Ok(false);
|
||||
|
|
@ -50,7 +50,7 @@ impl<'a, D> Symbol for Owner<'a, D> where D: AsRef<str> + fmt::Display {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D> fmt::Display for Owner<'a, D> where D: AsRef<str> + fmt::Display {
|
||||
impl<'a, C: CommandRunner, D> fmt::Display for Owner<'a, C, D> where D: AsRef<str> + fmt::Display {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
|
||||
write!(f, "Owner {} for {}", self.user_name, self.path)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@ use storage::Storage;
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub enum StorageDirection { Load, Save }
|
||||
|
||||
pub struct StoredDirectory<'a, S> where S: Storage {
|
||||
pub struct StoredDirectory<'a, S, C: 'a + CommandRunner> where S: Storage {
|
||||
path: Cow<'a, str>,
|
||||
storage: S,
|
||||
dir: StorageDirection,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a, S> StoredDirectory<'a, S> where S: Storage {
|
||||
pub fn new(path: Cow<'a, str>, storage: S, dir: StorageDirection, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, S, C: CommandRunner> StoredDirectory<'a, S, C> where S: Storage {
|
||||
pub fn new(path: Cow<'a, str>, storage: S, dir: StorageDirection, command_runner: &'a C) -> Self {
|
||||
StoredDirectory {
|
||||
path: path,
|
||||
storage: storage,
|
||||
|
|
@ -32,13 +32,13 @@ impl<'a, S> StoredDirectory<'a, S> where S: Storage {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S> fmt::Display for StoredDirectory<'a, S> where S: Storage {
|
||||
impl<'a, S, C: CommandRunner> fmt::Display for StoredDirectory<'a, S, C> where S: Storage {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Stored directory {} ({:?})", self.path, self.dir)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S> Symbol for StoredDirectory<'a, S> where S: Storage {
|
||||
impl<'a, S, C: CommandRunner> Symbol for StoredDirectory<'a, S, C> where S: Storage {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
let metadata = fs::metadata(self.path.as_ref());
|
||||
// Check if dir exists
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ use std::fmt;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct ReloadService<'a> {
|
||||
pub struct ReloadService<'a, C: 'a + CommandRunner> {
|
||||
service: &'a str,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> ReloadService<'a> {
|
||||
pub fn new(service: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, C: CommandRunner> ReloadService<'a, C> {
|
||||
pub fn new(service: &'a str, command_runner: &'a C) -> Self {
|
||||
ReloadService {
|
||||
service: service,
|
||||
command_runner: command_runner
|
||||
|
|
@ -18,7 +18,7 @@ impl<'a> ReloadService<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for ReloadService<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
Ok(true)
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ impl<'a> Symbol for ReloadService<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for ReloadService<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for ReloadService<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
|
||||
write!(f, "Reload service {}", self.service)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@ impl<E: Error> fmt::Display for SystemdUserSessionError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SystemdUserSession<'a> {
|
||||
pub struct SystemdUserSession<'a, C: 'a + CommandRunner> {
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> SystemdUserSession<'a> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, C: CommandRunner> SystemdUserSession<'a, C> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
SystemdUserSession {
|
||||
user_name: user_name,
|
||||
command_runner: command_runner
|
||||
|
|
@ -47,7 +47,7 @@ impl<'a> SystemdUserSession<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for SystemdUserSession<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for SystemdUserSession<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
let mut path = PathBuf::from("/var/lib/systemd/linger");
|
||||
path.push(self.user_name.borrow() as &str);
|
||||
|
|
@ -68,7 +68,7 @@ impl<'a> Symbol for SystemdUserSession<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for SystemdUserSession<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for SystemdUserSession<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
|
||||
write!(f, "Systemd user session for {}", self.user_name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct TlsCsr<'a> {
|
||||
pub struct TlsCsr<'a, C: 'a + CommandRunner> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> TlsCsr<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> TlsCsr<'a> {
|
||||
impl<'a, C: CommandRunner> TlsCsr<'a, C> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
TlsCsr {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
|
|
@ -29,13 +29,13 @@ impl<'a> TlsCsr<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for TlsCsr<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for TlsCsr<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "TlsCsr {}", self.domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for TlsCsr<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(&self.get_csr_path()).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ use std::path::Path;
|
|||
use command_runner::CommandRunner;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct TlsKey<'a> {
|
||||
pub struct TlsKey<'a, C: 'a + CommandRunner> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> TlsKey<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> TlsKey<'a> {
|
||||
impl<'a, C: CommandRunner> TlsKey<'a, C> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
TlsKey {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
|
|
@ -28,13 +28,13 @@ impl<'a> TlsKey<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for TlsKey<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for TlsKey<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "TlsKey {}", self.domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for TlsKey<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(&self.get_path()).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ use command_runner::CommandRunner;
|
|||
use resources::Resource;
|
||||
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct SelfSignedTlsCert<'a> {
|
||||
pub struct SelfSignedTlsCert<'a, C: 'a + CommandRunner> {
|
||||
domain: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> SelfSignedTlsCert<'a> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a CommandRunner) -> SelfSignedTlsCert<'a> {
|
||||
impl<'a, C: CommandRunner> SelfSignedTlsCert<'a, C> {
|
||||
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
|
||||
SelfSignedTlsCert {
|
||||
domain: domain,
|
||||
command_runner: command_runner
|
||||
|
|
@ -29,7 +29,7 @@ impl<'a> SelfSignedTlsCert<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for SelfSignedTlsCert<'a> {
|
||||
impl<'a, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "SelfSignedTlsCert {}", self.domain)
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ impl<'a> fmt::Display for SelfSignedTlsCert<'a> {
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24*60*60;
|
||||
|
||||
impl<'a> Symbol for SelfSignedTlsCert<'a> {
|
||||
impl<'a, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !Path::new(&self.get_cert_path()).exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -71,14 +71,14 @@ impl fmt::Display for UserError {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct User<'a, E, A> where E: Error + Sized, A: 'a + UserAdder<SubE=E> {
|
||||
pub struct User<'a, C: 'a + CommandRunner, E, A> where E: Error + Sized, A: 'a + UserAdder<SubE=E> {
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a CommandRunner,
|
||||
command_runner: &'a C,
|
||||
user_adder: &'a A
|
||||
}
|
||||
|
||||
impl<'a, E: Error + Sized, A: 'a + UserAdder<SubE=E>> User<'a, E, A> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a CommandRunner, user_adder: &'a A) -> User<'a, E, A> {
|
||||
impl<'a, C: CommandRunner, E: Error + Sized, A: 'a + UserAdder<SubE=E>> User<'a, C, E, A> {
|
||||
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C, user_adder: &'a A) -> Self {
|
||||
User {
|
||||
user_name: user_name,
|
||||
command_runner: command_runner,
|
||||
|
|
@ -87,13 +87,13 @@ impl<'a, E: Error + Sized, A: 'a + UserAdder<SubE=E>> User<'a, E, A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, E: Error, A: UserAdder<SubE=E>> fmt::Display for User<'a, E, A> {
|
||||
impl<'a, C: CommandRunner, E: Error, A: UserAdder<SubE=E>> fmt::Display for User<'a, C, E, A> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "User {}", self.user_name)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> {
|
||||
impl<'a, C: CommandRunner, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, C, E, A> {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
let output = try!(self.command_runner.run_with_args("getent", &["passwd", &*self.user_name]));
|
||||
match output.status.code() {
|
||||
|
|
@ -120,17 +120,17 @@ impl<'a, E: 'static + Error, A: UserAdder<SubE=E>> Symbol for User<'a, E, A> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SystemUserAdder<'a> {
|
||||
command_runner: &'a CommandRunner
|
||||
pub struct SystemUserAdder<'a, C: 'a + CommandRunner> {
|
||||
command_runner: &'a C
|
||||
}
|
||||
|
||||
impl<'a> SystemUserAdder<'a> {
|
||||
pub fn new(command_runner: &'a CommandRunner) -> SystemUserAdder<'a> {
|
||||
impl<'a, C: CommandRunner> SystemUserAdder<'a, C> {
|
||||
pub fn new(command_runner: &'a C) -> Self {
|
||||
SystemUserAdder { command_runner: command_runner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> UserAdder for SystemUserAdder<'a> {
|
||||
impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
|
||||
type SubE = IoError;
|
||||
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError<IoError>> {
|
||||
let output = self.command_runner.run_with_args(
|
||||
|
|
|
|||
|
|
@ -54,10 +54,11 @@ impl<'a, C, R> Symbol for WordpressPlugin<'a, C, R> where C: Deref<Target=str> +
|
|||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<Error>> {
|
||||
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", &[&format!("https://downloads.wordpress.org/plugin/{}.zip", self.name), "-o", &zip]));
|
||||
try!(self.command_runner.run_successfully("curl", &[source.as_ref() as &str, "-o", zip.as_ref()]));
|
||||
try!(self.command_runner.run_successfully("rm", &["-rf", &self.get_path().to_string_lossy()]));
|
||||
self.command_runner.run_successfully("unzip", &[&zip, "-d", &Path::new(&*self.base).join("wp-content/plugins").to_string_lossy()])
|
||||
self.command_runner.run_successfully("unzip", &[zip.as_ref(), "-d".as_ref(), Path::new(&*self.base).join("wp-content/plugins").as_os_str()])
|
||||
}
|
||||
|
||||
fn get_prerequisites(&self) -> Vec<Resource> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue