Reorganize workspace layout and split out blahd

This commit is contained in:
oxalica 2024-08-30 19:16:44 -04:00
parent 370722731b
commit 668b873b07
10 changed files with 89 additions and 66 deletions

49
Cargo.lock generated
View file

@ -224,28 +224,16 @@ name = "blah"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"axum",
"bitflags", "bitflags",
"bitflags_serde_shim", "bitflags_serde_shim",
"clap",
"ed25519-dalek", "ed25519-dalek",
"futures-util",
"hex", "hex",
"html-escape", "html-escape",
"humantime",
"rand_core", "rand_core",
"rusqlite", "rusqlite",
"sd-notify",
"serde", "serde",
"serde-aux",
"serde-constant",
"serde_json", "serde_json",
"syn", "syn",
"tokio",
"tokio-stream",
"tower-http",
"tracing",
"tracing-subscriber",
"uuid", "uuid",
] ]
@ -254,7 +242,6 @@ name = "blahctl"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bitflags",
"blah", "blah",
"clap", "clap",
"ed25519-dalek", "ed25519-dalek",
@ -263,6 +250,30 @@ dependencies = [
"reqwest", "reqwest",
"rusqlite", "rusqlite",
"tokio", "tokio",
]
[[package]]
name = "blahd"
version = "0.0.0"
dependencies = [
"anyhow",
"axum",
"blah",
"clap",
"ed25519-dalek",
"futures-util",
"hex",
"humantime",
"rusqlite",
"sd-notify",
"serde",
"serde-aux",
"serde_json",
"tokio",
"tokio-stream",
"tower-http",
"tracing",
"tracing-subscriber",
"uuid", "uuid",
] ]
@ -462,7 +473,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
dependencies = [ dependencies = [
"pkcs8", "pkcs8",
"serde",
"signature", "signature",
] ]
@ -477,7 +487,6 @@ dependencies = [
"rand_core", "rand_core",
"serde", "serde",
"sha2", "sha2",
"signature",
"subtle", "subtle",
"zeroize", "zeroize",
] ]
@ -1414,15 +1423,6 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "serde-constant"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301d0de95fe56444b1ea1ee62363452b756fe715fb4eab505be16b906599b47e"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.209" version = "1.0.209"
@ -1500,7 +1500,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [ dependencies = [
"digest",
"rand_core", "rand_core",
] ]

View file

