From 26272a1379ac07609690f8ce393f853fc9107def Mon Sep 17 00:00:00 2001 From: Tyler Cook <10459406+cilki@users.noreply.github.com> Date: Sun, 5 Jan 2025 20:46:51 -0600 Subject: [PATCH] wip: update sysinfo structs --- sandpolis/src/agent/layer/shell.rs | 2 +- sandpolis/src/agent/layer/sysinfo/mod.rs | 6 ++ sandpolis/src/agent/layer/sysinfo/os/user.rs | 4 +- sandpolis/src/agent/mod.rs | 9 +- sandpolis/src/core/database.rs | 96 +++++++++++++------ .../src/core/layer/sysinfo/hardware/cpu.rs | 21 ++-- .../core/layer/sysinfo/hardware/disk/mod.rs | 56 ++++++----- .../layer/sysinfo/hardware/disk/partition.rs | 34 +++---- .../core/layer/sysinfo/hardware/disk/smart.rs | 70 +++++++------- .../src/core/layer/sysinfo/hardware/mod.rs | 2 + .../src/core/layer/sysinfo/hardware/nic.rs | 2 +- .../src/core/layer/sysinfo/hardware/sensor.rs | 15 +-- .../src/core/layer/sysinfo/hardware/sound.rs | 14 +-- .../core/layer/sysinfo/os/kernel_module.rs | 10 -- sandpolis/src/core/layer/sysinfo/os/mod.rs | 13 +++ .../src/core/layer/sysinfo/os/network/arp.rs | 18 ++-- .../src/core/layer/sysinfo/os/network/mod.rs | 14 +-- .../src/core/layer/sysinfo/os/process/fd.rs | 4 - .../src/core/layer/sysinfo/os/process/mod.rs | 7 ++ sandpolis/src/core/user.rs | 13 ++- sandpolis/src/server/mod.rs | 9 +- sandpolis/src/server/user.rs | 10 +- 22 files changed, 262 insertions(+), 167 deletions(-) delete mode 100644 sandpolis/src/core/layer/sysinfo/os/kernel_module.rs delete mode 100644 sandpolis/src/core/layer/sysinfo/os/process/fd.rs diff --git a/sandpolis/src/agent/layer/shell.rs b/sandpolis/src/agent/layer/shell.rs index 5fd617812..86a65cc8d 100644 --- a/sandpolis/src/agent/layer/shell.rs +++ b/sandpolis/src/agent/layer/shell.rs @@ -121,7 +121,7 @@ impl Drop for ShellSession { debug!("Killing child process"); self.process.kill(); // TODO await - self.data.ended = todo!(); + // self.data.update(ShellSessionDelta::ended); } } diff --git a/sandpolis/src/agent/layer/sysinfo/mod.rs b/sandpolis/src/agent/layer/sysinfo/mod.rs index 374c45b74..902079ad5 100644 --- a/sandpolis/src/agent/layer/sysinfo/mod.rs +++ b/sandpolis/src/agent/layer/sysinfo/mod.rs @@ -7,6 +7,12 @@ pub struct SysinfoLayer { pub memory: MemoryMonitor, } +impl SysinfoLayer { + pub fn new() -> Self { + todo!() + } +} + pub fn router() -> Router { Router::new() } diff --git a/sandpolis/src/agent/layer/sysinfo/os/user.rs b/sandpolis/src/agent/layer/sysinfo/os/user.rs index ba807ecfb..2adf4fa89 100644 --- a/sandpolis/src/agent/layer/sysinfo/os/user.rs +++ b/sandpolis/src/agent/layer/sysinfo/os/user.rs @@ -2,10 +2,10 @@ use crate::agent::Monitor; use crate::core::database::{Collection, Oid}; use crate::core::layer::sysinfo::os::user::UserData; use anyhow::Result; -use sysinfo::{User, Users}; +use sysinfo::Users; impl Monitor for Collection { - fn refresh(&self) -> Result<()> { + fn refresh(&mut self) -> Result<()> { for user in Users::new_with_refreshed_list().list() { self.document(**user.id())?.mutate(|data| { data.uid = **user.id() as u64; diff --git a/sandpolis/src/agent/mod.rs b/sandpolis/src/agent/mod.rs index eb26e0823..5758bc960 100644 --- a/sandpolis/src/agent/mod.rs +++ b/sandpolis/src/agent/mod.rs @@ -221,10 +221,17 @@ pub async fn main(args: CommandLine) -> Result<()> { let _ = tokio::fs::remove_file(&args.agent_args.agent_socket).await; let db = Database::new(args.storage.join("agent.db"))?; + let state = AgentState { + local: Arc::new(AgentInstance { + #[cfg(feature = "layer-sysinfo")] + sysinfo: crate::agent::layer::sysinfo::SysinfoLayer::new(), + }), + db, + }; let uds = UnixListener::bind(&args.agent_args.agent_socket)?; tokio::spawn(async move { - let app = Router::new().with_state(AgentState { db }); + let app = Router::new().with_state(state); #[cfg(feature = "layer-shell")] let app = app.nest("/layer/shell", crate::agent::layer::shell::router()); diff --git a/sandpolis/src/core/database.rs b/sandpolis/src/core/database.rs index 0f7356755..a387af2b4 100644 --- a/sandpolis/src/core/database.rs +++ b/sandpolis/src/core/database.rs @@ -3,28 +3,39 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::fmt::{Display, Write}; use std::marker::PhantomData; -use std::str::FromStr; use std::{path::Path, sync::Arc}; use tracing::debug; use super::InstanceId; -use super::{Instance, InstanceData, InstanceType}; #[derive(Clone)] pub struct Database(sled::Db); impl Database { + /// Initialize a new database from the given directory. pub fn new

(path: P) -> Result where P: AsRef, { - Ok(Self(sled::Config::new().path(path.as_ref()).open()?)) + let path = path.as_ref(); + + debug!(path = %path.display(), "Initializing database"); + Ok(Self(sled::Config::new().path(path).open()?)) } pub fn document(&self, oid: impl TryInto) -> Result> where - T: Serialize + DeserializeOwned + Clone, + T: Serialize + DeserializeOwned, { + let oid = oid.try_into()?; + todo!() + } + + pub fn collection(&self, oid: impl TryInto) -> Result> + where + T: Serialize + DeserializeOwned, + { + let oid = oid.try_into()?; todo!() } @@ -45,27 +56,49 @@ impl Display for Oid { let mut iter = self.0.iter(); loop { if let Some(b) = iter.next() { - f.write_char(*b as char); + f.write_char(*b as char)?; if ':' as u8 == *b { - // TODO timestamp + // The next 8 bytes are the timestamp + let mut timestamp = 0u64; + for i in 0..8 { + if let Some(byte) = iter.next() { + timestamp |= (*byte as u64) << (i * 8); + } else { + return Err(std::fmt::Error); + } + } + f.write_str(&format!("{}", timestamp))?; } } else { break; } } - todo!() + Ok(()) + } +} + +#[cfg(test)] +mod test_display { + use super::Oid; + + #[test] + fn test_format_good() { + assert_eq!(Oid("/a".as_bytes().to_vec()).to_string(), "/a"); } } impl Oid { - pub fn extend(mut self, extension: &str) -> Result { - self.path.push('/' as u8); - self.path.extend_from_slice(extension.as_bytes()); - Ok(self) + pub fn extend(&self, oid: impl TryInto) -> Result { + let mut path = self.0.clone(); + + path.push('/' as u8); + path.extend_from_slice(&oid.try_into()?.0); + Ok(Oid(path)) } - pub fn timestamp(mut self, timestamp: u64) -> Result> { + /// Add or replace the timestamp. + pub fn timestamp(mut self, timestamp: u64) -> Result { // TODO overwrite timestamp if one exists for byte in self.path.iter().rev() { if *byte == ':' as u8 { @@ -108,19 +141,16 @@ impl AsRef<[u8]> for Oid { #[derive(Clone)] pub struct Collection where - T: Serialize + DeserializeOwned + Clone, + T: Serialize + DeserializeOwned, { db: sled::Tree, oid: Oid, data: PhantomData, } -impl Collection { - pub fn get_document(&self, id: I) -> Result>> - where - I: Into, - { - let oid = self.oid.extend_id(id.into())?; +impl Collection { + pub fn get_document(&self, oid: impl TryInto) -> Result>> { + let oid = self.oid.extend(oid)?; Ok(if let Some(data) = self.db.get(&oid)? { Some(Document { @@ -133,20 +163,26 @@ impl Collection { }) } - pub fn collection(&self) -> Result> + pub fn documents(&self) { + self.db + .range::<&Oid, std::ops::Range<&Oid>>(&self.oid..&self.oid); + } + + pub fn collection(&self, oid: impl TryInto) -> Result> where U: Serialize + DeserializeOwned + Clone, { - todo!() + Ok(Collection { + db: self.db.clone(), + oid: self.oid.extend(oid)?, + data: PhantomData {}, + }) } } -impl Collection { - pub fn document(&self, id: I) -> Result> - where - I: Into, - { - let oid = self.oid.extend_id(id.into())?; +impl Collection { + pub fn document(&self, oid: impl TryInto) -> Result> { + let oid = self.oid.extend(oid)?; Ok(Document { db: self.db.clone(), @@ -163,13 +199,17 @@ impl Collection { #[derive(Clone)] pub struct Document where - T: Serialize + DeserializeOwned + Clone, + T: Serialize + DeserializeOwned, { pub db: sled::Tree, pub oid: Oid, pub data: T, } +impl Document { + // pub fn update(&mut self, update: ) +} + impl Document { pub fn mutate(&mut self, mutator: F) -> Result<()> where diff --git a/sandpolis/src/core/layer/sysinfo/hardware/cpu.rs b/sandpolis/src/core/layer/sysinfo/hardware/cpu.rs index 2ef15fb1f..d4f8a4483 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/cpu.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/cpu.rs @@ -1,23 +1,22 @@ pub struct CpuData { - /// null + /// Product model pub model: Option, - /// null + /// Vendor name pub vendor: Option, /// The specified frequency in Hertz pub frequency_spec: u64, + /// Actual frequency in Hertz + pub frequency: u64, /// The size of the L1 cache in bytes - pub l1_cache: u64, + pub l1_cache: Option, /// The size of the L2 cache in bytes - pub l2_cache: u64, + pub l2_cache: Option, /// The size of the L3 cache in bytes - pub l3_cache: u64, + pub l3_cache: Option, /// The size of the L4 cache in bytes - pub l4_cache: u64, -} - -pub struct CpuCoreData { + pub l4_cache: Option, /// The core's usage between 0.0 and 1.0 - pub usage: Double, + pub usage: f64, /// The core's temperature in Celsius - pub temperature: Double, + pub temperature: Option, } diff --git a/sandpolis/src/core/layer/sysinfo/hardware/disk/mod.rs b/sandpolis/src/core/layer/sysinfo/hardware/disk/mod.rs index 200ff74d3..042def401 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/disk/mod.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/disk/mod.rs @@ -1,26 +1,30 @@ -/// null -pub name: java.lang.String, -/// null -pub model: java.lang.String, -/// null -pub serial: java.lang.String, -/// The disk's total size in bytes -pub size: java.lang.Long, -/// null -pub reads: java.lang.Long, -/// null -pub read_bytes: java.lang.Long, -/// null -pub writes: java.lang.Long, -/// null -pub write_bytes: java.lang.Long, -/// null -pub queue_length: java.lang.Long, -/// null -pub transfer_time: java.lang.Long, -/// null -pub model_family: java.lang.String, -/// null -pub firmware_version: java.lang.String, -/// null -pub read_error_rate: java.lang.Long, +pub mod smart; + +pub struct DiskData { + /// null + pub name: String, + /// null + pub model: String, + /// null + pub serial: String, + /// Total size in bytes + pub size: u64, + /// null + pub reads: u64, + /// null + pub read_bytes: u64, + /// null + pub writes: u64, + /// null + pub write_bytes: u64, + /// null + pub queue_length: u64, + /// null + pub transfer_time: u64, + /// null + pub model_family: String, + /// null + pub firmware_version: String, + /// null + pub read_error_rate: u64, +} diff --git a/sandpolis/src/core/layer/sysinfo/hardware/disk/partition.rs b/sandpolis/src/core/layer/sysinfo/hardware/disk/partition.rs index 0d9c7dd62..441011ebe 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/disk/partition.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/disk/partition.rs @@ -1,16 +1,18 @@ -/// null -pub identification: java.lang.String, -/// null -pub name: java.lang.String, -/// null -pub description: java.lang.String, -/// The partition's UUID -pub uuid: java.lang.String, -/// The partition's total size in bytes -pub size: java.lang.Long, -/// null -pub major: java.lang.Integer, -/// null -pub minor: java.lang.Integer, -/// The partition's mount point -pub mount: java.lang.String, +pub struct PartitionData { + /// null + pub identification: String, + /// null + pub name: String, + /// null + pub description: String, + /// The partition's UUID + pub uuid: String, + /// The partition's total size in bytes + pub size: u64, + /// null + pub major: u32, + /// null + pub minor: u32, + /// The partition's mount point + pub mount: String, +} diff --git a/sandpolis/src/core/layer/sysinfo/hardware/disk/smart.rs b/sandpolis/src/core/layer/sysinfo/hardware/disk/smart.rs index cc4971742..593baf782 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/disk/smart.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/disk/smart.rs @@ -1,34 +1,36 @@ -/// Drive rotations per minute -pub rotation_rate: java.lang.Long, -/// null -pub spin_up_time: java.lang.Long, -/// null -pub start_stop_cycles: java.lang.Long, -/// null -pub reallocated_sectors: java.lang.Long, -/// null -pub seek_error_rate: java.lang.Long, -/// null -pub power_on_time: java.lang.Long, -/// null -pub spin_retries: java.lang.Long, -/// null -pub calibration_retries: java.lang.Long, -/// null -pub power_cycles: java.lang.Long, -/// null -pub poweroff_retracts: java.lang.Long, -/// null -pub load_cycles: java.lang.Long, -/// null -pub temperature: java.lang.Long, -/// null -pub reallocated_events: java.lang.Long, -/// null -pub current_pending_sector: java.lang.Long, -/// null -pub offline_uncorrectable: java.lang.Long, -/// null -pub crc_errors: java.lang.Long, -/// null -pub multizone_error_rate: java.lang.Long, +pub struct SmartData { + /// Drive rotations per minute + pub rotation_rate: u64, + /// null + pub spin_up_time: u64, + /// null + pub start_stop_cycles: u64, + /// null + pub reallocated_sectors: u64, + /// null + pub seek_error_rate: u64, + /// null + pub power_on_time: u64, + /// null + pub spin_retries: u64, + /// null + pub calibration_retries: u64, + /// null + pub power_cycles: u64, + /// null + pub poweroff_retracts: u64, + /// null + pub load_cycles: u64, + /// null + pub temperature: u64, + /// null + pub reallocated_events: u64, + /// null + pub current_pending_sector: u64, + /// null + pub offline_uncorrectable: u64, + /// null + pub crc_errors: u64, + /// null + pub multizone_error_rate: u64, +} diff --git a/sandpolis/src/core/layer/sysinfo/hardware/mod.rs b/sandpolis/src/core/layer/sysinfo/hardware/mod.rs index cd51e448b..cc8b8477b 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/mod.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/mod.rs @@ -1,7 +1,9 @@ pub mod battery; pub mod cpu; +pub mod disk; pub mod display; pub mod mainboard; pub mod memory; pub mod nic; +pub mod sensor; pub mod usb; diff --git a/sandpolis/src/core/layer/sysinfo/hardware/nic.rs b/sandpolis/src/core/layer/sysinfo/hardware/nic.rs index baf30efde..9c4628c24 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/nic.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/nic.rs @@ -4,7 +4,7 @@ pub struct NicData { /// The interface's description pub description: String, /// The interface's maximum transmission unit in bytes - pub mtu: Integer, + pub mtu: u32, /// The interface's MAC address pub mac: String, /// null diff --git a/sandpolis/src/core/layer/sysinfo/hardware/sensor.rs b/sandpolis/src/core/layer/sysinfo/hardware/sensor.rs index 9e7ec52ba..46de9ee96 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/sensor.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/sensor.rs @@ -1,6 +1,9 @@ -/// null -pub fan_speed: java.lang.Integer, -/// null -pub temperature: java.lang.Double, -/// null -pub voltage: java.lang.Double, +/// A generic sensor in the system. +pub struct SensorData { + /// A fan speed reading in RPM + pub fan_speed: Option, + /// A temperature reading in Celsius + pub temperature: Option, + /// A voltage reading in Volts + pub voltage: Option, +} diff --git a/sandpolis/src/core/layer/sysinfo/hardware/sound.rs b/sandpolis/src/core/layer/sysinfo/hardware/sound.rs index 377c5d0e0..548d5eec7 100644 --- a/sandpolis/src/core/layer/sysinfo/hardware/sound.rs +++ b/sandpolis/src/core/layer/sysinfo/hardware/sound.rs @@ -1,6 +1,8 @@ -/// null -pub driver_version: java.lang.String, -/// null -pub name: java.lang.String, -/// null -pub codec: java.lang.String, +pub struct SoundDeviceData { + /// null + pub driver_version: String, + /// null + pub name: String, + /// null + pub codec: String, +} diff --git a/sandpolis/src/core/layer/sysinfo/os/kernel_module.rs b/sandpolis/src/core/layer/sysinfo/os/kernel_module.rs deleted file mode 100644 index 7fcaa3901..000000000 --- a/sandpolis/src/core/layer/sysinfo/os/kernel_module.rs +++ /dev/null @@ -1,10 +0,0 @@ -/// Module name -pub name: java.lang.String, -/// Size of module content -pub size: java.lang.String, -/// Module reverse dependencies -pub used_by: java.lang.String, -/// Kernel module status -pub status: java.lang.String, -/// Kernel module address -pub address: java.lang.String, diff --git a/sandpolis/src/core/layer/sysinfo/os/mod.rs b/sandpolis/src/core/layer/sysinfo/os/mod.rs index 654e453e2..385123d16 100644 --- a/sandpolis/src/core/layer/sysinfo/os/mod.rs +++ b/sandpolis/src/core/layer/sysinfo/os/mod.rs @@ -25,3 +25,16 @@ pub struct OsData { /// OS architecture pub arch: String, } + +pub struct KernelModuleData { + /// Module name + pub name: String, + /// Size of module content + pub size: String, + /// Module reverse dependencies + pub used_by: String, + /// Kernel module status + pub status: String, + /// Kernel module address + pub address: String, +} diff --git a/sandpolis/src/core/layer/sysinfo/os/network/arp.rs b/sandpolis/src/core/layer/sysinfo/os/network/arp.rs index ed3c9f51b..e26f0243a 100644 --- a/sandpolis/src/core/layer/sysinfo/os/network/arp.rs +++ b/sandpolis/src/core/layer/sysinfo/os/network/arp.rs @@ -1,8 +1,10 @@ -/// IPv4 address target -pub address: java.lang.String, -/// MAC address of broadcasted address -pub mac: java.lang.String, -/// Interface of the network for the MAC -pub interface_id: java.lang.String, -/// Whether the ARP entry is permanent -pub permanent: java.lang.Boolean, +pub struct ArpEntryData { + /// IPv4 address target + pub address: String, + /// MAC address of broadcasted address + pub mac: String, + /// Interface of the network for the MAC + pub interface_id: String, + /// Whether the ARP entry is permanent + pub permanent: Boolean, +} diff --git a/sandpolis/src/core/layer/sysinfo/os/network/mod.rs b/sandpolis/src/core/layer/sysinfo/os/network/mod.rs index 2a9576bdd..9a872726a 100644 --- a/sandpolis/src/core/layer/sysinfo/os/network/mod.rs +++ b/sandpolis/src/core/layer/sysinfo/os/network/mod.rs @@ -1,6 +1,8 @@ -/// The host's hostname -pub hostname: java.lang.String, -/// The host's fully-qualified domain name -pub fqdn: java.lang.String, -/// The host's DNS servers -pub dns: java.lang.String, +pub struct NetworkData { + /// The host's hostname + pub hostname: String, + /// The host's fully-qualified domain name + pub fqdn: String, + /// The host's DNS servers + pub dns: String, +} diff --git a/sandpolis/src/core/layer/sysinfo/os/process/fd.rs b/sandpolis/src/core/layer/sysinfo/os/process/fd.rs deleted file mode 100644 index 346de03c2..000000000 --- a/sandpolis/src/core/layer/sysinfo/os/process/fd.rs +++ /dev/null @@ -1,4 +0,0 @@ -/// Process-specific file descriptor number -pub fd: java.lang.Long, -/// Filesystem path of descriptor -pub path: java.lang.Long, diff --git a/sandpolis/src/core/layer/sysinfo/os/process/mod.rs b/sandpolis/src/core/layer/sysinfo/os/process/mod.rs index c66ecd3c7..f3d25f7cf 100644 --- a/sandpolis/src/core/layer/sysinfo/os/process/mod.rs +++ b/sandpolis/src/core/layer/sysinfo/os/process/mod.rs @@ -42,3 +42,10 @@ pub struct ProcessData { /// The number of file handles that the process owns pub handle_count: u64, } + +pub struct FdData { + /// Process-specific file descriptor number + pub fd: u64, + /// Filesystem path of descriptor + pub path: String, +} diff --git a/sandpolis/src/core/user.rs b/sandpolis/src/core/user.rs index a7914a8fb..13b01143b 100644 --- a/sandpolis/src/core/user.rs +++ b/sandpolis/src/core/user.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use url::Url; use validator::Validate; #[derive(Serialize, Deserialize, Validate)] @@ -31,13 +30,15 @@ pub struct CreateUserRequest { pub password: String, /// TOTP secret URL - pub totp_secret: Option, + pub totp_secret: Option, } +#[derive(Serialize, Deserialize)] pub enum CreateUserResponse { Ok, } +#[derive(Serialize, Deserialize)] pub struct GetUsersRequest { /// Search by username prefix pub username: Option, @@ -46,11 +47,13 @@ pub struct GetUsersRequest { pub email: Option, } +#[derive(Serialize, Deserialize)] pub enum GetUsersResponse { Ok(Vec), } /// Update an existing user account. +#[derive(Serialize, Deserialize)] pub struct UpdateUserRequest { /// User to edit pub username: String, @@ -68,6 +71,7 @@ pub struct UpdateUserRequest { pub expiration: Option, } +#[derive(Serialize, Deserialize)] pub enum UpdateUserResponse { Ok, @@ -76,6 +80,7 @@ pub enum UpdateUserResponse { } /// Request a login from the server +#[derive(Serialize, Deserialize)] pub struct LoginRequest { /// User to login as pub username: String, @@ -87,8 +92,10 @@ pub struct LoginRequest { pub totp_token: Option, } +#[derive(Serialize, Deserialize)] pub enum LoginResponse { - Ok, + /// The login was successful and returned a session token + Ok(String), /// The request was invalid Invalid, diff --git a/sandpolis/src/server/mod.rs b/sandpolis/src/server/mod.rs index 99815c986..990b908a9 100644 --- a/sandpolis/src/server/mod.rs +++ b/sandpolis/src/server/mod.rs @@ -21,6 +21,8 @@ //! Every LS server maintains a database containing just the contents relevant to it //! which is continuously replicated to a GS server's database. +use crate::core::database::Collection; +use crate::core::user::UserData; use crate::core::{database::Database, S7S_PORT}; use crate::CommandLine; use anyhow::{Context, Result}; @@ -39,7 +41,6 @@ use std::{ path::PathBuf, }; use tracing::{info, trace}; -use user::User; pub mod user; @@ -65,8 +66,12 @@ pub struct ServerInstance { } pub async fn main(args: CommandLine) -> Result<()> { + let db = Database::new(args.storage.join("server.db"))?; let state = ServerState { - db: Database::new(args.storage.join("server.db"))?, + local: Arc::new(ServerInstance { + users: db.collection("/server/users")?, + }), + db, }; let app = Router::new().fallback(fallback_handler).with_state(state); diff --git a/sandpolis/src/server/user.rs b/sandpolis/src/server/user.rs index 38326a0bd..c45f489c6 100644 --- a/sandpolis/src/server/user.rs +++ b/sandpolis/src/server/user.rs @@ -9,7 +9,13 @@ use serde::{Deserialize, Serialize}; use std::{fmt::Display, num::NonZeroU32}; use validator::Validate; -use crate::core::database::Document; +use crate::core::{ + database::Document, + user::{ + CreateUserRequest, CreateUserResponse, GetUsersRequest, GetUsersResponse, LoginRequest, + LoginResponse, + }, +}; use super::ServerState; @@ -26,7 +32,7 @@ pub struct PasswordData { pub hash: Vec, /// TOTP secret token - pub totp_secret: Option, + pub totp_secret: Option, } impl Display for PasswordData {