More reorg

This commit is contained in:
JP Stringham
2026-03-06 17:22:33 -05:00
parent 9c32cb6245
commit 0218923390
4 changed files with 92 additions and 9 deletions

View File

@@ -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 USERS_ENDPT: &str = "/api/admin/v1/users";
const OAUTH_LINKS_ENDPT: &str = "/api/admin/v1/upstream-oauth-links"; const OAUTH_LINKS_ENDPT: &str = "/api/admin/v1/upstream-oauth-links";

70
src/app/admin/server.rs Normal file
View File

@@ -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,
}

View File

@@ -3,6 +3,7 @@ use super::App;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use crate::json_types::*; use crate::json_types::*;
use clap::Subcommand;
use reqwest::StatusCode; use reqwest::StatusCode;
impl App { impl App {
@@ -185,3 +186,11 @@ impl App {
self.auth_token = Some(token); self.auth_token = Some(token);
} }
} }
#[derive(Debug, Subcommand, PartialEq, Eq)]
pub enum SetupCommands {
GetAuthMetadata,
RegisterClient,
AuthorizeDevice,
RefreshAuth,
}

View File

@@ -14,9 +14,8 @@ use std::io::Write;
use clap::{CommandFactory, Parser, Subcommand}; use clap::{CommandFactory, Parser, Subcommand};
use colored::{ColoredString, Colorize}; use colored::{ColoredString, Colorize};
use enum_iterator::Sequence;
use crate::app::App; use crate::app::{App, admin::server::ServerCommands, setup::SetupCommands};
// google oauth // google oauth
// 754241279547-kk48of2t6eu5vol85hn6op3ofpp3em76.apps.googleusercontent.com // 754241279547-kk48of2t6eu5vol85hn6op3ofpp3em76.apps.googleusercontent.com
@@ -84,6 +83,10 @@ fn main() {
match cli.command { match cli.command {
Commands::Setup(_) => unreachable!("Blocked by above match"), 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(), Commands::ShowOauthLinks => app.show_oauth_links(),
} }
} }
@@ -122,6 +125,9 @@ enum Commands {
#[command(subcommand_help_heading = "Setup Auth for Admin API")] #[command(subcommand_help_heading = "Setup Auth for Admin API")]
#[command(arg_required_else_help = true)] #[command(arg_required_else_help = true)]
Setup(SetupCommandArgs), Setup(SetupCommandArgs),
#[command(subcommand_help_heading = "Get site config and version")]
#[command(arg_required_else_help = true)]
Server(ServerCommandArgs),
ShowOauthLinks, ShowOauthLinks,
} }
@@ -131,12 +137,10 @@ struct SetupCommandArgs {
command: SetupCommands, command: SetupCommands,
} }
#[derive(Debug, Subcommand, PartialEq, Eq, Sequence)] #[derive(Debug, Parser)]
enum SetupCommands { struct ServerCommandArgs {
GetAuthMetadata, #[command(subcommand)]
RegisterClient, command: ServerCommands,
AuthorizeDevice,
RefreshAuth,
} }
fn quick_format_bool(b: bool) -> ColoredString { fn quick_format_bool(b: bool) -> ColoredString {