aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock26
-rw-r--r--Cargo.toml10
-rw-r--r--lib/warden-core/Cargo.toml21
-rw-r--r--lib/warden-core/src/config/cli/database.rs (renamed from warden/src/config/cli/database.rs)4
-rw-r--r--lib/warden-core/src/config/cli/mod.rs (renamed from warden/src/config/cli/mod.rs)0
-rw-r--r--lib/warden-core/src/config/log_level.rs (renamed from warden/src/config/log_level.rs)0
-rw-r--r--lib/warden-core/src/config/mod.rs (renamed from warden/src/config/mod.rs)19
-rw-r--r--lib/warden-core/src/error.rs15
-rw-r--r--lib/warden-core/src/lib.rs3
-rw-r--r--warden/Cargo.toml6
-rw-r--r--warden/src/main.rs2
11 files changed, 78 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 595583f..7b78797 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -103,17 +103,6 @@ dependencies = [
]
[[package]]
-name = "async-trait"
-version = "0.1.89"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "atoi"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3052,7 +3041,6 @@ name = "warden"
version = "0.1.0"
dependencies = [
"anyhow",
- "async-trait",
"axum",
"clap",
"jsonschema",
@@ -3075,6 +3063,20 @@ dependencies = [
"utoipa-scalar",
"utoipa-swagger-ui",
"uuid",
+ "warden-core",
+]
+
+[[package]]
+name = "warden-core"
+version = "0.1.0"
+dependencies = [
+ "clap",
+ "serde",
+ "sqlx",
+ "thiserror 2.0.18",
+ "tracing",
+ "tracing-subscriber",
+ "url",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 5446260..2bdad55 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,20 +1,28 @@
[workspace]
resolver = "3"
-members = ["warden"]
+members = ["warden", "lib/*"]
[workspace.package]
license = "AGPL-3.0-only"
readme = "README.md"
documentation = "https://books.kanjala.com/warden"
homepage = "https://git.kanjala.com/warden"
+publish = false
[workspace.dependencies]
+async-trait = "0.1.89"
+clap = "4.6.0"
+jsonschema = "0.45.0"
+secrecy = { version = "0.10.3", features = ["serde"] }
serde = "1.0.228"
serde_json = "1.0.149"
+thiserror = "2.0.18"
time = { version = "0.3.47", default-features = false }
tracing = "0.1.44"
+tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
url = "2.5.8"
uuid = "1.23.0"
+warden-core = { path = "lib/warden-core" }
[workspace.dependencies.sqlx]
version = "0.8.6"
diff --git a/lib/warden-core/Cargo.toml b/lib/warden-core/Cargo.toml
new file mode 100644
index 0000000..1f92e87
--- /dev/null
+++ b/lib/warden-core/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "warden-core"
+version = "0.1.0"
+edition = "2024"
+license.workspace = true
+readme.workspace = true
+documentation.workspace = true
+homepage.workspace = true
+publish.workspace = true
+
+[dependencies]
+clap = { workspace = true, features = ["derive", "env"] }
+serde = { workspace = true, features = ["derive"] }
+thiserror.workspace = true
+tracing.workspace = true
+tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
+url.workspace = true
+
+[dependencies.sqlx]
+workspace = true
+features = ["json", "runtime-tokio-rustls", "time"]
diff --git a/warden/src/config/cli/database.rs b/lib/warden-core/src/config/cli/database.rs
index 34da09e..31ba930 100644
--- a/warden/src/config/cli/database.rs
+++ b/lib/warden-core/src/config/cli/database.rs
@@ -2,6 +2,8 @@ use clap::Parser;
use serde::{Deserialize, Serialize};
use url::Url;
+use crate::WardenError;
+
#[derive(Parser, Clone, Deserialize, Serialize, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Database {
@@ -55,7 +57,7 @@ impl Default for Database {
}
impl Database {
- pub fn merge(cli: &Self, file: &Self) -> anyhow::Result<Self> {
+ pub fn merge(cli: &Self, file: &Self) -> Result<Self, WardenError> {
let url = cli.database_url.clone().or(file.database_url.clone());
let pool_size = cli
diff --git a/warden/src/config/cli/mod.rs b/lib/warden-core/src/config/cli/mod.rs
index 36f6bf0..36f6bf0 100644
--- a/warden/src/config/cli/mod.rs
+++ b/lib/warden-core/src/config/cli/mod.rs
diff --git a/warden/src/config/log_level.rs b/lib/warden-core/src/config/log_level.rs
index 3edfbc3..3edfbc3 100644
--- a/warden/src/config/log_level.rs
+++ b/lib/warden-core/src/config/log_level.rs
diff --git a/warden/src/config/mod.rs b/lib/warden-core/src/config/mod.rs
index 742f50d..9d0c937 100644
--- a/warden/src/config/mod.rs
+++ b/lib/warden-core/src/config/mod.rs
@@ -9,6 +9,7 @@ pub use cli::Commands;
use serde::Deserialize;
use tracing_subscriber::EnvFilter;
+use crate::WardenError;
use crate::config::cli::CliEnvironment;
use crate::config::cli::database::Database;
@@ -45,7 +46,7 @@ pub struct Server {
}
impl Server {
- fn merge(cli: &Cli, file: &Cli, missing: &mut Vec<&str>) -> anyhow::Result<Self> {
+ fn merge(cli: &Cli, file: &Cli, missing: &mut Vec<&str>) -> Result<Self, WardenError> {
let port = cli.server.port.or(file.server.port);
if port.is_none() {
@@ -82,14 +83,12 @@ impl Server {
}
if !missing.is_empty() {
- anyhow::bail!(
- "Missing required configuration values:\n{}",
- missing
- .iter()
- .map(|f| format!(" - {}", f))
- .collect::<Vec<_>>()
- .join("\n")
- );
+ let err = missing
+ .iter()
+ .map(|f| format!(" - {}", f))
+ .collect::<Vec<_>>()
+ .join("\n");
+ return Err(WardenError::Config(err));
}
let log_level =
@@ -110,7 +109,7 @@ impl Server {
}
impl Configuration {
- pub fn merge(cli: &Cli, file: &Cli) -> anyhow::Result<Self> {
+ pub fn merge(cli: &Cli, file: &Cli) -> Result<Self, WardenError> {
let mut missing = Vec::new();
let server = Server::merge(cli, file, &mut missing)?;
diff --git a/lib/warden-core/src/error.rs b/lib/warden-core/src/error.rs
new file mode 100644
index 0000000..f05971f
--- /dev/null
+++ b/lib/warden-core/src/error.rs
@@ -0,0 +1,15 @@
+use thiserror::Error;
+
+#[derive(Error, Debug)]
+pub enum WardenError {
+ #[error(transparent)]
+ Datastore(#[from] sqlx::Error),
+ #[error(transparent)]
+ Url(#[from] url::ParseError),
+ #[error("Missing required configuration values:\n`{0}`")]
+ Config(String),
+ #[error("invalid header (expected {expected:?}, found {found:?})")]
+ InvalidHeader { expected: String, found: String },
+ #[error("unknown data store error")]
+ Unknown,
+}
diff --git a/lib/warden-core/src/lib.rs b/lib/warden-core/src/lib.rs
new file mode 100644
index 0000000..f200ba1
--- /dev/null
+++ b/lib/warden-core/src/lib.rs
@@ -0,0 +1,3 @@
+mod error;
+pub use error::WardenError;
+pub mod config;
diff --git a/warden/Cargo.toml b/warden/Cargo.toml
index d2b7b49..b3c3ef1 100644
--- a/warden/Cargo.toml
+++ b/warden/Cargo.toml
@@ -8,10 +8,9 @@ homepage.workspace = true
[dependencies]
anyhow = "1.0.102"
-async-trait = "0.1.89"
axum = { version = "0.8.8", features = ["macros"] }
-clap = { version = "4.6.0", features = ["derive", "env"] }
-jsonschema = "0.45.0"
+clap.workspace = true
+jsonschema.workspace = true
secrecy = { version = "0.10.3", features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
@@ -29,6 +28,7 @@ utoipa-redoc = { version = "6.0.0", optional = true }
utoipa-scalar = { version = "0.3.0", optional = true }
utoipa-swagger-ui = { version = "9.0.2", optional = true }
uuid = { workspace = true, features = ["v7"] }
+warden-core.workspace = true
[dependencies.sqlx]
workspace = true
diff --git a/warden/src/main.rs b/warden/src/main.rs
index 7924a7e..ab37e41 100644
--- a/warden/src/main.rs
+++ b/warden/src/main.rs
@@ -8,13 +8,13 @@ use tokio::net::TcpListener;
use anyhow::Context as _;
use clap::Parser as _;
use tracing::info;
+use warden_core::config;
use crate::{
config::{Commands, Configuration},
state::AppState,
};
-mod config;
mod logging;
mod server;
mod state;