Lint
This commit is contained in:
parent
64bdf403d4
commit
e060ce5a68
35 changed files with 142 additions and 236 deletions
|
|
@ -106,7 +106,7 @@ impl<'a> TempSetEnv<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for TempSetEnv<'a> {
|
||||
impl Drop for TempSetEnv<'_> {
|
||||
fn drop(&mut self) {
|
||||
match self.old_value {
|
||||
Some(ref val) => env::set_var(self.name, val),
|
||||
|
|
@ -115,7 +115,7 @@ impl<'a> Drop for TempSetEnv<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'a, U, C> {
|
||||
impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> {
|
||||
fn run_with_args_and_stdin(
|
||||
&self,
|
||||
program: &str,
|
||||
|
|
@ -125,8 +125,8 @@ impl<'a, U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<
|
|||
let uid = get_user_by_name(self.user_name.as_ref())
|
||||
.expect("User does not exist")
|
||||
.uid();
|
||||
let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
|
||||
let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
|
||||
let _set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
|
||||
let _set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
|
||||
//println!("{} {:?}", program, args);
|
||||
let mut child = Command::new(program)
|
||||
.args(args)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub struct Factory {}
|
|||
|
||||
impl Factory {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn get_repo<'a, CR: CommandRunner>(
|
||||
|
|
@ -87,15 +87,15 @@ impl<'a, C: CommandRunner> SymbolRepository<'a>
|
|||
matches[1].to_string(),
|
||||
self.command_runner,
|
||||
)),
|
||||
])) 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<dyn Symbol>
|
||||
))
|
||||
} else {
|
||||
Box::new(Dir::new(value.to_string())) as Box<dyn Symbol>
|
||||
Box::new(Dir::new(value.to_string()))
|
||||
})
|
||||
}
|
||||
"file" => {
|
||||
|
|
@ -104,17 +104,17 @@ impl<'a, C: CommandRunner> SymbolRepository<'a>
|
|||
Some(Box::new(TlsCsr::new(
|
||||
matches[1].to_string().into(),
|
||||
self.command_runner,
|
||||
)) 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<dyn Symbol>)
|
||||
)))
|
||||
} else if let Some(matches) = self.systemd_linger.captures(value) {
|
||||
Some(Box::new(SystemdUserSession::new(
|
||||
matches[1].to_string(),
|
||||
self.command_runner,
|
||||
)) as Box<dyn Symbol>)
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
28
src/lib.rs
28
src/lib.rs
|
|
@ -1,23 +1,29 @@
|
|||
// rustfmt
|
||||
|
||||
#![deny(
|
||||
macro_use_extern_crate,
|
||||
meta_variable_misuse,
|
||||
non_ascii_idents,
|
||||
trivial_numeric_casts,
|
||||
unused,
|
||||
unreachable_pub,
|
||||
unsafe_code,
|
||||
unstable_features,
|
||||
unused_extern_crates,
|
||||
unused_import_braces,
|
||||
unused_qualifications,
|
||||
variant_size_differences,
|
||||
clippy::use_self
|
||||
rust_2018_idioms,
|
||||
future_incompatible,
|
||||
clippy::cargo,
|
||||
clippy::nursery,
|
||||
clippy::pedantic
|
||||
)]
|
||||
#![warn(unused_results)]
|
||||
/*
|
||||
#![warn(missing_docs, trivial_casts,
|
||||
#![allow(
|
||||
single_use_lifetimes,
|
||||
trivial_casts,
|
||||
clippy::module_name_repetitions,
|
||||
clippy::cargo_common_metadata,
|
||||
rustdoc,
|
||||
missing_docs,
|
||||
missing_copy_implementations,
|
||||
missing_debug_implementations
|
||||
)]
|
||||
*/
|
||||
#![allow(box_pointers)]
|
||||
|
||||
#[macro_use]
|
||||
mod for_each_tuple;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<'a> FilteringLogger<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Logger for FilteringLogger<'a> {
|
||||
impl Logger for FilteringLogger<'_> {
|
||||
fn debug(&mut self, _str: &str) {}
|
||||
fn write(&mut self, str: &str) {
|
||||
self.logger.write(str)
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ pub enum SymbolRunError {
|
|||
impl Error for SymbolRunError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
SymbolRunError::Symbol(_) => "Symbol execution error",
|
||||
SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol",
|
||||
Self::Symbol(_) => "Symbol execution error",
|
||||
Self::ExecuteDidNotReach(_) => "Target not reached after executing symbol",
|
||||
}
|
||||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
match self {
|
||||
SymbolRunError::Symbol(ref e) => Some(&**e),
|
||||
SymbolRunError::ExecuteDidNotReach(_) => None,
|
||||
Self::Symbol(ref e) => Some(&**e),
|
||||
Self::ExecuteDidNotReach(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@ impl Error for SymbolRunError {
|
|||
impl fmt::Display for SymbolRunError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
SymbolRunError::Symbol(ref e) => write!(f, "{}", e),
|
||||
SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description()),
|
||||
Self::Symbol(ref e) => write!(f, "{}", e),
|
||||
Self::ExecuteDidNotReach(_) => write!(f, "{}", self.description()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -119,13 +119,10 @@ where
|
|||
let mut logger = self.1.borrow_mut();
|
||||
logger.debug(format!("Running symbol {}", symbol).as_str());
|
||||
let res = self.0.run_symbol(symbol);
|
||||
match res {
|
||||
Err(ref e) => {
|
||||
logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str());
|
||||
}
|
||||
Ok(_) => {
|
||||
logger.debug(format!("Successfully finished {}", symbol).as_str());
|
||||
}
|
||||
if let Err(ref e) = res {
|
||||
logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str())
|
||||
} else {
|
||||
logger.debug(format!("Successfully finished {}", symbol).as_str())
|
||||
}
|
||||
res
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub trait Storage {
|
|||
pub struct SimpleStorage(String, String);
|
||||
|
||||
impl SimpleStorage {
|
||||
pub fn new(base: String, filename: String) -> Self {
|
||||
pub const fn new(base: String, filename: String) -> Self {
|
||||
Self(base, filename)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> AcmeAccountKey<'a, P, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeAccountKey<'a, P, C> {
|
||||
impl<P: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeAccountKey<'_, P, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "AcmeAccountKey {}", self.path.as_ref().display())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> {
|
||||
impl<P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'_, P, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.path.as_ref().exists() {
|
||||
return Ok(false);
|
||||
|
|
@ -46,7 +46,7 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for AcmeAccountKey<'a, P, C> {
|
|||
"-text",
|
||||
],
|
||||
)?;
|
||||
Ok(stdout.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
Ok(stdout.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: As
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>>
|
||||
fmt::Display for AcmeCert<'a, D, R, C, K, CH>
|
||||
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> fmt::Display
|
||||
for AcmeCert<'_, D, R, C, K, CH>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "AcmeCert {}", self.domain.as_ref())
|
||||
|
|
@ -61,8 +61,8 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: As
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
|
||||
|
||||
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> Symbol
|
||||
for AcmeCert<'a, D, R, C, K, CH>
|
||||
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner, K: AsRef<Path>, CH: AsRef<Path>> Symbol
|
||||
for AcmeCert<'_, D, R, C, K, CH>
|
||||
{
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.get_cert_path().exists() {
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> AcmeCertChain<'a, D, R
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display
|
||||
for AcmeCertChain<'a, D, R, C>
|
||||
{
|
||||
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display for AcmeCertChain<'_, D, R, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "AcmeCertChain {}", self.domain.as_ref())
|
||||
}
|
||||
|
|
@ -42,7 +40,7 @@ impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> fmt::Display
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
|
||||
|
||||
impl<'a, D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> Symbol for AcmeCertChain<'a, D, R, C> {
|
||||
impl<D: AsRef<str>, R: AsRef<Path>, C: CommandRunner> Symbol for AcmeCertChain<'_, D, R, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.get_cert_chain_path().exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl<'a, U: Clone + AsRef<str>, H: AsRef<Path>, C: AsRef<str>, R: CommandRunner>
|
|||
acme_command_runner,
|
||||
}
|
||||
}
|
||||
pub fn get_challenges_dir(&'a self) -> Cow<Path> {
|
||||
pub fn get_challenges_dir(&'a self) -> Cow<'_, Path> {
|
||||
[self.home_dir.as_ref(), "challenges".as_ref()]
|
||||
.iter()
|
||||
.collect::<PathBuf>()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl<'r, U: AsRef<str>, R: CommandRunner> Cron<'r, String, U, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'r, C, U, R> {
|
||||
impl<C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'_, C, U, R> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let tab = self
|
||||
.command_runner
|
||||
|
|
@ -53,7 +53,7 @@ impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'r, C,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'r, C: AsRef<str>, U: AsRef<str>, R: CommandRunner> fmt::Display for Cron<'r, C, U, R> {
|
||||
impl<C: AsRef<str>, U: AsRef<str>, R: CommandRunner> fmt::Display for Cron<'_, C, U, R> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "Cron {}", self.user.as_ref())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use crate::symbols::stored_directory::{StorageDirection, StoredDirectory};
|
|||
use crate::symbols::systemd::reload::ReloadService;
|
||||
use crate::symbols::systemd::user_service::UserService;
|
||||
use crate::symbols::tls::SelfSignedTlsCert;
|
||||
use crate::symbols::{Symbol, SymbolRunner};
|
||||
use crate::symbols::Symbol;
|
||||
|
||||
pub trait Policy {
|
||||
fn user_name_for_host(&self, host_name: &'static str) -> String {
|
||||
|
|
@ -29,7 +29,7 @@ pub trait Policy {
|
|||
fn socket_path(&self, user_name: &str, service_name: &str) -> PathBuf {
|
||||
format!("/var/tmp/{}-{}.socket", user_name, service_name).into()
|
||||
}
|
||||
fn acme_user(&self) -> Cow<str> {
|
||||
fn acme_user(&self) -> Cow<'_, str> {
|
||||
"acme".into()
|
||||
}
|
||||
}
|
||||
|
|
@ -38,22 +38,20 @@ pub struct DefaultPolicy;
|
|||
|
||||
impl Policy for DefaultPolicy {}
|
||||
|
||||
pub struct SymbolFactory<'a, C: 'a + CommandRunner, R: 'a + SymbolRunner, P: 'a + Policy> {
|
||||
pub struct SymbolFactory<'a, C: CommandRunner, P: Policy> {
|
||||
command_runner: &'a C,
|
||||
acme_factory: AcmeFactory<'a, Cow<'a, str>, PathBuf, &'a str, C>,
|
||||
symbol_runner: &'a R,
|
||||
policy: &'a P,
|
||||
}
|
||||
|
||||
impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFactory<'b, C, R, P> {
|
||||
pub fn new(command_runner: &'b C, symbol_runner: &'b R, policy: &'b P, cert: &'b str) -> Self {
|
||||
impl<'b, C: 'b + CommandRunner, P: 'b + Policy> SymbolFactory<'b, C, P> {
|
||||
pub fn new(command_runner: &'b C, policy: &'b P, cert: &'b str) -> Self {
|
||||
let acme_user = policy.acme_user();
|
||||
let acme_home = policy.home_for_user(&acme_user);
|
||||
let acme_factory = AcmeFactory::new(acme_user, acme_home, cert, command_runner);
|
||||
SymbolFactory {
|
||||
command_runner,
|
||||
acme_factory,
|
||||
symbol_runner,
|
||||
policy,
|
||||
}
|
||||
}
|
||||
|
|
@ -289,7 +287,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
|
|||
),
|
||||
StoredDirectory::new(
|
||||
string_target,
|
||||
data.clone(),
|
||||
data,
|
||||
StorageDirection::Load,
|
||||
self.command_runner,
|
||||
),
|
||||
|
|
@ -395,7 +393,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
|
|||
let socket_path = self.policy.socket_path(&user_name, service_name);
|
||||
self.get_nginx_acme_server(
|
||||
host_name,
|
||||
NginxServer::new_proxy(host_name, socket_path, root_dir, self.command_runner),
|
||||
NginxServer::new_proxy(host_name, &socket_path, root_dir, self.command_runner),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'a, C, T> {
|
||||
impl<C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'_, C, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
|
@ -39,7 +39,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> fmt::Display for GitCheckout<'a, C, T
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
|
||||
impl<C: CommandRunner, T: AsRef<Path>> GitCheckout<'_, C, T> {
|
||||
fn _run_in_target_repo<S: AsRef<OsStr>>(&self, args: &[S]) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
let mut new_args = vec![OsStr::new("-C"), self.target.as_ref().as_ref()];
|
||||
new_args.extend(args.iter().map(AsRef::as_ref));
|
||||
|
|
@ -47,7 +47,7 @@ impl<'a, C: CommandRunner, T: AsRef<Path>> GitCheckout<'a, C, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, T: AsRef<Path>> Symbol for GitCheckout<'a, C, T> {
|
||||
impl<C: CommandRunner, T: AsRef<Path>> Symbol for GitCheckout<'_, C, T> {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, C: CommandRunner> fmt::Display for GitSubmodules<'a, P, C> {
|
||||
impl<P: AsRef<Path>, C: CommandRunner> fmt::Display for GitSubmodules<'_, P, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Submodules for {}", self.target.as_ref().display())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
|
||||
impl<P: AsRef<Path>, C: CommandRunner> GitSubmodules<'_, P, C> {
|
||||
fn _run_in_target_repo(&self, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
let mut new_args: Vec<&OsStr> = vec![];
|
||||
new_args.extend_from_slice(args!["-C", self.target.as_ref()]);
|
||||
|
|
@ -35,7 +35,7 @@ impl<'a, P: AsRef<Path>, C: CommandRunner> GitSubmodules<'a, P, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, C: CommandRunner> Symbol for GitSubmodules<'a, P, C> {
|
||||
impl<P: AsRef<Path>, C: CommandRunner> Symbol for GitSubmodules<'_, P, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.target.as_ref().exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ impl<'a> List<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Symbol for List<'a> {
|
||||
impl Symbol for List<'_> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
for symbol in &self.symbols {
|
||||
if !symbol.target_reached()? {
|
||||
|
|
@ -99,7 +99,7 @@ impl<'a> SymbolListAction<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Action for SymbolListAction<'a> {
|
||||
impl Action for SymbolListAction<'_> {
|
||||
fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||
for symbol in self.symbols {
|
||||
symbol.as_action(self.runner).run()?;
|
||||
|
|
@ -118,7 +118,7 @@ impl<'a> ListAction<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Action for ListAction<'a> {
|
||||
impl Action for ListAction<'_> {
|
||||
fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||
for action in &self.actions {
|
||||
action.run()?;
|
||||
|
|
@ -127,7 +127,7 @@ impl<'a> Action for ListAction<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for List<'a> {
|
||||
impl fmt::Display for List<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "List [ ")?;
|
||||
for symbol in &self.symbols {
|
||||
|
|
|
|||
|
|
@ -28,15 +28,15 @@ impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> MariaDBDatabase<'a, D,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> fmt::Display
|
||||
for MariaDBDatabase<'a, D, S, C>
|
||||
impl<D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> fmt::Display
|
||||
for MariaDBDatabase<'_, D, S, C>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "MariaDB Database {}", self.db_name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> Symbol for MariaDBDatabase<'a, D, S, C> {
|
||||
impl<D: AsRef<str>, S: AsRef<Path>, C: CommandRunner> Symbol for MariaDBDatabase<'_, D, S, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
Ok(
|
||||
self
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> {
|
||||
impl<N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'_, N, C, S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Dump MariaDB Database {}", self.db_name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'a, N, C, S> {
|
||||
impl<N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for DatabaseDump<'_, N, C, S> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let dump_date = self.storage.recent_date()?;
|
||||
let modified_date = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref()))?;
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl<'a, U: AsRef<str>, C: CommandRunner> MariaDBUser<'a, U, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, U: AsRef<str>, C: CommandRunner> fmt::Display for MariaDBUser<'a, U, C> {
|
||||
impl<U: AsRef<str>, C: CommandRunner> fmt::Display for MariaDBUser<'_, U, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "MariaDB User {}", self.user_name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for MariaDBUser<'a, U, C> {
|
||||
impl<U: AsRef<str>, C: CommandRunner> Symbol for MariaDBUser<'_, U, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
Ok(
|
||||
self
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl<'a, S: Symbol> SymbolAction<'a, S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S: Symbol> Action for SymbolAction<'a, S> {
|
||||
impl<S: Symbol> Action for SymbolAction<'_, S> {
|
||||
fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||
self.runner.run_symbol(self.symbol)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub enum NginxServerError<E: Error> {
|
|||
|
||||
impl From<io::Error> for NginxServerError<io::Error> {
|
||||
fn from(err: io::Error) -> Self {
|
||||
NginxServerError::ExecError(err)
|
||||
Self::ExecError(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ impl<E: Error> Error for NginxServerError<E> {
|
|||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
match self {
|
||||
NginxServerError::ExecError(ref e) => Some(e),
|
||||
Self::ExecError(ref e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ where
|
|||
pub struct LocalTcpSocket(usize);
|
||||
|
||||
impl LocalTcpSocket {
|
||||
pub fn new(x: usize) -> Self {
|
||||
pub const fn new(x: usize) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
|
@ -130,12 +130,12 @@ impl<'a, C: CommandRunner> NginxServer<'a, C, String, PathBuf> {
|
|||
target
|
||||
),
|
||||
);
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
Self::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_proxy<S: SocketSpec, STATIC: AsRef<Path>>(
|
||||
domain: &'a str,
|
||||
socket_path: S,
|
||||
socket_path: &'_ S,
|
||||
static_path: STATIC,
|
||||
command_runner: &'a C,
|
||||
) -> Self {
|
||||
|
|
@ -163,7 +163,7 @@ location @proxy {{
|
|||
proxy_content
|
||||
),
|
||||
);
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
Self::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_php<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>(
|
||||
|
|
@ -177,7 +177,7 @@ location @proxy {{
|
|||
domain,
|
||||
&(php_server_config_snippet(socket_path, static_path) + additional_config),
|
||||
);
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
Self::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new_static<S: AsRef<Path>>(
|
||||
|
|
@ -195,7 +195,7 @@ location @proxy {{
|
|||
static_path.as_ref().to_str().unwrap()
|
||||
),
|
||||
);
|
||||
NginxServer::new(domain, content, command_runner)
|
||||
Self::new(domain, content, command_runner)
|
||||
}
|
||||
|
||||
pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self {
|
||||
|
|
@ -207,7 +207,7 @@ location @proxy {{
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> Symbol for NginxServer<'a, C, T, P> {
|
||||
impl<C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> Symbol for NginxServer<'_, C, T, P> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.file.target_reached()? {
|
||||
return Ok(false);
|
||||
|
|
@ -239,9 +239,7 @@ impl<'a, C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> Symbol for NginxServer
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> fmt::Display
|
||||
for NginxServer<'a, C, T, P>
|
||||
{
|
||||
impl<C: CommandRunner, T: AsRef<str>, P: AsRef<Path>> fmt::Display for NginxServer<'_, C, T, P> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "Nginx server config")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ impl<'a, T: AsRef<Path>, C: CommandRunner> NpmInstall<'a, T, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C> {
|
||||
impl<T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'_, T, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
|
@ -29,7 +29,7 @@ impl<'a, T: AsRef<Path>, C: CommandRunner> fmt::Display for NpmInstall<'a, T, C>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: AsRef<Path>, C: CommandRunner> Symbol for NpmInstall<'a, T, C> {
|
||||
impl<T: AsRef<Path>, C: CommandRunner> Symbol for NpmInstall<'_, T, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.target.as_ref().exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Owner<'a, C, D, U> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'a, C, D, U> {
|
||||
impl<C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'_, C, D, U> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !Path::new(self.path.as_ref()).exists() {
|
||||
return Ok(false);
|
||||
|
|
@ -60,7 +60,7 @@ impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> Symbol for Owner<'a, C
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> fmt::Display for Owner<'a, C, D, U> {
|
||||
impl<C: CommandRunner, D: AsRef<Path>, U: AsRef<str>> fmt::Display for Owner<'_, C, D, U> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(
|
||||
f,
|
||||
|
|
|
|||
|
|
@ -28,17 +28,15 @@ impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> PostgreSQLDatabase<'a,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> fmt::Display
|
||||
for PostgreSQLDatabase<'a, N, S, C>
|
||||
impl<N: AsRef<str>, S: AsRef<str>, C: CommandRunner> fmt::Display
|
||||
for PostgreSQLDatabase<'_, N, S, C>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "PostgreSQL Database {}", self.name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, S: AsRef<str>, C: CommandRunner> Symbol
|
||||
for PostgreSQLDatabase<'a, N, S, C>
|
||||
{
|
||||
impl<N: AsRef<str>, S: AsRef<str>, C: CommandRunner> Symbol for PostgreSQLDatabase<'_, N, S, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
Ok(
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::command_runner::CommandRunner;
|
||||
use crate::storage::Storage;
|
||||
use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
||||
|
||||
pub struct DatabaseDump<'a, N: AsRef<str>, C: CommandRunner, S: Storage> {
|
||||
db_name: N,
|
||||
storage: S,
|
||||
command_runner: &'a C,
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> {
|
||||
pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self {
|
||||
DatabaseDump {
|
||||
db_name,
|
||||
storage,
|
||||
command_runner,
|
||||
}
|
||||
}
|
||||
|
||||
fn run_sql(&self, sql: &str) -> Result<String, Box<dyn Error>> {
|
||||
let b = self
|
||||
.command_runner
|
||||
.get_output("mariadb", args!["--skip-column-names", "-B", "-e", sql])?;
|
||||
Ok(String::from_utf8(b)?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> fmt::Display for DatabaseDump<'a, N, C, S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Dump MariaDB Database {}", self.db_name.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
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 = self.storage.recent_date()?;
|
||||
let modified_date = 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(u64::from_str(modified_date.trim_end())? <= dump_date)
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
||||
self.command_runner.run_successfully(
|
||||
"sh",
|
||||
args![
|
||||
"-c",
|
||||
format!(
|
||||
"mysqldump '{}' > {}",
|
||||
self.db_name.as_ref(),
|
||||
self.storage.write_filename()
|
||||
),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
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 dyn SymbolRunner) -> Box<dyn Action + 'b>
|
||||
where
|
||||
Self: 'b,
|
||||
{
|
||||
Box::new(OwnedSymbolAction::new(runner, *self))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
mod database;
|
||||
mod database_dump;
|
||||
|
||||
pub use self::database::PostgreSQLDatabase;
|
||||
//pub use self::database_dump::PostgreSQLDump;
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> StoredDirectory<'a, P, S,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display
|
||||
for StoredDirectory<'a, P, S, C>
|
||||
{
|
||||
impl<P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display for StoredDirectory<'_, P, S, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
|
@ -47,7 +45,7 @@ impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> fmt::Display
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'a, P, S, C> {
|
||||
impl<P: AsRef<Path>, S: Storage, C: CommandRunner> Symbol for StoredDirectory<'_, P, S, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let metadata = fs::metadata(self.path.as_ref());
|
||||
// Check if dir exists
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl<'a, C: CommandRunner> ReloadService<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> {
|
||||
impl<C: CommandRunner> Symbol for ReloadService<'_, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
Ok(true)
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> fmt::Display for ReloadService<'a, C> {
|
||||
impl<C: CommandRunner> fmt::Display for ReloadService<'_, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "Reload service {}", self.service)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ impl From<io::Error> for UserServiceError<io::Error> {
|
|||
impl<E: Error> Error for UserServiceError<E> {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
UserServiceError::ExecError(ref e) => e.description(),
|
||||
UserServiceError::GenericError => "Generic error",
|
||||
UserServiceError::ActivationFailed(_) => "Activation of service failed",
|
||||
Self::ExecError(ref e) => e.description(),
|
||||
Self::GenericError => "Generic error",
|
||||
Self::ActivationFailed(_) => "Activation of service failed",
|
||||
}
|
||||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
match self {
|
||||
UserServiceError::ExecError(ref e) => Some(e),
|
||||
Self::ExecError(ref e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -126,9 +126,7 @@ WantedBy=default.target
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner>
|
||||
UserService<'a, S, U, C, R>
|
||||
{
|
||||
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> UserService<'_, S, U, C, R> {
|
||||
fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result<String, Box<dyn Error>> {
|
||||
let mut tries = 5;
|
||||
loop {
|
||||
|
|
@ -176,8 +174,8 @@ impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
|
||||
for UserService<'a, S, U, C, R>
|
||||
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
|
||||
for UserService<'_, S, U, C, R>
|
||||
{
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !(self.config.target_reached()?) {
|
||||
|
|
@ -226,8 +224,8 @@ impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> Symbol
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> fmt::Display
|
||||
for UserService<'a, S, U, C, R>
|
||||
impl<S: AsRef<Path>, U: AsRef<str>, C: AsRef<str>, R: CommandRunner> fmt::Display
|
||||
for UserService<'_, S, U, C, R>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "Systemd user service unit for {}", self.service_name)
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ pub enum SystemdUserSessionError<E: Error> {
|
|||
impl<E: Error> Error for SystemdUserSessionError<E> {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
SystemdUserSessionError::ExecError(ref e) => e.description(),
|
||||
SystemdUserSessionError::GenericError => "Generic error",
|
||||
Self::ExecError(ref e) => e.description(),
|
||||
Self::GenericError => "Generic error",
|
||||
}
|
||||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
match self {
|
||||
SystemdUserSessionError::ExecError(ref e) => Some(e),
|
||||
Self::ExecError(ref e) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ impl<'a, U: AsRef<str>, C: CommandRunner> SystemdUserSession<'a, U, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C> {
|
||||
impl<U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'_, U, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let mut path = PathBuf::from("/var/lib/systemd/linger");
|
||||
path.push(self.user_name.as_ref());
|
||||
|
|
@ -72,7 +72,7 @@ impl<'a, U: AsRef<str>, C: CommandRunner> Symbol for SystemdUserSession<'a, U, C
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, U: AsRef<str>, C: CommandRunner> fmt::Display for SystemdUserSession<'a, U, C> {
|
||||
impl<U: AsRef<str>, C: CommandRunner> fmt::Display for SystemdUserSession<'_, U, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "Systemd user session for {}", self.user_name.as_ref())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ impl<'a, C: CommandRunner> TlsCsr<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> fmt::Display for TlsCsr<'a, C> {
|
||||
impl<C: CommandRunner> fmt::Display for TlsCsr<'_, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "TlsCsr {}", self.domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> Symbol for TlsCsr<'a, C> {
|
||||
impl<C: CommandRunner> Symbol for TlsCsr<'_, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.get_csr_path().exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ impl<'a, C: CommandRunner> TlsKey<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> fmt::Display for TlsKey<'a, C> {
|
||||
impl<C: CommandRunner> fmt::Display for TlsKey<'_, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "TlsKey {}", self.domain)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
|
||||
impl<C: CommandRunner> Symbol for TlsKey<'_, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.get_path().exists() {
|
||||
return Ok(false);
|
||||
|
|
@ -54,7 +54,7 @@ impl<'a, C: CommandRunner> Symbol for TlsKey<'a, C> {
|
|||
"-text".as_ref(),
|
||||
],
|
||||
)?;
|
||||
Ok(output.starts_with(&format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
Ok(output.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes()))
|
||||
}
|
||||
|
||||
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ impl<'a, D: AsRef<str>, C: CommandRunner> SelfSignedTlsCert<'a, D, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a, D, C> {
|
||||
impl<D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'_, D, C> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "SelfSignedTlsCert {}", self.domain.as_ref())
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ impl<'a, D: AsRef<str>, C: CommandRunner> fmt::Display for SelfSignedTlsCert<'a,
|
|||
|
||||
const DAYS_IN_SECONDS: u32 = 24 * 60 * 60;
|
||||
|
||||
impl<'a, D: AsRef<str>, C: CommandRunner> Symbol for SelfSignedTlsCert<'a, D, C> {
|
||||
impl<D: AsRef<str>, C: CommandRunner> Symbol for SelfSignedTlsCert<'_, D, C> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
if !self.get_cert_path().exists() {
|
||||
return Ok(false);
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ pub enum UserAdderError {
|
|||
impl Error for UserAdderError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
UserAdderError::AlreadyExists => "User already exists",
|
||||
UserAdderError::UnknownError => "Unknown error",
|
||||
UserAdderError::ImplError(_) => "User adding error",
|
||||
Self::AlreadyExists => "User already exists",
|
||||
Self::UnknownError => "Unknown error",
|
||||
Self::ImplError(_) => "User adding error",
|
||||
}
|
||||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
match self {
|
||||
UserAdderError::ImplError(ref e) => Some(e.as_ref()),
|
||||
Self::ImplError(ref e) => Some(e.as_ref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ impl Error for UserAdderError {
|
|||
|
||||
impl fmt::Display for UserAdderError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.cause() {
|
||||
match self.source() {
|
||||
Some(e) => write!(f, "{} (cause: {})", self.description(), e),
|
||||
None => write!(f, "{}", self.description()),
|
||||
}
|
||||
|
|
@ -50,10 +50,10 @@ pub enum UserError {
|
|||
impl Error for UserError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
UserError::GenericError => "Could not find out if user exists",
|
||||
Self::GenericError => "Could not find out if user exists",
|
||||
}
|
||||
}
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
match self {
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ impl Error for UserError {
|
|||
|
||||
impl fmt::Display for UserError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.cause() {
|
||||
match self.source() {
|
||||
Some(e) => write!(f, "{} (cause: {})", self.description(), e),
|
||||
None => write!(f, "{}", self.description()),
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ impl<'a, C: CommandRunner> SystemUserAdder<'a, C> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
|
||||
impl<C: CommandRunner> UserAdder for SystemUserAdder<'_, C> {
|
||||
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> {
|
||||
let output = self.command_runner.run_with_args(
|
||||
"adduser",
|
||||
|
|
@ -152,11 +152,7 @@ impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
|
|||
println!("{:?}", output);
|
||||
Err(UserAdderError::AlreadyExists)
|
||||
}
|
||||
Some(_) => {
|
||||
println!("{:?}", output);
|
||||
Err(UserAdderError::UnknownError)
|
||||
}
|
||||
None => {
|
||||
_ => {
|
||||
println!("{:?}", output);
|
||||
Err(UserAdderError::UnknownError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> WordpressPlugin<'a, P,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPlugin<'a, P, N, R> {
|
||||
impl<P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPlugin<'_, P, N, R> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let base_path = self.get_path();
|
||||
if !base_path.exists() {
|
||||
|
|
@ -119,8 +119,8 @@ impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> Symbol for WordpressPl
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> fmt::Display
|
||||
for WordpressPlugin<'a, P, N, R>
|
||||
impl<P: AsRef<Path>, N: AsRef<str>, R: CommandRunner> fmt::Display
|
||||
for WordpressPlugin<'_, P, N, R>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "WordpressPlugin {}", self.name.as_ref())
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl<'a, C: AsRef<str>, R: CommandRunner> WordpressTranslation<'a, C, PathBuf, R
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'a, C, D, R> {
|
||||
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'_, C, D, R> {
|
||||
fn get_pairs(&self) -> Vec<(String, PathBuf)> {
|
||||
let version_x = self
|
||||
.version
|
||||
|
|
@ -47,15 +47,13 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'
|
|||
locale.to_lowercase().replace('_', "-")
|
||||
};
|
||||
let mut res = vec![];
|
||||
for &(in_slug, out_slug) in [
|
||||
for &(in_slug, out_slug) in &[
|
||||
("", ""),
|
||||
("cc/", "continents-cities-"),
|
||||
("admin/", "admin-"),
|
||||
("admin/network/", "admin-network-"),
|
||||
]
|
||||
.iter()
|
||||
{
|
||||
for format in ["po", "mo"].iter() {
|
||||
] {
|
||||
for format in &["po", "mo"] {
|
||||
res.push((
|
||||
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format),
|
||||
[self.path.as_ref(), format!("{}{}.{}", out_slug, self.locale.as_ref(), format).as_ref()].iter().collect()
|
||||
|
|
@ -66,9 +64,7 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> WordpressTranslation<'
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol
|
||||
for WordpressTranslation<'a, C, D, R>
|
||||
{
|
||||
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol for WordpressTranslation<'_, C, D, R> {
|
||||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let mut newest = String::new();
|
||||
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
|
||||
|
|
@ -136,8 +132,8 @@ impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> Symbol
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> fmt::Display
|
||||
for WordpressTranslation<'a, C, D, R>
|
||||
impl<C: AsRef<str>, D: AsRef<Path>, R: CommandRunner> fmt::Display
|
||||
for WordpressTranslation<'_, C, D, R>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
write!(f, "WordpressTranslation {}", self.path.as_ref().display())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue