CLI account management + Directory refactoring
This commit is contained in:
@@ -21,42 +21,20 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
use jmap_client::client::Credentials;
|
||||
use reqwest::header::AUTHORIZATION;
|
||||
use reqwest::Method;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{cli::DatabaseCommands, is_localhost, UnwrapResult};
|
||||
use super::cli::{Client, DatabaseCommands};
|
||||
|
||||
pub async fn cmd_database(url: &str, credentials: Credentials, command: DatabaseCommands) {
|
||||
let url = match command {
|
||||
DatabaseCommands::Delete { account } => format!("{}/admin/account/delete/{}", url, account),
|
||||
DatabaseCommands::Rename {
|
||||
account,
|
||||
new_account,
|
||||
} => format!("{}/admin/account/rename/{}/{}", url, account, new_account),
|
||||
DatabaseCommands::Purge {} => format!("{}/admin/blob/purge", url),
|
||||
};
|
||||
|
||||
let response = reqwest::Client::builder()
|
||||
.danger_accept_invalid_certs(is_localhost(&url))
|
||||
.build()
|
||||
.unwrap_or_default()
|
||||
.get(url)
|
||||
.header(
|
||||
AUTHORIZATION,
|
||||
match credentials {
|
||||
Credentials::Basic(s) => format!("Basic {s}"),
|
||||
Credentials::Bearer(s) => format!("Bearer {s}"),
|
||||
},
|
||||
)
|
||||
.send()
|
||||
.await
|
||||
.unwrap_result("send GET request");
|
||||
if response.status().is_success() {
|
||||
eprintln!("Success.");
|
||||
} else {
|
||||
eprintln!(
|
||||
"Request Failed: {}",
|
||||
response.text().await.unwrap_result("fetch text")
|
||||
);
|
||||
impl DatabaseCommands {
|
||||
pub async fn exec(self, client: Client) {
|
||||
match self {
|
||||
DatabaseCommands::Maintenance {} => {
|
||||
client
|
||||
.http_request::<Value, String>(Method::GET, "/admin/store/maintenance", None)
|
||||
.await;
|
||||
eprintln!("Success.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user