From d9676a4ce7ed40d29bb83f0bc2eb299feb4f30d0 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Tue, 16 May 2023 16:20:01 +0200 Subject: [PATCH] Issues from clippy --- flake.nix | 2 +- src/domain/checker.rs | 2 +- src/domain/config.rs | 2 +- src/domain/manager.rs | 2 +- src/main.rs | 10 ++++------ src/origin/store/git.rs | 6 +++--- src/service.rs | 37 +++++++++++++++++-------------------- src/service/http_tpl.rs | 9 +++++---- 8 files changed, 33 insertions(+), 37 deletions(-) diff --git a/flake.nix b/flake.nix index 32a8b45..f969c62 100644 --- a/flake.nix +++ b/flake.nix @@ -32,10 +32,10 @@ CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; }; + devShell = pkgs.mkShell { nativeBuildInputs = [ toolchain - pkgs.glibc.static ]; shellHook = '' source $(pwd)/.env.dev diff --git a/src/domain/checker.rs b/src/domain/checker.rs index 91b0b4b..971adfd 100644 --- a/src/domain/checker.rs +++ b/src/domain/checker.rs @@ -99,7 +99,7 @@ impl DNSChecker { { let domain = Name::from_str("_domiply_challenge") .map_err(|e| CheckDomainError::Unexpected(Box::from(e)))? - .append_domain(&domain) + .append_domain(domain) .map_err(|e| CheckDomainError::Unexpected(Box::from(e)))?; let response = match self diff --git a/src/domain/config.rs b/src/domain/config.rs index 445722c..141947d 100644 --- a/src/domain/config.rs +++ b/src/domain/config.rs @@ -73,7 +73,7 @@ impl Store for FSStore { _ => GetError::Unexpected(Box::from(e)), })?; - Ok(serde_json::from_reader(config_file).map_err(|e| GetError::Unexpected(Box::from(e)))?) + serde_json::from_reader(config_file).map_err(|e| GetError::Unexpected(Box::from(e))) } fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError> { diff --git a/src/domain/manager.rs b/src/domain/manager.rs index 87c7492..80d84d9 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -195,7 +195,7 @@ where Box::pin(async move { let config_hash = config .hash() - .map_err(|e| SyncWithConfigError::Unexpected(Box::from(e)))?; + .map_err(|e| SyncWithConfigError::Unexpected(e))?; self.domain_checker .check_domain(&domain, &config_hash) diff --git a/src/main.rs b/src/main.rs index c209fc5..0c512d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ use clap::Parser; use futures::stream::StreamExt; -use signal_hook::consts::signal; use signal_hook_tokio::Signals; use tokio::select; use tokio::time; @@ -54,15 +53,15 @@ fn main() { { let canceller = canceller.clone(); tokio_runtime.spawn(async move { - let mut signals = Signals::new(&[signal::SIGTERM, signal::SIGINT, signal::SIGQUIT]) - .expect("initialized signals"); + let mut signals = + Signals::new(signal_hook::consts::TERM_SIGNALS).expect("initialized signals"); - if let Some(_) = signals.next().await { + if (signals.next().await).is_some() { println!("Gracefully shutting down..."); canceller.cancel(); } - if let Some(_) = signals.next().await { + if (signals.next().await).is_some() { println!("Forcefully shutting down"); std::process::exit(1); }; @@ -149,7 +148,6 @@ fn main() { }); let server_handler = { - let canceller = canceller.clone(); tokio_runtime.spawn(async move { let addr = config.http_listen_addr; diff --git a/src/origin/store/git.rs b/src/origin/store/git.rs index 75a161c..f6d1ccb 100644 --- a/src/origin/store/git.rs +++ b/src/origin/store/git.rs @@ -111,11 +111,11 @@ impl Store { .map_err(|e| GetOriginError::Unexpected(Box::from(e)))? .tree(); - return Ok(sync::Arc::from(Origin { + Ok(sync::Arc::from(Origin { descr, repo: repo.into(), tree_object_id, - })); + })) } fn sync_inner( @@ -127,7 +127,7 @@ impl Store { use gix::progress::Discard; let should_interrupt = &core::sync::atomic::AtomicBool::new(false); - let repo_path = &self.repo_path(&descr); + let repo_path = &self.repo_path(descr); // if the path doesn't exist then use the gix clone feature to clone it into the // directory. diff --git a/src/service.rs b/src/service.rs index afd2f94..56f8915 100644 --- a/src/service.rs +++ b/src/service.rs @@ -23,7 +23,7 @@ pub struct Service<'svc> { handlebars: handlebars::Handlebars<'svc>, } -pub fn new<'svc, 'mgr>( +pub fn new<'svc>( domain_manager: sync::Arc, target_a: net::Ipv4Addr, passphrase: String, @@ -34,7 +34,7 @@ pub fn new<'svc, 'mgr>( target_a, passphrase, http_domain, - handlebars: self::http_tpl::get().expect("Retrieved Handlebars templates"), + handlebars: self::http_tpl::get(), } } @@ -104,7 +104,7 @@ impl<'svc> Service<'svc> { self.render( status_code, "/base.html", - &BasePresenter { + BasePresenter { page_name: "/error.html", data: &Response { error_msg: e }, }, @@ -128,7 +128,7 @@ impl<'svc> Service<'svc> { fn serve_origin(&self, domain: domain::Name, path: &'_ str) -> SvcResponse { let mut path_owned; - let path = match path.ends_with("/") { + let path = match path.ends_with('/') { true => { path_owned = String::from(path); path_owned.push_str("index.html"); @@ -148,8 +148,8 @@ impl<'svc> Service<'svc> { }; let mut buf = Vec::::new(); - match origin.read_file_into(&path, &mut buf) { - Ok(_) => self.serve_string(200, &path, buf), + match origin.read_file_into(path, &mut buf) { + Ok(_) => self.serve_string(200, path, buf), Err(origin::ReadFileIntoError::FileNotFound) => { self.render_error_page(404, "File not found") } @@ -190,9 +190,9 @@ impl<'svc> Service<'svc> { self.render_page( "/domain.html", - &Response { + Response { domain: args.domain, - config: config, + config, }, ) } @@ -222,15 +222,15 @@ impl<'svc> Service<'svc> { } }; - return self.render_page( + self.render_page( "/domain_init.html", - &Response { + Response { domain: args.domain, flat_config: config.into(), target_a: self.target_a, challenge_token: config_hash, }, - ); + ) } async fn domain_sync( @@ -276,12 +276,12 @@ impl<'svc> Service<'svc> { error_msg, }; - return self.render_page("/domain_sync.html", response); + self.render_page("/domain_sync.html", response) } } -pub async fn handle_request<'svc>( - svc: sync::Arc>, +pub async fn handle_request( + svc: sync::Arc>, req: Request, ) -> Result, Infallible> { match handle_request_inner(svc, req).await { @@ -291,16 +291,13 @@ pub async fn handle_request<'svc>( } fn strip_port(host: &str) -> &str { - match host.rfind(":") { + match host.rfind(':') { None => host, Some(i) => &host[..i], } } -pub async fn handle_request_inner<'svc>( - svc: sync::Arc>, - req: Request, -) -> SvcResponse { +pub async fn handle_request_inner(svc: sync::Arc>, req: Request) -> SvcResponse { let maybe_host = match ( req.headers() .get("Host") @@ -321,7 +318,7 @@ pub async fn handle_request_inner<'svc>( let method = req.method(); let path = req.uri().path(); - if method == &Method::GET && path.starts_with("/static/") { + if method == Method::GET && path.starts_with("/static/") { return svc.render(200, path, ()); } diff --git a/src/service/http_tpl.rs b/src/service/http_tpl.rs index d403d8e..a9d3ffd 100644 --- a/src/service/http_tpl.rs +++ b/src/service/http_tpl.rs @@ -1,12 +1,13 @@ -use handlebars::{Handlebars, TemplateError}; +use handlebars::Handlebars; #[derive(rust_embed::RustEmbed)] #[folder = "src/service/http_tpl"] #[prefix = "/"] struct Dir; -pub fn get<'hbs>() -> Result, TemplateError> { +pub fn get<'hbs>() -> Handlebars<'hbs> { let mut reg = Handlebars::new(); - reg.register_embed_templates::()?; - Ok(reg) + reg.register_embed_templates::() + .expect("registered embedded templates"); + reg }