More reorg
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
70
src/app/admin/server.rs
Normal file
70
src/app/admin/server.rs
Normal 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,
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
20
src/main.rs
20
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 {
|
||||
|
||||
Reference in New Issue
Block a user