From 50ce87161b61f2d539fd178f67f186b3935ce7ec Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 16 Jun 2024 22:26:52 +0000 Subject: [PATCH] refactor admin command visibilities and use statements Signed-off-by: Jason Volk --- .../{appservice_command.rs => commands.rs} | 8 ++-- src/admin/appservice/mod.rs | 10 ++--- .../debug/{debug_commands.rs => commands.rs} | 37 +++++++++--------- src/admin/debug/mod.rs | 16 +++----- .../{federation_commands.rs => commands.rs} | 10 ++--- src/admin/federation/mod.rs | 14 +++---- .../fsck/{fsck_commands.rs => commands.rs} | 5 ++- src/admin/fsck/mod.rs | 12 +++--- .../media/{media_commands.rs => commands.rs} | 9 +++-- src/admin/media/mod.rs | 12 +++--- src/admin/query/account_data.rs | 2 +- src/admin/query/appservice.rs | 2 +- src/admin/query/globals.rs | 2 +- src/admin/query/mod.rs | 38 +++++++++---------- src/admin/query/presence.rs | 2 +- src/admin/query/room_alias.rs | 2 +- src/admin/query/room_state_cache.rs | 2 +- src/admin/query/sending.rs | 2 +- src/admin/query/users.rs | 2 +- src/admin/room/mod.rs | 26 ++++++------- src/admin/room/room_alias_commands.rs | 2 +- src/admin/room/room_commands.rs | 2 +- src/admin/room/room_directory_commands.rs | 2 +- src/admin/room/room_info_commands.rs | 2 +- src/admin/room/room_moderation_commands.rs | 2 +- .../{server_commands.rs => commands.rs} | 28 +++++++------- src/admin/server/mod.rs | 10 ++--- src/admin/tester/mod.rs | 4 +- .../user/{user_commands.rs => commands.rs} | 21 +++++----- src/admin/user/mod.rs | 11 +++--- 30 files changed, 145 insertions(+), 152 deletions(-) rename src/admin/appservice/{appservice_command.rs => commands.rs} (89%) rename src/admin/debug/{debug_commands.rs => commands.rs} (95%) rename src/admin/federation/{federation_commands.rs => commands.rs} (92%) rename src/admin/fsck/{fsck_commands.rs => commands.rs} (89%) rename src/admin/media/{media_commands.rs => commands.rs} (97%) rename src/admin/server/{server_commands.rs => commands.rs} (77%) rename src/admin/user/{user_commands.rs => commands.rs} (96%) diff --git a/src/admin/appservice/appservice_command.rs b/src/admin/appservice/commands.rs similarity index 89% rename from src/admin/appservice/appservice_command.rs rename to src/admin/appservice/commands.rs index 6f36ebf7..5b764296 100644 --- a/src/admin/appservice/appservice_command.rs +++ b/src/admin/appservice/commands.rs @@ -2,7 +2,7 @@ use ruma::{api::appservice::Registration, events::room::message::RoomMessageEven use crate::{escape_html, services, Result}; -pub(crate) async fn register(body: Vec<&str>) -> Result { +pub(super) async fn register(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { return Ok(RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", @@ -26,7 +26,7 @@ pub(crate) async fn register(body: Vec<&str>) -> Result } } -pub(crate) async fn unregister(_body: Vec<&str>, appservice_identifier: String) -> Result { +pub(super) async fn unregister(_body: Vec<&str>, appservice_identifier: String) -> Result { match services() .appservice .unregister_appservice(&appservice_identifier) @@ -39,7 +39,7 @@ pub(crate) async fn unregister(_body: Vec<&str>, appservice_identifier: String) } } -pub(crate) async fn show(_body: Vec<&str>, appservice_identifier: String) -> Result { +pub(super) async fn show(_body: Vec<&str>, appservice_identifier: String) -> Result { match services() .appservice .get_registration(&appservice_identifier) @@ -59,7 +59,7 @@ pub(crate) async fn show(_body: Vec<&str>, appservice_identifier: String) -> Res } } -pub(crate) async fn list(_body: Vec<&str>) -> Result { +pub(super) async fn list(_body: Vec<&str>) -> Result { let appservices = services().appservice.iter_ids().await; let output = format!("Appservices ({}): {}", appservices.len(), appservices.join(", ")); Ok(RoomMessageEventContent::text_plain(output)) diff --git a/src/admin/appservice/mod.rs b/src/admin/appservice/mod.rs index 8cf246b9..87ab1b6d 100644 --- a/src/admin/appservice/mod.rs +++ b/src/admin/appservice/mod.rs @@ -1,14 +1,14 @@ +mod commands; + use clap::Subcommand; use conduit::Result; use ruma::events::room::message::RoomMessageEventContent; -use self::appservice_command::{list, register, show, unregister}; - -pub(crate) mod appservice_command; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum AppserviceCommand { +pub(super) enum AppserviceCommand { /// - Register an appservice using its registration YAML /// /// This command needs a YAML generated by an appservice (such as a bridge), @@ -38,7 +38,7 @@ pub(crate) enum AppserviceCommand { List, } -pub(crate) async fn process(command: AppserviceCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: AppserviceCommand, body: Vec<&str>) -> Result { Ok(match command { AppserviceCommand::Register => register(body).await?, AppserviceCommand::Unregister { diff --git a/src/admin/debug/debug_commands.rs b/src/admin/debug/commands.rs similarity index 95% rename from src/admin/debug/debug_commands.rs rename to src/admin/debug/commands.rs index 681dc6fb..0409af32 100644 --- a/src/admin/debug/debug_commands.rs +++ b/src/admin/debug/commands.rs @@ -4,6 +4,7 @@ use std::{ time::Instant, }; +use api::client::validate_and_add_event_id; use conduit::{ debug, info, log, log::{capture, Capture}, @@ -19,15 +20,13 @@ use service::{rooms::event_handler::parse_incoming_pdu, sending::resolve::resolv use tokio::sync::RwLock; use tracing_subscriber::EnvFilter; -use crate::api::client::validate_and_add_event_id; - -pub(crate) async fn echo(_body: Vec<&str>, message: Vec) -> Result { +pub(super) async fn echo(_body: Vec<&str>, message: Vec) -> Result { let message = message.join(" "); Ok(RoomMessageEventContent::notice_plain(message)) } -pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box) -> Result { +pub(super) async fn get_auth_chain(_body: Vec<&str>, event_id: Box) -> Result { let event_id = Arc::::from(event_id); if let Some(event) = services().rooms.timeline.get_pdu_json(&event_id)? { let room_id_str = event @@ -53,7 +52,7 @@ pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box) -> } } -pub(crate) async fn parse_pdu(body: Vec<&str>) -> Result { +pub(super) async fn parse_pdu(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { return Ok(RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", @@ -81,7 +80,7 @@ pub(crate) async fn parse_pdu(body: Vec<&str>) -> Result, event_id: Box) -> Result { +pub(super) async fn get_pdu(_body: Vec<&str>, event_id: Box) -> Result { let mut outlier = false; let mut pdu_json = services() .rooms @@ -119,7 +118,7 @@ pub(crate) async fn get_pdu(_body: Vec<&str>, event_id: Box) -> Result< } } -pub(crate) async fn get_remote_pdu_list( +pub(super) async fn get_remote_pdu_list( body: Vec<&str>, server: Box, force: bool, ) -> Result { if !services().globals.config.allow_federation { @@ -166,7 +165,7 @@ pub(crate) async fn get_remote_pdu_list( Ok(RoomMessageEventContent::text_plain("Fetched list of remote PDUs.")) } -pub(crate) async fn get_remote_pdu( +pub(super) async fn get_remote_pdu( _body: Vec<&str>, event_id: Box, server: Box, ) -> Result { if !services().globals.config.allow_federation { @@ -256,7 +255,7 @@ pub(crate) async fn get_remote_pdu( } } -pub(crate) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Result { +pub(super) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Result { let room_state = services() .rooms .state_accessor @@ -289,7 +288,7 @@ pub(crate) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Re )) } -pub(crate) async fn ping(_body: Vec<&str>, server: Box) -> Result { +pub(super) async fn ping(_body: Vec<&str>, server: Box) -> Result { if server == services().globals.server_name() { return Ok(RoomMessageEventContent::text_plain( "Not allowed to send federation requests to ourselves.", @@ -332,7 +331,7 @@ pub(crate) async fn ping(_body: Vec<&str>, server: Box) -> Result) -> Result { +pub(super) async fn force_device_list_updates(_body: Vec<&str>) -> Result { // Force E2EE device list updates for all users for user_id in services().users.iter().filter_map(Result::ok) { services().users.mark_device_key_update(&user_id)?; @@ -342,7 +341,7 @@ pub(crate) async fn force_device_list_updates(_body: Vec<&str>) -> Result, filter: Option, reset: bool, ) -> Result { if reset { @@ -395,7 +394,7 @@ pub(crate) async fn change_log_level( Ok(RoomMessageEventContent::text_plain("No log level was specified.")) } -pub(crate) async fn sign_json(body: Vec<&str>) -> Result { +pub(super) async fn sign_json(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { return Ok(RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", @@ -418,7 +417,7 @@ pub(crate) async fn sign_json(body: Vec<&str>) -> Result) -> Result { +pub(super) async fn verify_json(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { return Ok(RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", @@ -449,7 +448,7 @@ pub(crate) async fn verify_json(body: Vec<&str>) -> Result, room_id: Box) -> Result { +pub(super) async fn first_pdu_in_room(_body: Vec<&str>, room_id: Box) -> Result { if !services() .rooms .state_cache @@ -470,7 +469,7 @@ pub(crate) async fn first_pdu_in_room(_body: Vec<&str>, room_id: Box) -> } #[tracing::instrument(skip(_body))] -pub(crate) async fn latest_pdu_in_room(_body: Vec<&str>, room_id: Box) -> Result { +pub(super) async fn latest_pdu_in_room(_body: Vec<&str>, room_id: Box) -> Result { if !services() .rooms .state_cache @@ -491,7 +490,7 @@ pub(crate) async fn latest_pdu_in_room(_body: Vec<&str>, room_id: Box) - } #[tracing::instrument(skip(_body))] -pub(crate) async fn force_set_room_state_from_server( +pub(super) async fn force_set_room_state_from_server( _body: Vec<&str>, server_name: Box, room_id: Box, ) -> Result { if !services() @@ -621,7 +620,7 @@ pub(crate) async fn force_set_room_state_from_server( )) } -pub(crate) async fn resolve_true_destination( +pub(super) async fn resolve_true_destination( _body: Vec<&str>, server_name: Box, no_cache: bool, ) -> Result { if !services().globals.config.allow_federation { @@ -659,7 +658,7 @@ pub(crate) async fn resolve_true_destination( } #[must_use] -pub(crate) fn memory_stats() -> RoomMessageEventContent { +pub(super) fn memory_stats() -> RoomMessageEventContent { let html_body = conduit::alloc::memory_stats(); if html_body.is_empty() { diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 52c49c20..19d3712a 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -1,18 +1,14 @@ +mod commands; + use clap::Subcommand; -use debug_commands::{first_pdu_in_room, force_set_room_state_from_server, latest_pdu_in_room}; +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, EventId, RoomId, ServerName}; -use self::debug_commands::{ - change_log_level, echo, force_device_list_updates, get_auth_chain, get_pdu, get_remote_pdu, get_remote_pdu_list, - get_room_state, memory_stats, parse_pdu, ping, resolve_true_destination, sign_json, verify_json, -}; -use crate::Result; - -pub(crate) mod debug_commands; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum DebugCommand { +pub(super) enum DebugCommand { /// - Echo input of admin command Echo { message: Vec, @@ -163,7 +159,7 @@ pub(crate) enum DebugCommand { MemoryStats, } -pub(crate) async fn process(command: DebugCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: DebugCommand, body: Vec<&str>) -> Result { Ok(match command { DebugCommand::Echo { message, diff --git a/src/admin/federation/federation_commands.rs b/src/admin/federation/commands.rs similarity index 92% rename from src/admin/federation/federation_commands.rs rename to src/admin/federation/commands.rs index b52a62f2..4084350d 100644 --- a/src/admin/federation/federation_commands.rs +++ b/src/admin/federation/commands.rs @@ -4,17 +4,17 @@ use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, use crate::{escape_html, get_room_info, services, utils::HtmlEscape, Result}; -pub(crate) async fn disable_room(_body: Vec<&str>, room_id: Box) -> Result { +pub(super) async fn disable_room(_body: Vec<&str>, room_id: Box) -> Result { services().rooms.metadata.disable_room(&room_id, true)?; Ok(RoomMessageEventContent::text_plain("Room disabled.")) } -pub(crate) async fn enable_room(_body: Vec<&str>, room_id: Box) -> Result { +pub(super) async fn enable_room(_body: Vec<&str>, room_id: Box) -> Result { services().rooms.metadata.disable_room(&room_id, false)?; Ok(RoomMessageEventContent::text_plain("Room enabled.")) } -pub(crate) async fn incoming_federation(_body: Vec<&str>) -> Result { +pub(super) async fn incoming_federation(_body: Vec<&str>) -> Result { let map = services().globals.roomid_federationhandletime.read().await; let mut msg = format!("Handling {} incoming pdus:\n", map.len()); @@ -26,7 +26,7 @@ pub(crate) async fn incoming_federation(_body: Vec<&str>) -> Result, server_name: Box, ) -> Result { let response = services() @@ -72,7 +72,7 @@ pub(crate) async fn fetch_support_well_known( )) } -pub(crate) async fn remote_user_in_rooms(_body: Vec<&str>, user_id: Box) -> Result { +pub(super) async fn remote_user_in_rooms(_body: Vec<&str>, user_id: Box) -> Result { if user_id.server_name() == services().globals.config.server_name { return Ok(RoomMessageEventContent::text_plain( "User belongs to our server, please use `list-joined-rooms` user admin command instead.", diff --git a/src/admin/federation/mod.rs b/src/admin/federation/mod.rs index 81469feb..46e323b2 100644 --- a/src/admin/federation/mod.rs +++ b/src/admin/federation/mod.rs @@ -1,16 +1,14 @@ +mod commands; + use clap::Subcommand; +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, RoomId, ServerName, UserId}; -use self::federation_commands::{ - disable_room, enable_room, fetch_support_well_known, incoming_federation, remote_user_in_rooms, -}; -use crate::Result; - -pub(crate) mod federation_commands; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum FederationCommand { +pub(super) enum FederationCommand { /// - List all rooms we are currently handling an incoming pdu from IncomingFederation, @@ -43,7 +41,7 @@ pub(crate) enum FederationCommand { }, } -pub(crate) async fn process(command: FederationCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: FederationCommand, body: Vec<&str>) -> Result { Ok(match command { FederationCommand::DisableRoom { room_id, diff --git a/src/admin/fsck/fsck_commands.rs b/src/admin/fsck/commands.rs similarity index 89% rename from src/admin/fsck/fsck_commands.rs rename to src/admin/fsck/commands.rs index 2eab94de..9fb0281a 100644 --- a/src/admin/fsck/fsck_commands.rs +++ b/src/admin/fsck/commands.rs @@ -1,11 +1,12 @@ +use conduit::Result; use ruma::events::room::message::RoomMessageEventContent; -use crate::{services, Result}; +use crate::services; /// Uses the iterator in `src/database/key_value/users.rs` to iterator over /// every user in our database (remote and local). Reports total count, any /// errors if there were any, etc -pub(crate) async fn check_all_users(_body: Vec<&str>) -> Result { +pub(super) async fn check_all_users(_body: Vec<&str>) -> Result { let timer = tokio::time::Instant::now(); let results = services().users.db.iter(); let query_time = timer.elapsed(); diff --git a/src/admin/fsck/mod.rs b/src/admin/fsck/mod.rs index e618fdc5..4252718d 100644 --- a/src/admin/fsck/mod.rs +++ b/src/admin/fsck/mod.rs @@ -1,18 +1,18 @@ +mod commands; + use clap::Subcommand; +use conduit::Result; use ruma::events::room::message::RoomMessageEventContent; -use self::fsck_commands::check_all_users; -use crate::Result; - -pub(crate) mod fsck_commands; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum FsckCommand { +pub(super) enum FsckCommand { CheckAllUsers, } -pub(crate) async fn process(command: FsckCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: FsckCommand, body: Vec<&str>) -> Result { Ok(match command { FsckCommand::CheckAllUsers => check_all_users(body).await?, }) diff --git a/src/admin/media/media_commands.rs b/src/admin/media/commands.rs similarity index 97% rename from src/admin/media/media_commands.rs rename to src/admin/media/commands.rs index a78ee387..c1026ae2 100644 --- a/src/admin/media/media_commands.rs +++ b/src/admin/media/commands.rs @@ -1,9 +1,10 @@ +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, EventId, MxcUri}; use tracing::{debug, info}; -use crate::{services, Result}; +use crate::services; -pub(crate) async fn delete( +pub(super) async fn delete( _body: Vec<&str>, mxc: Option>, event_id: Option>, ) -> Result { if event_id.is_some() && mxc.is_some() { @@ -137,7 +138,7 @@ pub(crate) async fn delete( )) } -pub(crate) async fn delete_list(body: Vec<&str>) -> Result { +pub(super) async fn delete_list(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { return Ok(RoomMessageEventContent::text_plain( "Expected code block in command body. Add --help for details.", @@ -164,7 +165,7 @@ pub(crate) async fn delete_list(body: Vec<&str>) -> Result, duration: String, force: bool, ) -> Result { let deleted_count = services() diff --git a/src/admin/media/mod.rs b/src/admin/media/mod.rs index b5957370..60f7a9bb 100644 --- a/src/admin/media/mod.rs +++ b/src/admin/media/mod.rs @@ -1,14 +1,14 @@ +mod commands; + use clap::Subcommand; +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, EventId, MxcUri}; -use self::media_commands::{delete, delete_list, delete_past_remote_media}; -use crate::Result; - -pub(crate) mod media_commands; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum MediaCommand { +pub(super) enum MediaCommand { /// - Deletes a single media file from our database and on the filesystem /// via a single MXC URL Delete { @@ -38,7 +38,7 @@ pub(crate) enum MediaCommand { }, } -pub(crate) async fn process(command: MediaCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: MediaCommand, body: Vec<&str>) -> Result { Ok(match command { MediaCommand::Delete { mxc, diff --git a/src/admin/query/account_data.rs b/src/admin/query/account_data.rs index eb7cd0d1..290d5a04 100644 --- a/src/admin/query/account_data.rs +++ b/src/admin/query/account_data.rs @@ -4,7 +4,7 @@ use super::AccountData; use crate::{services, Result}; /// All the getters and iterators from src/database/key_value/account_data.rs -pub(crate) async fn account_data(subcommand: AccountData) -> Result { +pub(super) async fn account_data(subcommand: AccountData) -> Result { match subcommand { AccountData::ChangesSince { user_id, diff --git a/src/admin/query/appservice.rs b/src/admin/query/appservice.rs index d108ca8d..a94f22b8 100644 --- a/src/admin/query/appservice.rs +++ b/src/admin/query/appservice.rs @@ -4,7 +4,7 @@ use super::Appservice; use crate::{services, Result}; /// All the getters and iterators from src/database/key_value/appservice.rs -pub(crate) async fn appservice(subcommand: Appservice) -> Result { +pub(super) async fn appservice(subcommand: Appservice) -> Result { match subcommand { Appservice::GetRegistration { appservice_id, diff --git a/src/admin/query/globals.rs b/src/admin/query/globals.rs index e5249118..bc8bcdef 100644 --- a/src/admin/query/globals.rs +++ b/src/admin/query/globals.rs @@ -4,7 +4,7 @@ use super::Globals; use crate::{services, Result}; /// All the getters and iterators from src/database/key_value/globals.rs -pub(crate) async fn globals(subcommand: Globals) -> Result { +pub(super) async fn globals(subcommand: Globals) -> Result { match subcommand { Globals::DatabaseVersion => { let timer = tokio::time::Instant::now(); diff --git a/src/admin/query/mod.rs b/src/admin/query/mod.rs index 2e5b0bb8..946e6ec8 100644 --- a/src/admin/query/mod.rs +++ b/src/admin/query/mod.rs @@ -1,13 +1,14 @@ -pub(crate) mod account_data; -pub(crate) mod appservice; -pub(crate) mod globals; -pub(crate) mod presence; -pub(crate) mod room_alias; -pub(crate) mod room_state_cache; -pub(crate) mod sending; -pub(crate) mod users; +mod account_data; +mod appservice; +mod globals; +mod presence; +mod room_alias; +mod room_state_cache; +mod sending; +mod users; use clap::Subcommand; +use conduit::Result; use room_state_cache::room_state_cache; use ruma::{ events::{room::message::RoomMessageEventContent, RoomAccountDataEventType}, @@ -18,12 +19,11 @@ use self::{ account_data::account_data, appservice::appservice, globals::globals, presence::presence, room_alias::room_alias, sending::sending, users::users, }; -use crate::Result; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// Query tables from database -pub(crate) enum QueryCommand { +pub(super) enum QueryCommand { /// - account_data.rs iterators and getters #[command(subcommand)] AccountData(AccountData), @@ -60,7 +60,7 @@ pub(crate) enum QueryCommand { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/account_data.rs -pub(crate) enum AccountData { +pub(super) enum AccountData { /// - Returns all changes to the account data that happened after `since`. ChangesSince { /// Full user ID @@ -85,7 +85,7 @@ pub(crate) enum AccountData { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/appservice.rs -pub(crate) enum Appservice { +pub(super) enum Appservice { /// - Gets the appservice registration info/details from the ID as a string GetRegistration { /// Appservice registration ID @@ -99,7 +99,7 @@ pub(crate) enum Appservice { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/presence.rs -pub(crate) enum Presence { +pub(super) enum Presence { /// - Returns the latest presence event for the given user. GetPresence { /// Full user ID @@ -117,7 +117,7 @@ pub(crate) enum Presence { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/rooms/alias.rs -pub(crate) enum RoomAlias { +pub(super) enum RoomAlias { ResolveLocalAlias { /// Full room alias alias: Box, @@ -135,7 +135,7 @@ pub(crate) enum RoomAlias { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomStateCache { +pub(super) enum RoomStateCache { ServerInRoom { server: Box, room_id: Box, @@ -208,7 +208,7 @@ pub(crate) enum RoomStateCache { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/globals.rs -pub(crate) enum Globals { +pub(super) enum Globals { DatabaseVersion, CurrentCount, @@ -227,7 +227,7 @@ pub(crate) enum Globals { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/sending.rs -pub(crate) enum Sending { +pub(super) enum Sending { /// - Queries database for all `servercurrentevent_data` ActiveRequests, @@ -283,12 +283,12 @@ pub(crate) enum Sending { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] /// All the getters and iterators from src/database/key_value/users.rs -pub(crate) enum Users { +pub(super) enum Users { Iter, } /// Processes admin query commands -pub(crate) async fn process(command: QueryCommand, _body: Vec<&str>) -> Result { +pub(super) async fn process(command: QueryCommand, _body: Vec<&str>) -> Result { Ok(match command { QueryCommand::AccountData(command) => account_data(command).await?, QueryCommand::Appservice(command) => appservice(command).await?, diff --git a/src/admin/query/presence.rs b/src/admin/query/presence.rs index f69dd19a..c54cad63 100644 --- a/src/admin/query/presence.rs +++ b/src/admin/query/presence.rs @@ -4,7 +4,7 @@ use super::Presence; use crate::{services, Result}; /// All the getters and iterators in key_value/presence.rs -pub(crate) async fn presence(subcommand: Presence) -> Result { +pub(super) async fn presence(subcommand: Presence) -> Result { match subcommand { Presence::GetPresence { user_id, diff --git a/src/admin/query/room_alias.rs b/src/admin/query/room_alias.rs index 62d05899..eaca285e 100644 --- a/src/admin/query/room_alias.rs +++ b/src/admin/query/room_alias.rs @@ -4,7 +4,7 @@ use super::RoomAlias; use crate::{services, Result}; /// All the getters and iterators in src/database/key_value/rooms/alias.rs -pub(crate) async fn room_alias(subcommand: RoomAlias) -> Result { +pub(super) async fn room_alias(subcommand: RoomAlias) -> Result { match subcommand { RoomAlias::ResolveLocalAlias { alias, diff --git a/src/admin/query/room_state_cache.rs b/src/admin/query/room_state_cache.rs index c062497e..63cf355f 100644 --- a/src/admin/query/room_state_cache.rs +++ b/src/admin/query/room_state_cache.rs @@ -3,7 +3,7 @@ use ruma::events::room::message::RoomMessageEventContent; use super::RoomStateCache; use crate::{services, Result}; -pub(crate) async fn room_state_cache(subcommand: RoomStateCache) -> Result { +pub(super) async fn room_state_cache(subcommand: RoomStateCache) -> Result { match subcommand { RoomStateCache::ServerInRoom { server, diff --git a/src/admin/query/sending.rs b/src/admin/query/sending.rs index 5a21ec87..8c52b45f 100644 --- a/src/admin/query/sending.rs +++ b/src/admin/query/sending.rs @@ -4,7 +4,7 @@ use super::Sending; use crate::{service::sending::Destination, services, Result}; /// All the getters and iterators in key_value/sending.rs -pub(crate) async fn sending(subcommand: Sending) -> Result { +pub(super) async fn sending(subcommand: Sending) -> Result { match subcommand { Sending::ActiveRequests => { let timer = tokio::time::Instant::now(); diff --git a/src/admin/query/users.rs b/src/admin/query/users.rs index ef99d880..7f0980ae 100644 --- a/src/admin/query/users.rs +++ b/src/admin/query/users.rs @@ -4,7 +4,7 @@ use super::Users; use crate::{services, Result}; /// All the getters and iterators in key_value/users.rs -pub(crate) async fn users(subcommand: Users) -> Result { +pub(super) async fn users(subcommand: Users) -> Result { match subcommand { Users::Iter => { let timer = tokio::time::Instant::now(); diff --git a/src/admin/room/mod.rs b/src/admin/room/mod.rs index ced96c95..72e72793 100644 --- a/src/admin/room/mod.rs +++ b/src/admin/room/mod.rs @@ -1,18 +1,18 @@ +mod room_alias_commands; +mod room_commands; +mod room_directory_commands; +mod room_info_commands; +mod room_moderation_commands; + use clap::Subcommand; +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, RoomId, RoomOrAliasId}; use self::room_commands::list; -use crate::Result; - -pub(crate) mod room_alias_commands; -pub(crate) mod room_commands; -pub(crate) mod room_directory_commands; -pub(crate) mod room_info_commands; -pub(crate) mod room_moderation_commands; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomCommand { +pub(super) enum RoomCommand { /// - List all rooms the server knows about List { page: Option, @@ -37,7 +37,7 @@ pub(crate) enum RoomCommand { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomInfoCommand { +pub(super) enum RoomInfoCommand { /// - List joined members in a room ListJoinedMembers { room_id: Box, @@ -54,7 +54,7 @@ pub(crate) enum RoomInfoCommand { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomAliasCommand { +pub(super) enum RoomAliasCommand { /// - Make an alias point to a room. Set { #[arg(short, long)] @@ -90,7 +90,7 @@ pub(crate) enum RoomAliasCommand { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomDirectoryCommand { +pub(super) enum RoomDirectoryCommand { /// - Publish a room to the room directory Publish { /// The room id of the room to publish @@ -111,7 +111,7 @@ pub(crate) enum RoomDirectoryCommand { #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum RoomModerationCommand { +pub(super) enum RoomModerationCommand { /// - Bans a room from local users joining and evicts all our local users /// from the room. Also blocks any invites (local and remote) for the /// banned room. @@ -167,7 +167,7 @@ pub(crate) enum RoomModerationCommand { ListBannedRooms, } -pub(crate) async fn process(command: RoomCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: RoomCommand, body: Vec<&str>) -> Result { Ok(match command { RoomCommand::Info(command) => room_info_commands::process(command, body).await?, diff --git a/src/admin/room/room_alias_commands.rs b/src/admin/room/room_alias_commands.rs index bde13e53..4f43ac6e 100644 --- a/src/admin/room/room_alias_commands.rs +++ b/src/admin/room/room_alias_commands.rs @@ -5,7 +5,7 @@ use ruma::{events::room::message::RoomMessageEventContent, RoomAliasId}; use super::RoomAliasCommand; use crate::{escape_html, services, Result}; -pub(crate) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Result { +pub(super) async fn process(command: RoomAliasCommand, _body: Vec<&str>) -> Result { let server_user = &services().globals.server_user; match command { diff --git a/src/admin/room/room_commands.rs b/src/admin/room/room_commands.rs index 50372e32..f64ccf30 100644 --- a/src/admin/room/room_commands.rs +++ b/src/admin/room/room_commands.rs @@ -4,7 +4,7 @@ use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; use crate::{escape_html, get_room_info, handler::PAGE_SIZE, services, Result}; -pub(crate) async fn list(_body: Vec<&str>, page: Option) -> Result { +pub(super) async fn list(_body: Vec<&str>, page: Option) -> Result { // TODO: i know there's a way to do this with clap, but i can't seem to find it let page = page.unwrap_or(1); let mut rooms = services() diff --git a/src/admin/room/room_directory_commands.rs b/src/admin/room/room_directory_commands.rs index 37c09791..5e81bd89 100644 --- a/src/admin/room/room_directory_commands.rs +++ b/src/admin/room/room_directory_commands.rs @@ -5,7 +5,7 @@ use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId}; use super::RoomDirectoryCommand; use crate::{escape_html, get_room_info, handler::PAGE_SIZE, services, Result}; -pub(crate) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) -> Result { +pub(super) async fn process(command: RoomDirectoryCommand, _body: Vec<&str>) -> Result { match command { RoomDirectoryCommand::Publish { room_id, diff --git a/src/admin/room/room_info_commands.rs b/src/admin/room/room_info_commands.rs index 0bcbc7ae..3b35d82c 100644 --- a/src/admin/room/room_info_commands.rs +++ b/src/admin/room/room_info_commands.rs @@ -6,7 +6,7 @@ use service::services; use super::RoomInfoCommand; use crate::{escape_html, Result}; -pub(crate) async fn process(command: RoomInfoCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: RoomInfoCommand, body: Vec<&str>) -> Result { match command { RoomInfoCommand::ListJoinedMembers { room_id, diff --git a/src/admin/room/room_moderation_commands.rs b/src/admin/room/room_moderation_commands.rs index 1876bf5e..095ccf61 100644 --- a/src/admin/room/room_moderation_commands.rs +++ b/src/admin/room/room_moderation_commands.rs @@ -9,7 +9,7 @@ use tracing::{debug, error, info, warn}; use super::{super::Service, RoomModerationCommand}; use crate::{escape_html, get_room_info, services, user_is_local, Result}; -pub(crate) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> Result { match command { RoomModerationCommand::BanRoom { force, diff --git a/src/admin/server/server_commands.rs b/src/admin/server/commands.rs similarity index 77% rename from src/admin/server/server_commands.rs rename to src/admin/server/commands.rs index 0e01d4bf..eb3ae20c 100644 --- a/src/admin/server/server_commands.rs +++ b/src/admin/server/commands.rs @@ -1,9 +1,9 @@ -use conduit::warn; +use conduit::{warn, Result}; use ruma::events::room::message::RoomMessageEventContent; -use crate::{services, Result}; +use crate::services; -pub(crate) async fn uptime(_body: Vec<&str>) -> Result { +pub(super) async fn uptime(_body: Vec<&str>) -> Result { let seconds = services() .server .started @@ -21,12 +21,12 @@ pub(crate) async fn uptime(_body: Vec<&str>) -> Result Ok(RoomMessageEventContent::notice_plain(result)) } -pub(crate) async fn show_config(_body: Vec<&str>) -> Result { +pub(super) async fn show_config(_body: Vec<&str>) -> Result { // Construct and send the response Ok(RoomMessageEventContent::text_plain(format!("{}", services().globals.config))) } -pub(crate) async fn memory_usage(_body: Vec<&str>) -> Result { +pub(super) async fn memory_usage(_body: Vec<&str>) -> Result { let response0 = services().memory_usage().await; let response1 = services().globals.db.memory_usage(); let response2 = conduit::alloc::memory_usage(); @@ -41,19 +41,19 @@ pub(crate) async fn memory_usage(_body: Vec<&str>) -> Result, amount: u32) -> Result { +pub(super) async fn clear_database_caches(_body: Vec<&str>, amount: u32) -> Result { services().globals.db.clear_caches(amount); Ok(RoomMessageEventContent::text_plain("Done.")) } -pub(crate) async fn clear_service_caches(_body: Vec<&str>, amount: u32) -> Result { +pub(super) async fn clear_service_caches(_body: Vec<&str>, amount: u32) -> Result { services().clear_caches(amount).await; Ok(RoomMessageEventContent::text_plain("Done.")) } -pub(crate) async fn list_backups(_body: Vec<&str>) -> Result { +pub(super) async fn list_backups(_body: Vec<&str>) -> Result { let result = services().globals.db.backup_list()?; if result.is_empty() { @@ -63,7 +63,7 @@ pub(crate) async fn list_backups(_body: Vec<&str>) -> Result) -> Result { +pub(super) async fn backup_database(_body: Vec<&str>) -> Result { if !cfg!(feature = "rocksdb") { return Ok(RoomMessageEventContent::text_plain( "Only RocksDB supports online backups in conduwuit.", @@ -87,7 +87,7 @@ pub(crate) async fn backup_database(_body: Vec<&str>) -> Result) -> Result { +pub(super) async fn list_database_files(_body: Vec<&str>) -> Result { if !cfg!(feature = "rocksdb") { return Ok(RoomMessageEventContent::text_plain( "Only RocksDB supports listing files in conduwuit.", @@ -98,7 +98,7 @@ pub(crate) async fn list_database_files(_body: Vec<&str>) -> Result, message: Vec) -> Result { +pub(super) async fn admin_notice(_body: Vec<&str>, message: Vec) -> Result { let message = message.join(" "); services().admin.send_text(&message).await; @@ -106,20 +106,20 @@ pub(crate) async fn admin_notice(_body: Vec<&str>, message: Vec) -> Resu } #[cfg(conduit_mods)] -pub(crate) async fn reload(_body: Vec<&str>) -> Result { +pub(super) async fn reload(_body: Vec<&str>) -> Result { services().server.reload()?; Ok(RoomMessageEventContent::notice_plain("Reloading server...")) } #[cfg(unix)] -pub(crate) async fn restart(_body: Vec<&str>) -> Result { +pub(super) async fn restart(_body: Vec<&str>) -> Result { services().server.restart()?; Ok(RoomMessageEventContent::notice_plain("Restarting server...")) } -pub(crate) async fn shutdown(_body: Vec<&str>) -> Result { +pub(super) async fn shutdown(_body: Vec<&str>) -> Result { warn!("shutdown command"); services().server.shutdown()?; diff --git a/src/admin/server/mod.rs b/src/admin/server/mod.rs index c3a517c0..13f6e265 100644 --- a/src/admin/server/mod.rs +++ b/src/admin/server/mod.rs @@ -1,14 +1,14 @@ -pub(crate) mod server_commands; +mod commands; use clap::Subcommand; +use conduit::Result; use ruma::events::room::message::RoomMessageEventContent; -use self::server_commands::*; -use crate::Result; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum ServerCommand { +pub(super) enum ServerCommand { /// - Time elapsed since startup Uptime, @@ -57,7 +57,7 @@ pub(crate) enum ServerCommand { Shutdown, } -pub(crate) async fn process(command: ServerCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: ServerCommand, body: Vec<&str>) -> Result { Ok(match command { ServerCommand::Uptime => uptime(body).await?, ServerCommand::ShowConfig => show_config(body).await?, diff --git a/src/admin/tester/mod.rs b/src/admin/tester/mod.rs index f7b4ecea..8350fe14 100644 --- a/src/admin/tester/mod.rs +++ b/src/admin/tester/mod.rs @@ -4,10 +4,10 @@ use crate::Result; #[cfg_attr(test, derive(Debug))] #[derive(clap::Subcommand)] -pub(crate) enum TesterCommands { +pub(super) enum TesterCommands { Tester, } -pub(crate) async fn process(command: TesterCommands, _body: Vec<&str>) -> Result { +pub(super) async fn process(command: TesterCommands, _body: Vec<&str>) -> Result { Ok(match command { TesterCommands::Tester => RoomMessageEventContent::notice_plain(String::from("completed")), }) diff --git a/src/admin/user/user_commands.rs b/src/admin/user/commands.rs similarity index 96% rename from src/admin/user/user_commands.rs rename to src/admin/user/commands.rs index cada5022..26ec1af5 100644 --- a/src/admin/user/user_commands.rs +++ b/src/admin/user/commands.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, fmt::Write as _}; use api::client::{join_room_by_id_helper, leave_all_rooms, update_avatar_url, update_displayname}; -use conduit::utils; +use conduit::{utils, Result}; use ruma::{ events::{ room::message::RoomMessageEventContent, @@ -15,12 +15,11 @@ use tracing::{error, info, warn}; use crate::{ escape_html, get_room_info, services, utils::{parse_active_local_user_id, parse_local_user_id}, - Result, }; const AUTO_GEN_PASSWORD_LENGTH: usize = 25; -pub(crate) async fn list(_body: Vec<&str>) -> Result { +pub(super) async fn list(_body: Vec<&str>) -> Result { match services().users.list_local_users() { Ok(users) => { let mut plain_msg = format!("Found {} local user account(s):\n```\n", users.len()); @@ -36,7 +35,7 @@ pub(crate) async fn list(_body: Vec<&str>) -> Result { } } -pub(crate) async fn create( +pub(super) async fn create( _body: Vec<&str>, username: String, password: Option, ) -> Result { // Validate user id @@ -127,7 +126,7 @@ pub(crate) async fn create( ))) } -pub(crate) async fn deactivate( +pub(super) async fn deactivate( _body: Vec<&str>, no_leave_rooms: bool, user_id: String, ) -> Result { // Validate user id @@ -166,7 +165,7 @@ pub(crate) async fn deactivate( ))) } -pub(crate) async fn reset_password(_body: Vec<&str>, username: String) -> Result { +pub(super) async fn reset_password(_body: Vec<&str>, username: String) -> Result { let user_id = parse_local_user_id(&username)?; if user_id == services().globals.server_user { @@ -190,7 +189,7 @@ pub(crate) async fn reset_password(_body: Vec<&str>, username: String) -> Result } } -pub(crate) async fn deactivate_all( +pub(super) async fn deactivate_all( body: Vec<&str>, no_leave_rooms: bool, force: bool, ) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { @@ -284,7 +283,7 @@ pub(crate) async fn deactivate_all( } } -pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Result { +pub(super) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Result { // Validate user id let user_id = parse_local_user_id(&user_id)?; @@ -335,7 +334,7 @@ pub(crate) async fn list_joined_rooms(_body: Vec<&str>, user_id: String) -> Resu Ok(RoomMessageEventContent::text_html(output_plain, output_html)) } -pub(crate) async fn put_room_tag( +pub(super) async fn put_room_tag( _body: Vec<&str>, user_id: String, room_id: Box, tag: String, ) -> Result { let user_id = parse_active_local_user_id(&user_id)?; @@ -370,7 +369,7 @@ pub(crate) async fn put_room_tag( ))) } -pub(crate) async fn delete_room_tag( +pub(super) async fn delete_room_tag( _body: Vec<&str>, user_id: String, room_id: Box, tag: String, ) -> Result { let user_id = parse_active_local_user_id(&user_id)?; @@ -402,7 +401,7 @@ pub(crate) async fn delete_room_tag( ))) } -pub(crate) async fn get_room_tags( +pub(super) async fn get_room_tags( _body: Vec<&str>, user_id: String, room_id: Box, ) -> Result { let user_id = parse_active_local_user_id(&user_id)?; diff --git a/src/admin/user/mod.rs b/src/admin/user/mod.rs index e11429de..31bf57d6 100644 --- a/src/admin/user/mod.rs +++ b/src/admin/user/mod.rs @@ -1,15 +1,14 @@ -pub(crate) mod user_commands; +mod commands; use clap::Subcommand; +use conduit::Result; use ruma::{events::room::message::RoomMessageEventContent, RoomId}; -use user_commands::{delete_room_tag, get_room_tags, put_room_tag}; -use self::user_commands::{create, deactivate, deactivate_all, list, list_joined_rooms, reset_password}; -use crate::Result; +use self::commands::*; #[cfg_attr(test, derive(Debug))] #[derive(Subcommand)] -pub(crate) enum UserCommand { +pub(super) enum UserCommand { /// - Create a new user Create { /// Username of the new user @@ -93,7 +92,7 @@ pub(crate) enum UserCommand { }, } -pub(crate) async fn process(command: UserCommand, body: Vec<&str>) -> Result { +pub(super) async fn process(command: UserCommand, body: Vec<&str>) -> Result { Ok(match command { UserCommand::List => list(body).await?, UserCommand::Create {