Issues from clippy

main
Brian Picciano 1 year ago
parent b608496aaa
commit d9676a4ce7
  1. 2
      flake.nix
  2. 2
      src/domain/checker.rs
  3. 2
      src/domain/config.rs
  4. 2
      src/domain/manager.rs
  5. 10
      src/main.rs
  6. 6
      src/origin/store/git.rs
  7. 37
      src/service.rs
  8. 9
      src/service/http_tpl.rs

@ -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

@ -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

@ -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> {

@ -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)

@ -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;

@ -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.

@ -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<dyn domain::manager::Manager>,
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::<u8>::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<Service<'svc>>,
pub async fn handle_request(
svc: sync::Arc<Service<'_>>,
req: Request<Body>,
) -> Result<Response<Body>, 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<Service<'svc>>,
req: Request<Body>,
) -> SvcResponse {
pub async fn handle_request_inner(svc: sync::Arc<Service<'_>>, req: Request<Body>) -> 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, ());
}

@ -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<Handlebars<'hbs>, TemplateError> {
pub fn get<'hbs>() -> Handlebars<'hbs> {
let mut reg = Handlebars::new();
reg.register_embed_templates::<Dir>()?;
Ok(reg)
reg.register_embed_templates::<Dir>()
.expect("registered embedded templates");
reg
}

Loading…
Cancel
Save