Issues from clippy
This commit is contained in:
parent
b608496aaa
commit
d9676a4ce7
@ -32,10 +32,10 @@
|
|||||||
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
||||||
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
|
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
|
||||||
};
|
};
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
devShell = pkgs.mkShell {
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
toolchain
|
toolchain
|
||||||
pkgs.glibc.static
|
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
source $(pwd)/.env.dev
|
source $(pwd)/.env.dev
|
||||||
|
@ -99,7 +99,7 @@ impl DNSChecker {
|
|||||||
{
|
{
|
||||||
let domain = Name::from_str("_domiply_challenge")
|
let domain = Name::from_str("_domiply_challenge")
|
||||||
.map_err(|e| CheckDomainError::Unexpected(Box::from(e)))?
|
.map_err(|e| CheckDomainError::Unexpected(Box::from(e)))?
|
||||||
.append_domain(&domain)
|
.append_domain(domain)
|
||||||
.map_err(|e| CheckDomainError::Unexpected(Box::from(e)))?;
|
.map_err(|e| CheckDomainError::Unexpected(Box::from(e)))?;
|
||||||
|
|
||||||
let response = match self
|
let response = match self
|
||||||
|
@ -73,7 +73,7 @@ impl Store for FSStore {
|
|||||||
_ => GetError::Unexpected(Box::from(e)),
|
_ => 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> {
|
fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError> {
|
||||||
|
@ -195,7 +195,7 @@ where
|
|||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let config_hash = config
|
let config_hash = config
|
||||||
.hash()
|
.hash()
|
||||||
.map_err(|e| SyncWithConfigError::Unexpected(Box::from(e)))?;
|
.map_err(|e| SyncWithConfigError::Unexpected(e))?;
|
||||||
|
|
||||||
self.domain_checker
|
self.domain_checker
|
||||||
.check_domain(&domain, &config_hash)
|
.check_domain(&domain, &config_hash)
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -1,6 +1,5 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use signal_hook::consts::signal;
|
|
||||||
use signal_hook_tokio::Signals;
|
use signal_hook_tokio::Signals;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
@ -54,15 +53,15 @@ fn main() {
|
|||||||
{
|
{
|
||||||
let canceller = canceller.clone();
|
let canceller = canceller.clone();
|
||||||
tokio_runtime.spawn(async move {
|
tokio_runtime.spawn(async move {
|
||||||
let mut signals = Signals::new(&[signal::SIGTERM, signal::SIGINT, signal::SIGQUIT])
|
let mut signals =
|
||||||
.expect("initialized 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...");
|
println!("Gracefully shutting down...");
|
||||||
canceller.cancel();
|
canceller.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = signals.next().await {
|
if (signals.next().await).is_some() {
|
||||||
println!("Forcefully shutting down");
|
println!("Forcefully shutting down");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
};
|
};
|
||||||
@ -149,7 +148,6 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let server_handler = {
|
let server_handler = {
|
||||||
let canceller = canceller.clone();
|
|
||||||
tokio_runtime.spawn(async move {
|
tokio_runtime.spawn(async move {
|
||||||
let addr = config.http_listen_addr;
|
let addr = config.http_listen_addr;
|
||||||
|
|
||||||
|
@ -111,11 +111,11 @@ impl Store {
|
|||||||
.map_err(|e| GetOriginError::Unexpected(Box::from(e)))?
|
.map_err(|e| GetOriginError::Unexpected(Box::from(e)))?
|
||||||
.tree();
|
.tree();
|
||||||
|
|
||||||
return Ok(sync::Arc::from(Origin {
|
Ok(sync::Arc::from(Origin {
|
||||||
descr,
|
descr,
|
||||||
repo: repo.into(),
|
repo: repo.into(),
|
||||||
tree_object_id,
|
tree_object_id,
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_inner(
|
fn sync_inner(
|
||||||
@ -127,7 +127,7 @@ impl Store {
|
|||||||
use gix::progress::Discard;
|
use gix::progress::Discard;
|
||||||
|
|
||||||
let should_interrupt = &core::sync::atomic::AtomicBool::new(false);
|
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
|
// if the path doesn't exist then use the gix clone feature to clone it into the
|
||||||
// directory.
|
// directory.
|
||||||
|
@ -23,7 +23,7 @@ pub struct Service<'svc> {
|
|||||||
handlebars: handlebars::Handlebars<'svc>,
|
handlebars: handlebars::Handlebars<'svc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'svc, 'mgr>(
|
pub fn new<'svc>(
|
||||||
domain_manager: sync::Arc<dyn domain::manager::Manager>,
|
domain_manager: sync::Arc<dyn domain::manager::Manager>,
|
||||||
target_a: net::Ipv4Addr,
|
target_a: net::Ipv4Addr,
|
||||||
passphrase: String,
|
passphrase: String,
|
||||||
@ -34,7 +34,7 @@ pub fn new<'svc, 'mgr>(
|
|||||||
target_a,
|
target_a,
|
||||||
passphrase,
|
passphrase,
|
||||||
http_domain,
|
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(
|
self.render(
|
||||||
status_code,
|
status_code,
|
||||||
"/base.html",
|
"/base.html",
|
||||||
&BasePresenter {
|
BasePresenter {
|
||||||
page_name: "/error.html",
|
page_name: "/error.html",
|
||||||
data: &Response { error_msg: e },
|
data: &Response { error_msg: e },
|
||||||
},
|
},
|
||||||
@ -128,7 +128,7 @@ impl<'svc> Service<'svc> {
|
|||||||
fn serve_origin(&self, domain: domain::Name, path: &'_ str) -> SvcResponse {
|
fn serve_origin(&self, domain: domain::Name, path: &'_ str) -> SvcResponse {
|
||||||
let mut path_owned;
|
let mut path_owned;
|
||||||
|
|
||||||
let path = match path.ends_with("/") {
|
let path = match path.ends_with('/') {
|
||||||
true => {
|
true => {
|
||||||
path_owned = String::from(path);
|
path_owned = String::from(path);
|
||||||
path_owned.push_str("index.html");
|
path_owned.push_str("index.html");
|
||||||
@ -148,8 +148,8 @@ impl<'svc> Service<'svc> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
match origin.read_file_into(&path, &mut buf) {
|
match origin.read_file_into(path, &mut buf) {
|
||||||
Ok(_) => self.serve_string(200, &path, buf),
|
Ok(_) => self.serve_string(200, path, buf),
|
||||||
Err(origin::ReadFileIntoError::FileNotFound) => {
|
Err(origin::ReadFileIntoError::FileNotFound) => {
|
||||||
self.render_error_page(404, "File not found")
|
self.render_error_page(404, "File not found")
|
||||||
}
|
}
|
||||||
@ -190,9 +190,9 @@ impl<'svc> Service<'svc> {
|
|||||||
|
|
||||||
self.render_page(
|
self.render_page(
|
||||||
"/domain.html",
|
"/domain.html",
|
||||||
&Response {
|
Response {
|
||||||
domain: args.domain,
|
domain: args.domain,
|
||||||
config: config,
|
config,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -222,15 +222,15 @@ impl<'svc> Service<'svc> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return self.render_page(
|
self.render_page(
|
||||||
"/domain_init.html",
|
"/domain_init.html",
|
||||||
&Response {
|
Response {
|
||||||
domain: args.domain,
|
domain: args.domain,
|
||||||
flat_config: config.into(),
|
flat_config: config.into(),
|
||||||
target_a: self.target_a,
|
target_a: self.target_a,
|
||||||
challenge_token: config_hash,
|
challenge_token: config_hash,
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn domain_sync(
|
async fn domain_sync(
|
||||||
@ -276,12 +276,12 @@ impl<'svc> Service<'svc> {
|
|||||||
error_msg,
|
error_msg,
|
||||||
};
|
};
|
||||||
|
|
||||||
return self.render_page("/domain_sync.html", response);
|
self.render_page("/domain_sync.html", response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_request<'svc>(
|
pub async fn handle_request(
|
||||||
svc: sync::Arc<Service<'svc>>,
|
svc: sync::Arc<Service<'_>>,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> Result<Response<Body>, Infallible> {
|
) -> Result<Response<Body>, Infallible> {
|
||||||
match handle_request_inner(svc, req).await {
|
match handle_request_inner(svc, req).await {
|
||||||
@ -291,16 +291,13 @@ pub async fn handle_request<'svc>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn strip_port(host: &str) -> &str {
|
fn strip_port(host: &str) -> &str {
|
||||||
match host.rfind(":") {
|
match host.rfind(':') {
|
||||||
None => host,
|
None => host,
|
||||||
Some(i) => &host[..i],
|
Some(i) => &host[..i],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_request_inner<'svc>(
|
pub async fn handle_request_inner(svc: sync::Arc<Service<'_>>, req: Request<Body>) -> SvcResponse {
|
||||||
svc: sync::Arc<Service<'svc>>,
|
|
||||||
req: Request<Body>,
|
|
||||||
) -> SvcResponse {
|
|
||||||
let maybe_host = match (
|
let maybe_host = match (
|
||||||
req.headers()
|
req.headers()
|
||||||
.get("Host")
|
.get("Host")
|
||||||
@ -321,7 +318,7 @@ pub async fn handle_request_inner<'svc>(
|
|||||||
let method = req.method();
|
let method = req.method();
|
||||||
let path = req.uri().path();
|
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, ());
|
return svc.render(200, path, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
use handlebars::{Handlebars, TemplateError};
|
use handlebars::Handlebars;
|
||||||
|
|
||||||
#[derive(rust_embed::RustEmbed)]
|
#[derive(rust_embed::RustEmbed)]
|
||||||
#[folder = "src/service/http_tpl"]
|
#[folder = "src/service/http_tpl"]
|
||||||
#[prefix = "/"]
|
#[prefix = "/"]
|
||||||
struct Dir;
|
struct Dir;
|
||||||
|
|
||||||
pub fn get<'hbs>() -> Result<Handlebars<'hbs>, TemplateError> {
|
pub fn get<'hbs>() -> Handlebars<'hbs> {
|
||||||
let mut reg = Handlebars::new();
|
let mut reg = Handlebars::new();
|
||||||
reg.register_embed_templates::<Dir>()?;
|
reg.register_embed_templates::<Dir>()
|
||||||
Ok(reg)
|
.expect("registered embedded templates");
|
||||||
|
reg
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user