From 0218923390d4b3fe019370c078c1b7d7c0e9d7a3 Mon Sep 17 00:00:00 2001 From: JP Stringham Date: Fri, 6 Mar 2026 17:22:33 -0500 Subject: [PATCH] More reorg --- src/app/admin.rs | 2 +- src/app/admin/server.rs | 70 +++++++++++++++++++++++++++++++++++++++++ src/app/setup.rs | 9 ++++++ src/main.rs | 20 +++++++----- 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 src/app/admin/server.rs diff --git a/src/app/admin.rs b/src/app/admin.rs index 7b8a2f0..e06cf4a 100644 --- a/src/app/admin.rs +++ b/src/app/admin.rs @@ -1,4 +1,4 @@ -const SITE_CONFIG: &str = "/api/admin/v1/site-config"; +pub mod server; const USERS_ENDPT: &str = "/api/admin/v1/users"; const OAUTH_LINKS_ENDPT: &str = "/api/admin/v1/upstream-oauth-links"; diff --git a/src/app/admin/server.rs b/src/app/admin/server.rs new file mode 100644 index 0000000..ce22a18 --- /dev/null +++ b/src/app/admin/server.rs @@ -0,0 +1,70 @@ +const SITE_CONFIG: &str = "/api/admin/v1/site-config"; +const VERSION_ENDPT: &str = "/api/admin/v1/version"; + +use clap::Subcommand; + +use crate::json_types::prettify_json_str; + +use super::super::App; + +impl App { + pub fn show_site_config(&self) { + let auth_token = self + .auth_token + .as_ref() + .expect("Need auth token to perform this action"); + + let url = format!("{}{SITE_CONFIG}", self.mas_base_url); + + let client = reqwest::blocking::Client::new(); + + let req = client + .get(url) + .header("Accept", "application/json") + .header( + "Authorization", + format!("Bearer {}", auth_token.access_token.clone()), + ) + .header("Content-Type", "application/json"); + + // println!("Req {:?}", req); + + let res = req.send().unwrap(); + + let json = prettify_json_str(res.text().unwrap().as_str()).unwrap(); + println!("{}", json); + } + + pub fn show_version(&self) { + let auth_token = self + .auth_token + .as_ref() + .expect("Need auth token to perform this action"); + + let url = format!("{}{VERSION_ENDPT}", self.mas_base_url); + + let client = reqwest::blocking::Client::new(); + + let req = client + .get(url) + .header("Accept", "application/json") + .header( + "Authorization", + format!("Bearer {}", auth_token.access_token.clone()), + ) + .header("Content-Type", "application/json"); + + // println!("Req {:?}", req); + + let res = req.send().unwrap(); + + let json = prettify_json_str(res.text().unwrap().as_str()).unwrap(); + println!("{}", json); + } +} + +#[derive(Debug, Subcommand, PartialEq, Eq)] +pub enum ServerCommands { + ShowSiteConfig, + ShowVersion, +} diff --git a/src/app/setup.rs b/src/app/setup.rs index 27ab3a8..92d1941 100644 --- a/src/app/setup.rs +++ b/src/app/setup.rs @@ -3,6 +3,7 @@ use super::App; use std::time::{Duration, Instant}; use crate::json_types::*; +use clap::Subcommand; use reqwest::StatusCode; impl App { @@ -185,3 +186,11 @@ impl App { self.auth_token = Some(token); } } + +#[derive(Debug, Subcommand, PartialEq, Eq)] +pub enum SetupCommands { + GetAuthMetadata, + RegisterClient, + AuthorizeDevice, + RefreshAuth, +} diff --git a/src/main.rs b/src/main.rs index 986689b..24c3e5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,9 +14,8 @@ use std::io::Write; use clap::{CommandFactory, Parser, Subcommand}; use colored::{ColoredString, Colorize}; -use enum_iterator::Sequence; -use crate::app::App; +use crate::app::{App, admin::server::ServerCommands, setup::SetupCommands}; // google oauth // 754241279547-kk48of2t6eu5vol85hn6op3ofpp3em76.apps.googleusercontent.com @@ -84,6 +83,10 @@ fn main() { match cli.command { Commands::Setup(_) => unreachable!("Blocked by above match"), + Commands::Server(sub) => match sub.command { + ServerCommands::ShowSiteConfig => app.show_site_config(), + ServerCommands::ShowVersion => app.show_version(), + }, Commands::ShowOauthLinks => app.show_oauth_links(), } } @@ -122,6 +125,9 @@ enum Commands { #[command(subcommand_help_heading = "Setup Auth for Admin API")] #[command(arg_required_else_help = true)] Setup(SetupCommandArgs), + #[command(subcommand_help_heading = "Get site config and version")] + #[command(arg_required_else_help = true)] + Server(ServerCommandArgs), ShowOauthLinks, } @@ -131,12 +137,10 @@ struct SetupCommandArgs { command: SetupCommands, } -#[derive(Debug, Subcommand, PartialEq, Eq, Sequence)] -enum SetupCommands { - GetAuthMetadata, - RegisterClient, - AuthorizeDevice, - RefreshAuth, +#[derive(Debug, Parser)] +struct ServerCommandArgs { + #[command(subcommand)] + command: ServerCommands, } fn quick_format_bool(b: bool) -> ColoredString {