Files
continuwuity/src/admin/admin.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
2.9 KiB
Rust
Raw Normal View History

2024-07-22 22:24:17 +00:00
use clap::Parser;
2026-06-29 21:58:45 -04:00
use conduwuit::{Err, Result};
2024-07-22 22:24:17 +00:00
use crate::{
appservice::{self, AppserviceCommand},
check::{self, CheckCommand},
context::Context,
debug::{self, DebugCommand},
federation::{self, FederationCommand},
media::{self, MediaCommand},
2026-06-29 21:58:45 -04:00
oidc::{self, OidcCommand},
query::{self, QueryCommand},
room::{self, RoomCommand},
server::{self, ServerCommand},
token::{self, TokenCommand},
user::{self, UserCommand},
2024-07-22 22:24:17 +00:00
};
#[derive(Debug, Parser)]
#[command(name = conduwuit_core::BRANDING, version = conduwuit_core::version())]
2025-05-24 00:28:09 +01:00
pub enum AdminCommand {
/// Commands for managing appservices
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Appservices(AppserviceCommand),
/// Commands for managing local users
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Users(UserCommand),
/// Commands for managing registration tokens
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
Token(TokenCommand),
2026-06-30 09:42:47 -04:00
/// Commands for managing OIDC
2026-06-29 21:58:45 -04:00
#[command(subcommand)]
Oidc(OidcCommand),
/// Commands for managing rooms
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Rooms(RoomCommand),
/// Commands for managing federation
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Federation(FederationCommand),
/// Commands for managing the server
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Server(ServerCommand),
/// Commands for managing media
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Media(MediaCommand),
/// Commands for checking integrity
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Check(CheckCommand),
/// Commands for debugging things
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Debug(DebugCommand),
/// Low-level queries for database getters and iterators
2026-06-30 09:42:47 -04:00
#[command(subcommand)]
2024-07-22 22:24:17 +00:00
Query(QueryCommand),
}
2026-01-04 03:04:37 +00:00
#[tracing::instrument(skip_all, name = "command", level = "info")]
pub(super) async fn process(command: AdminCommand, context: &Context<'_>) -> Result {
2024-07-27 00:11:41 +00:00
use AdminCommand::*;
2024-07-22 22:24:17 +00:00
2025-01-04 16:57:07 +00:00
match command {
| Appservices(command) => {
// appservice commands are all restricted
context.bail_restricted()?;
appservice::process(command, context).await
},
| Media(command) => media::process(command, context).await,
| Users(command) => {
// user commands are all restricted
context.bail_restricted()?;
user::process(command, context).await
},
| Token(command) => {
// token commands are all restricted
context.bail_restricted()?;
token::process(command, context).await
},
2026-06-29 21:58:45 -04:00
| Oidc(command) => {
// OIDC commands are all restricted
context.bail_restricted()?;
if !context.services.oidc.enabled() {
return Err!("OIDC is not configured");
}
oidc::process(command, context).await
},
| Rooms(command) => room::process(command, context).await,
| Federation(command) => federation::process(command, context).await,
| Server(command) => server::process(command, context).await,
| Debug(command) => debug::process(command, context).await,
| Query(command) => {
// query commands are all restricted
context.bail_restricted()?;
query::process(command, context).await
},
| Check(command) => check::process(command, context).await,
2025-02-25 18:38:12 +00:00
}
2024-07-22 22:24:17 +00:00
}