@ -1,36 +1,29 @@
[workspace]
resolver = "2"
members = [
".",
"blahctl",
"blahd",
]
default-members = ["blahd"]
[package] [package]
name = "blah" name = "blah"
version = "0.0.0" version = "0.0.0"
edition = "2021" edition = "2021"
# TODO: Shrink dependencies.
[dependencies] [dependencies]
anyhow = "1.0.86" anyhow = "1"
axum = { version = "0.7.5", features = ["tokio"] } bitflags = "2"
bitflags = "2.6.0" bitflags_serde_shim = "0.2"
bitflags_serde_shim = "0.2.5" ed25519-dalek = "2.1"
clap = { version = "4.5.16", features = ["derive"] } hex = { version = "0.4", features = ["serde"] }
ed25519-dalek = { version = "2.1.1", features = ["digest", "serde"] } html-escape = "0.2"
futures-util = "0.3.30" rand_core = "0.6"
hex = { version = "0.4.3", features = ["serde"] } rusqlite = { version = "0.32", optional = true }
html-escape = "0.2.13" serde = { version = "1", features = ["derive"] }
humantime = "2.1.0" serde_json = "1"
rand_core = "0.6.4" uuid = { version = "1", features = ["serde"] }
rusqlite = { version = "0.32.1", features = ["uuid"] }
sd-notify = "0.4.2"
serde = { version = "1.0.209", features = ["derive"] }
serde-aux = "4.5.0"
serde-constant = "0.1.0"
serde_json = "1.0.127"
tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread", "sync"] }
tokio-stream = { version = "0.1.15", features = ["sync"] }
tower-http = { version = "0.5.2", features = ["cors", "limit"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
uuid = { version = "1.10.0", features = ["serde", "v4"] }
[dev-dependencies] [dev-dependencies]
syn = { version = "2.0.76", features = ["full", "visit"] } syn = { version = "2.0.76", features = ["full", "visit"] }
[workspace]
members = [ "./blahctl" ]

View file

@ -4,14 +4,13 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.86" anyhow = "1"
bitflags = "2.6.0" clap = { version = "4", features = ["derive"] }
blah.path = ".." ed25519-dalek = { version = "2", features = ["pkcs8", "pem", "rand_core"] }
clap = { version = "4.5.16", features = ["derive"] }
ed25519-dalek = { version = "2.1.1", features = ["pkcs8", "pem", "rand_core"] }
hex = "0.4" hex = "0.4"
rand = "0.8.5" rand = "0.8"
reqwest = { version = "0.12.7", features = ["json"] } reqwest = { version = "0.12", features = ["json"] }
rusqlite = "0.32.1" rusqlite = "0.32"
tokio = { version = "1.39.3", features = ["rt", "macros"] } tokio = { version = "1", features = ["rt", "macros"] }
uuid = "1.10.0"
blah = { path = "..", features = ["rusqlite"] }

View file

@ -3,11 +3,12 @@ use std::path::{Path, PathBuf};
use std::{fs, io}; use std::{fs, io};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use bitflags::Flags; use blah::bitflags;
use blah::types::{ use blah::types::{
ChatPayload, CreateRoomPayload, MemberPermission, RichText, RoomAttrs, RoomMember, ChatPayload, CreateRoomPayload, MemberPermission, RichText, RoomAttrs, RoomMember,
RoomMemberList, ServerPermission, UserKey, WithSig, RoomMemberList, ServerPermission, UserKey, WithSig,
}; };
use blah::uuid::Uuid;
use ed25519_dalek::pkcs8::spki::der::pem::LineEnding; use ed25519_dalek::pkcs8::spki::der::pem::LineEnding;
use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey, EncodePublicKey}; use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey, EncodePrivateKey, EncodePublicKey};
use ed25519_dalek::{SigningKey, VerifyingKey, PUBLIC_KEY_LENGTH}; use ed25519_dalek::{SigningKey, VerifyingKey, PUBLIC_KEY_LENGTH};
@ -15,7 +16,6 @@ use rand::rngs::OsRng;
use reqwest::Url; use reqwest::Url;
use rusqlite::{named_params, Connection}; use rusqlite::{named_params, Connection};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use uuid::Uuid;
/// NB. Sync with docs of [`User::url`]. /// NB. Sync with docs of [`User::url`].
const KEY_URL_SUBPATH: &str = "/.well-known/blah/key"; const KEY_URL_SUBPATH: &str = "/.well-known/blah/key";
@ -66,7 +66,7 @@ enum DbCommand {
}, },
} }
fn flag_parser<T: Flags>(s: &str) -> clap::error::Result<T> { fn flag_parser<T: bitflags::Flags>(s: &str) -> clap::error::Result<T> {
bitflags::parser::from_str_strict(s) bitflags::parser::from_str_strict(s)
.map_err(|_| clap::Error::new(clap::error::ErrorKind::InvalidValue)) .map_err(|_| clap::Error::new(clap::error::ErrorKind::InvalidValue))
} }
@ -142,7 +142,7 @@ impl User {
} }
} }
static INIT_SQL: &str = include_str!("../../init.sql"); static INIT_SQL: &str = include_str!("../../blahd/init.sql");
fn main() -> Result<()> { fn main() -> Result<()> {
let cli = <Cli as clap::Parser>::parse(); let cli = <Cli as clap::Parser>::parse();

26
blahd/Cargo.toml Normal file
View file

@ -0,0 +1,26 @@
[package]
name = "blahd"
version = "0.0.0"
edition = "2021"
[dependencies]
anyhow = "1"
axum = { version = "0.7", features = ["tokio"] }
clap = { version = "4", features = ["derive"] }
ed25519-dalek = "2"
futures-util = "0.3"
hex = { version = "0.4", features = ["serde"] }
humantime = "2"
rusqlite = { version = "0.32", features = ["uuid"] }
sd-notify = "0.4"
serde = { version = "1", features = ["derive"] }
serde-aux = "4"
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] }
tokio-stream = { version = "0.1", features = ["sync"] }
tower-http = { version = "0.5", features = ["cors", "limit"] }
tracing = "0.1"
tracing-subscriber = "0.3"
uuid = { version = "1", features = ["v4"] }
blah = { path = "..", features = ["rusqlite"] }

View file

@ -1 +1,6 @@
// Re-export of public dependencies.
pub use bitflags;
pub use ed25519_dalek;
pub use uuid;
pub mod types; pub mod types;

View file

@ -367,6 +367,7 @@ impl_serde_for_bitflags!(ServerPermission);
impl_serde_for_bitflags!(MemberPermission); impl_serde_for_bitflags!(MemberPermission);
impl_serde_for_bitflags!(RoomAttrs); impl_serde_for_bitflags!(RoomAttrs);
#[cfg(feature = "rusqlite")]
mod sql_impl { mod sql_impl {
use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef}; use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSqlOutput, ValueRef};
use rusqlite::{Result, ToSql}; use rusqlite::{Result, ToSql};