More reorg, ready to start adding more commands
This commit is contained in:
11
src/app.rs
11
src/app.rs
@@ -23,6 +23,12 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn admin_api_ready(&self) -> bool {
|
||||||
|
self.auth_metadata.is_some()
|
||||||
|
&& self.client_registration.is_some()
|
||||||
|
&& self.auth_token.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_status(&self) {
|
pub fn print_status(&self) {
|
||||||
println!("\nApp Base URL: {}", self.matrix_base_url);
|
println!("\nApp Base URL: {}", self.matrix_base_url);
|
||||||
println!(
|
println!(
|
||||||
@@ -33,5 +39,10 @@ impl App {
|
|||||||
"Client Reg? {}",
|
"Client Reg? {}",
|
||||||
crate::quick_format_bool(self.client_registration.is_some())
|
crate::quick_format_bool(self.client_registration.is_some())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Admin API Ready? {}",
|
||||||
|
crate::quick_format_bool(self.admin_api_ready())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
src/main.rs
70
src/main.rs
@@ -32,7 +32,6 @@ fn main() {
|
|||||||
print!("\x1B[2J\x1B[2;5H");
|
print!("\x1B[2J\x1B[2;5H");
|
||||||
println!("{}", "Welcome to auth tools CLI".bright_cyan());
|
println!("{}", "Welcome to auth tools CLI".bright_cyan());
|
||||||
println!("{} {MATRIX_SERVER_BASE_URL}\n\n", "Homeserver:".green());
|
println!("{} {MATRIX_SERVER_BASE_URL}\n\n", "Homeserver:".green());
|
||||||
print_menu();
|
|
||||||
|
|
||||||
let mut app = App::new(MATRIX_SERVER_BASE_URL, MAS_SERVER_BASE_URL);
|
let mut app = App::new(MATRIX_SERVER_BASE_URL, MAS_SERVER_BASE_URL);
|
||||||
app.get_auth_metadata();
|
app.get_auth_metadata();
|
||||||
@@ -40,6 +39,8 @@ fn main() {
|
|||||||
|
|
||||||
app.print_status();
|
app.print_status();
|
||||||
|
|
||||||
|
print_menu();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let input = readline().unwrap();
|
let input = readline().unwrap();
|
||||||
let input = input.trim();
|
let input = input.trim();
|
||||||
@@ -61,68 +62,31 @@ fn main() {
|
|||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Setup(sub_args) => {
|
Commands::Setup(sub_args) => {
|
||||||
println!("subargs: {:?}", sub_args);
|
|
||||||
|
|
||||||
match sub_args.command {
|
match sub_args.command {
|
||||||
SetupCommands::GetAuthMetadata => app.get_auth_metadata(),
|
SetupCommands::GetAuthMetadata => app.get_auth_metadata(),
|
||||||
SetupCommands::RegisterClient => app.register_client(),
|
SetupCommands::RegisterClient => app.register_client(),
|
||||||
SetupCommands::AuthorizeDevice => app.authorize_device(),
|
SetupCommands::AuthorizeDevice => app.authorize_device(),
|
||||||
SetupCommands::RefreshAuth => app.refresh_auth(),
|
SetupCommands::RefreshAuth => app.refresh_auth(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
|
if !app.admin_api_ready() {
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
"Admin API not ready; please use setup subcommand first".red()
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match cli.command {
|
||||||
|
Commands::Setup(_) => unreachable!("Blocked by above match"),
|
||||||
Commands::ShowOauthLinks => app.show_oauth_links(),
|
Commands::ShowOauthLinks => app.show_oauth_links(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// todo!("nope");
|
|
||||||
|
|
||||||
// let req = client
|
|
||||||
// .post(format!(
|
|
||||||
// "{base_url}{USERS_ENDPT}/01KJXZRB1FSNNQ22DDC0368V9G/deactivate"
|
|
||||||
// ))
|
|
||||||
// .header("Accept", "application/json")
|
|
||||||
// .header("Authorization", access_token)
|
|
||||||
// .header("Content-Type", "application/json")
|
|
||||||
// .body(include_str!("../deactivate.json"));
|
|
||||||
// let req = client
|
|
||||||
// .post(format!("{base_url}{REGISTRATION_TOKENS_ENDPOINT}/new"))
|
|
||||||
// .header("Authorization", format!("Bearer {access_token}"))
|
|
||||||
// .body("{}");
|
|
||||||
// let req = client.get(format!("{base_url}{USERS_ENDPOINT_V3}")).header(
|
|
||||||
// "Authorization",
|
|
||||||
// "Bearer syt_anA_YRbjQUlvKVDuAfIDIdPW_0k2VVC",
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let req = client
|
|
||||||
// .put(format!(
|
|
||||||
// "{base_url}{USERS_ENDPOINT_V2}/@afriend:supersaturn.space"
|
|
||||||
// ))
|
|
||||||
// .header("Authorization", "))
|
|
||||||
// .body(include_str!("../postbody.json"));
|
|
||||||
|
|
||||||
// println!("{:?}", req);
|
|
||||||
|
|
||||||
// let req = req.send().unwrap();
|
|
||||||
|
|
||||||
// match req.status() {
|
|
||||||
// StatusCode::OK | StatusCode::NO_CONTENT | StatusCode::CREATED => (),
|
|
||||||
// StatusCode::UNAUTHORIZED => {
|
|
||||||
// if !req.text().unwrap().contains("token expired") {
|
|
||||||
// panic!("Not authorized: {}", req.text().unwrap());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let req = client.get(format!("{MAS_SERVER_BASE_URL}{TOKEN_ENDPT}"));
|
|
||||||
// }
|
|
||||||
// sc => panic!("Bad response?\n{}\n{:?}", sc, req.text()),
|
|
||||||
// };
|
|
||||||
// let req_txt = req.text().unwrap();
|
|
||||||
|
|
||||||
// // println!("{}", &req_txt);
|
|
||||||
|
|
||||||
// let txt = prettify_json_str(&req_txt);
|
|
||||||
// println!("Blocking req status\n\n{}\n\n", txt.unwrap());
|
|
||||||
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MENU_HELP_TEMPLATE: &str = "\
|
const MENU_HELP_TEMPLATE: &str = "\
|
||||||
|
|||||||
Reference in New Issue
Block a user