Compare commits

..

2 commits

Author SHA1 Message Date
b7c6a14571 Update dependencies 2020-10-19 14:29:10 +02:00
da98bfba8c Style 2020-10-19 14:29:02 +02:00
18 changed files with 39 additions and 21 deletions

View file

@ -6,11 +6,11 @@ edition = "2018"
build = "src/build.rs"
[dependencies]
users = "0.10.0"
users = "0.11.0"
regex = "1.0.1"
futures = "0.3"
async-trait = "0.1"
tokio = { version = "0.2", features = ["process", "io-util", "rt-core", "macros", "sync"] }
tokio = { version = "0.3", features = ["rt", "process", "io-util", "macros", "sync"] }
once_cell = "1.4"
[dev-dependencies]

View file

@ -6,11 +6,15 @@ use std::{
thread,
time::Duration,
};
use tokio::runtime::Builder;
pub use async_trait::async_trait;
pub fn run<F: Future>(future: F) -> F::Output {
tokio::runtime::Runtime::new().unwrap().block_on(future)
Builder::new_current_thread()
.build()
.unwrap()
.block_on(future)
}
pub use tokio::try_join;

View file

@ -719,9 +719,7 @@ impl<D: Clone> ImplementationBuilder<MariaDbDatabase<D>> for DefaultBuilder {
impl<D: Clone> ImplementationBuilder<PostgresqlDatabase<D>> for DefaultBuilder {
type Prerequisites = ();
fn prerequisites(_: &PostgresqlDatabase<D>) -> Self::Prerequisites {
()
}
fn prerequisites(_: &PostgresqlDatabase<D>) -> Self::Prerequisites {}
type Implementation = (PostgreSQLDatabaseSymbol<'static, String, String, StdCommandRunner>,);
fn create(

View file

@ -72,6 +72,7 @@ impl CommandRunner for StdCommandRunner {
.expect("Failed to write to stdin");
let res = child.wait_with_output().await;
//println!("{:?}", res);
#[allow(clippy::let_and_return)]
res
}
}

View file

@ -80,7 +80,7 @@ pub struct FilteringLogger<'a, L> {
}
impl<'a, L> FilteringLogger<'a, L> {
pub fn new(logger: &'a L, max_level: Level) -> Self {
pub const fn new(logger: &'a L, max_level: Level) -> Self {
Self { logger, max_level }
}
}
@ -104,6 +104,7 @@ pub struct StoringLogger {
}
impl StoringLogger {
#[must_use]
pub fn new() -> Self {
Self::default()
}

View file

@ -7,5 +7,6 @@ pub use symbol_runner::{
SymbolRunner,
};
mod runnable;
#[allow(clippy::module_inception)]
mod setup;
pub use setup::SetupFacade as Setup;

View file

@ -16,6 +16,7 @@ pub trait Runnable {
}
#[async_trait(?Send)]
#[allow(clippy::use_self)]
impl<S> Runnable for S
where
Self: Symbol + Debug,

View file

@ -242,7 +242,9 @@ mod test {
fn from_artifact(_from: ()) -> Self {
Self
}
#[allow(clippy::unused_unit)]
fn into_artifact(self) -> () {
#[allow(clippy::unused_unit)]
()
}
}

View file

@ -14,6 +14,7 @@ pub trait Storage {
pub struct SimpleStorage(PathBuf);
impl SimpleStorage {
#[must_use]
pub const fn new(base: PathBuf) -> Self {
Self(base)
}

View file

@ -11,7 +11,7 @@ pub struct Dir<P> {
}
impl<P> Dir<P> {
pub fn new(path: P) -> Self {
pub const fn new(path: P) -> Self {
Self { path }
}
}

View file

@ -12,7 +12,7 @@ pub struct File<D, C> {
}
impl<D, C> File<D, C> {
pub fn new(path: D, content: C) -> Self {
pub const fn new(path: D, content: C) -> Self {
Self { path, content }
}
}

View file

@ -13,7 +13,7 @@ pub struct GitSubmodules<'a, P, C> {
}
impl<'a, P, C> GitSubmodules<'a, P, C> {
pub fn new(target: P, command_runner: &'a C) -> Self {
pub const fn new(target: P, command_runner: &'a C) -> Self {
Self {
target,
command_runner,

View file

@ -34,8 +34,8 @@ impl<'a, N, C: CommandRunner, S> Dump<'a, N, C, S> {
impl<N: AsRef<str>, C: CommandRunner, S: Storage> Symbol for Dump<'_, N, C, S> {
async 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())).await?;
let modified_date = _modified_date.trim_end();
let output = self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name.as_ref())).await?;
let modified_date = output.trim_end();
Ok(modified_date != "NULL" && u64::from_str(modified_date)? <= dump_date)
}

View file

@ -11,7 +11,7 @@ pub struct UserSession<'a, U, C> {
}
impl<'a, U, C> UserSession<'a, U, C> {
pub fn new(user_name: U, command_runner: &'a C) -> Self {
pub const fn new(user_name: U, command_runner: &'a C) -> Self {
Self {
user_name,
command_runner,

View file

@ -14,7 +14,7 @@ pub struct Csr<C, D, K, P> {
}
impl<C, D, K, P> Csr<C, D, K, P> {
pub fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
pub const fn new(command_runner: C, domain: D, key_path: K, csr_path: P) -> Self {
Self {
command_runner,
domain,

View file

@ -8,19 +8,17 @@ use std::path::Path;
pub struct Key<C, P> {
file_path: P,
command_runner: C,
bytes: u32,
}
impl<C, P> Key<C, P> {
pub fn new(command_runner: C, file_path: P) -> Self {
pub const fn new(command_runner: C, file_path: P) -> Self {
Self {
file_path,
command_runner,
bytes: 4096,
}
}
fn get_bytes(&self) -> u32 {
4096
}
}
#[async_trait(?Send)]
@ -57,7 +55,7 @@ impl<C: CommandRunner, P: AsRef<Path>> Symbol for Key<C, P> {
"genrsa",
"-out",
self.file_path.as_ref(),
self.get_bytes().to_string(),
self.bytes.to_string(),
],
)
.await

View file

@ -15,7 +15,7 @@ pub struct User<U, C> {
}
impl<U, C> User<U, C> {
pub fn new(user_name: U, command_runner: C) -> Self {
pub const fn new(user_name: U, command_runner: C) -> Self {
Self {
user_name,
command_runner,

View file

@ -1,6 +1,7 @@
use std::fmt::Display;
use std::path::Path;
#[must_use]
pub fn default_server<P: AsRef<Path>>(challenges_snippet_path: P) -> String {
format!(
"server {{
@ -12,6 +13,7 @@ pub fn default_server<P: AsRef<Path>>(challenges_snippet_path: P) -> String {
)
}
#[must_use]
pub fn server_config<D: Display, C: AsRef<Path>, K: AsRef<Path>, T: Display, S: AsRef<Path>>(
domain: D,
cert_path: C,
@ -53,6 +55,7 @@ server {{
)
}
#[must_use]
pub fn php_snippet<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>(
index: &'static str,
socket_path: SOCKET,
@ -71,6 +74,7 @@ pub fn php_snippet<SOCKET: AsRef<Path>, STATIC: AsRef<Path>>(
)
}
#[must_use]
pub fn redir_snippet(target: &str) -> String {
format!(
"location / {{
@ -85,6 +89,7 @@ pub trait SocketSpec {
}
impl<T: AsRef<Path>> SocketSpec for T {
#[must_use]
fn to_nginx(&self) -> String {
format!("unix:{}:", self.as_ref().to_str().unwrap())
}
@ -94,17 +99,20 @@ impl<T: AsRef<Path>> SocketSpec for T {
pub struct LocalTcpSocket(usize);
impl LocalTcpSocket {
#[must_use]
pub const fn new(x: usize) -> Self {
Self(x)
}
}
impl SocketSpec for LocalTcpSocket {
#[must_use]
fn to_nginx(&self) -> String {
format!("localhost:{}", self.0)
}
}
#[must_use]
pub fn proxy_snippet<S: SocketSpec, STATIC: AsRef<Path>>(
socket_path: &S,
static_path: STATIC,
@ -125,6 +133,7 @@ pub fn proxy_snippet<S: SocketSpec, STATIC: AsRef<Path>>(
)
}
#[must_use]
pub fn static_snippet<S: AsRef<Path>>(static_path: S) -> String {
format!(
"root {};
@ -134,6 +143,7 @@ pub fn static_snippet<S: AsRef<Path>>(static_path: S) -> String {
)
}
#[must_use]
pub fn dokuwiki_snippet() -> String {
"
location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; }
@ -149,6 +159,7 @@ pub fn dokuwiki_snippet() -> String {
}".into()
}
#[must_use]
pub fn nextcloud_snippet() -> String {
"
client_max_body_size 500M;