Skip to main content

tuwunel_admin/query/
globals.rs

1use clap::Subcommand;
2use ruma::OwnedServerName;
3use tuwunel_core::Result;
4
5use crate::Context;
6
7#[derive(Debug, Subcommand)]
8/// All the getters and iterators from src/service/globals/
9pub(crate) enum GlobalsCommand {
10	DatabaseVersion,
11
12	CurrentCount,
13
14	/// - This returns an empty `Ok(BTreeMap<..>)` when there are no keys found
15	///   for the server.
16	SigningKeysFor {
17		origin: OwnedServerName,
18	},
19}
20
21/// All the getters and iterators from src/service/globals/
22pub(super) async fn process(subcommand: GlobalsCommand, context: &Context<'_>) -> Result {
23	let services = context.services;
24
25	match subcommand {
26		| GlobalsCommand::DatabaseVersion => {
27			let timer = tokio::time::Instant::now();
28			let results = services.globals.db.database_version().await;
29			let query_time = timer.elapsed();
30
31			write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
32		},
33		| GlobalsCommand::CurrentCount => {
34			let timer = tokio::time::Instant::now();
35			let results = services.globals.current_count();
36			let query_time = timer.elapsed();
37
38			write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
39		},
40		| GlobalsCommand::SigningKeysFor { origin } => {
41			let timer = tokio::time::Instant::now();
42			let results = services
43				.server_keys
44				.verify_keys_for(&origin)
45				.await;
46			let query_time = timer.elapsed();
47
48			write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
49		},
50	}
51	.await
52}