cli: backup manager: rust fmt

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-10 17:50:35 +02:00
parent 6082d75966
commit 4ad118c613
16 changed files with 305 additions and 303 deletions

View File

@ -4,19 +4,19 @@ use std::io::{self, Write};
use anyhow::Error; use anyhow::Error;
use serde_json::{json, Value}; use serde_json::{json, Value};
use proxmox_sys::fs::CreateOptions;
use proxmox_router::{cli::*, RpcEnvironment}; use proxmox_router::{cli::*, RpcEnvironment};
use proxmox_schema::api; use proxmox_schema::api;
use proxmox_sys::fs::CreateOptions;
use pbs_api_types::percent_encoding::percent_encode_component;
use pbs_api_types::{
GroupFilter, SyncJobConfig, DATASTORE_SCHEMA, GROUP_FILTER_LIST_SCHEMA,
IGNORE_VERIFIED_BACKUPS_SCHEMA, REMOTE_ID_SCHEMA, REMOVE_VANISHED_BACKUPS_SCHEMA, UPID_SCHEMA,
VERIFICATION_OUTDATED_AFTER_SCHEMA,
};
use pbs_client::{display_task_log, view_task_result}; use pbs_client::{display_task_log, view_task_result};
use pbs_config::sync; use pbs_config::sync;
use pbs_tools::json::required_string_param; use pbs_tools::json::required_string_param;
use pbs_api_types::percent_encoding::percent_encode_component;
use pbs_api_types::{
GroupFilter, SyncJobConfig,
DATASTORE_SCHEMA, GROUP_FILTER_LIST_SCHEMA, IGNORE_VERIFIED_BACKUPS_SCHEMA, REMOTE_ID_SCHEMA,
REMOVE_VANISHED_BACKUPS_SCHEMA, UPID_SCHEMA, VERIFICATION_OUTDATED_AFTER_SCHEMA,
};
use proxmox_rest_server::wait_for_local_worker; use proxmox_rest_server::wait_for_local_worker;
@ -42,7 +42,6 @@ use proxmox_backup_manager::*;
)] )]
/// Start garbage collection for a specific datastore. /// Start garbage collection for a specific datastore.
async fn start_garbage_collection(param: Value) -> Result<Value, Error> { async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let store = required_string_param(&param, "store")?; let store = required_string_param(&param, "store")?;
@ -73,7 +72,6 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
)] )]
/// Show garbage collection status for a specific datastore. /// Show garbage collection status for a specific datastore.
async fn garbage_collection_status(param: Value) -> Result<Value, Error> { async fn garbage_collection_status(param: Value) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let store = required_string_param(&param, "store")?; let store = required_string_param(&param, "store")?;
@ -94,17 +92,18 @@ async fn garbage_collection_status(param: Value) -> Result<Value, Error> {
} }
fn garbage_collection_commands() -> CommandLineInterface { fn garbage_collection_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("status", .insert(
"status",
CliCommand::new(&API_METHOD_GARBAGE_COLLECTION_STATUS) CliCommand::new(&API_METHOD_GARBAGE_COLLECTION_STATUS)
.arg_param(&["store"]) .arg_param(&["store"])
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name),
) )
.insert("start", .insert(
"start",
CliCommand::new(&API_METHOD_START_GARBAGE_COLLECTION) CliCommand::new(&API_METHOD_START_GARBAGE_COLLECTION)
.arg_param(&["store"]) .arg_param(&["store"])
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name),
); );
cmd_def.into() cmd_def.into()
@ -135,7 +134,6 @@ fn garbage_collection_commands() -> CommandLineInterface {
)] )]
/// List running server tasks. /// List running server tasks.
async fn task_list(param: Value) -> Result<Value, Error> { async fn task_list(param: Value) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
@ -147,15 +145,25 @@ async fn task_list(param: Value) -> Result<Value, Error> {
"start": 0, "start": 0,
"limit": limit, "limit": limit,
}); });
let mut result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?; let mut result = client
.get("api2/json/nodes/localhost/tasks", Some(args))
.await?;
let mut data = result["data"].take(); let mut data = result["data"].take();
let return_type = &api2::node::tasks::API_METHOD_LIST_TASKS.returns; let return_type = &api2::node::tasks::API_METHOD_LIST_TASKS.returns;
use pbs_tools::format::{render_epoch, render_task_status}; use pbs_tools::format::{render_epoch, render_task_status};
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("starttime").right_align(false).renderer(render_epoch)) .column(
.column(ColumnConfig::new("endtime").right_align(false).renderer(render_epoch)) ColumnConfig::new("starttime")
.right_align(false)
.renderer(render_epoch),
)
.column(
ColumnConfig::new("endtime")
.right_align(false)
.renderer(render_epoch),
)
.column(ColumnConfig::new("upid")) .column(ColumnConfig::new("upid"))
.column(ColumnConfig::new("status").renderer(render_task_status)); .column(ColumnConfig::new("status").renderer(render_task_status));
@ -175,7 +183,6 @@ async fn task_list(param: Value) -> Result<Value, Error> {
)] )]
/// Display the task log. /// Display the task log.
async fn task_log(param: Value) -> Result<Value, Error> { async fn task_log(param: Value) -> Result<Value, Error> {
let upid = required_string_param(&param, "upid")?; let upid = required_string_param(&param, "upid")?;
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
@ -196,24 +203,23 @@ async fn task_log(param: Value) -> Result<Value, Error> {
)] )]
/// Try to stop a specific task. /// Try to stop a specific task.
async fn task_stop(param: Value) -> Result<Value, Error> { async fn task_stop(param: Value) -> Result<Value, Error> {
let upid_str = required_string_param(&param, "upid")?; let upid_str = required_string_param(&param, "upid")?;
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
let path = format!("api2/json/nodes/localhost/tasks/{}", percent_encode_component(upid_str)); let path = format!(
"api2/json/nodes/localhost/tasks/{}",
percent_encode_component(upid_str)
);
let _ = client.delete(&path, None).await?; let _ = client.delete(&path, None).await?;
Ok(Value::Null) Ok(Value::Null)
} }
fn task_mgmt_cli() -> CommandLineInterface { fn task_mgmt_cli() -> CommandLineInterface {
let task_log_cmd_def = CliCommand::new(&API_METHOD_TASK_LOG).arg_param(&["upid"]);
let task_log_cmd_def = CliCommand::new(&API_METHOD_TASK_LOG) let task_stop_cmd_def = CliCommand::new(&API_METHOD_TASK_STOP).arg_param(&["upid"]);
.arg_param(&["upid"]);
let task_stop_cmd_def = CliCommand::new(&API_METHOD_TASK_STOP)
.arg_param(&["upid"]);
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_TASK_LIST)) .insert("list", CliCommand::new(&API_METHOD_TASK_LIST))
@ -260,7 +266,6 @@ async fn pull_datastore(
group_filter: Option<Vec<GroupFilter>>, group_filter: Option<Vec<GroupFilter>>,
param: Value, param: Value,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
@ -308,11 +313,7 @@ async fn pull_datastore(
} }
)] )]
/// Verify backups /// Verify backups
async fn verify( async fn verify(store: String, mut param: Value) -> Result<Value, Error> {
store: String,
mut param: Value,
) -> Result<Value, Error> {
let output_format = extract_output_format(&mut param); let output_format = extract_output_format(&mut param);
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
@ -357,15 +358,18 @@ async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let packages = crate::api2::node::apt::get_versions()?; let packages = crate::api2::node::apt::get_versions()?;
let mut packages = json!(if verbose { &packages[..] } else { &packages[1..2] }); let mut packages = json!(if verbose {
&packages[..]
} else {
&packages[1..2]
});
let options = default_table_format_options() let options = default_table_format_options()
.disable_sort() .disable_sort()
.noborder(true) // just not helpful for version info which gets copy pasted often .noborder(true) // just not helpful for version info which gets copy pasted often
.column(ColumnConfig::new("Package")) .column(ColumnConfig::new("Package"))
.column(ColumnConfig::new("Version")) .column(ColumnConfig::new("Version"))
.column(ColumnConfig::new("ExtraInfo").header("Extra Info")) .column(ColumnConfig::new("ExtraInfo").header("Extra Info"));
;
let return_type = &crate::api2::node::apt::API_METHOD_GET_VERSIONS.returns; let return_type = &crate::api2::node::apt::API_METHOD_GET_VERSIONS.returns;
format_and_print_result_full(&mut packages, return_type, &output_format, &options); format_and_print_result_full(&mut packages, return_type, &output_format, &options);
@ -374,7 +378,6 @@ async fn get_versions(verbose: bool, param: Value) -> Result<Value, Error> {
} }
async fn run() -> Result<(), Error> { async fn run() -> Result<(), Error> {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("acl", acl_commands()) .insert("acl", acl_commands())
.insert("datastore", datastore_commands()) .insert("datastore", datastore_commands())
@ -397,33 +400,40 @@ async fn run() -> Result<(), Error> {
"pull", "pull",
CliCommand::new(&API_METHOD_PULL_DATASTORE) CliCommand::new(&API_METHOD_PULL_DATASTORE)
.arg_param(&["remote", "remote-store", "local-store"]) .arg_param(&["remote", "remote-store", "local-store"])
.completion_cb("local-store", pbs_config::datastore::complete_datastore_name) .completion_cb(
"local-store",
pbs_config::datastore::complete_datastore_name,
)
.completion_cb("remote", pbs_config::remote::complete_remote_name) .completion_cb("remote", pbs_config::remote::complete_remote_name)
.completion_cb("remote-store", complete_remote_datastore_name) .completion_cb("remote-store", complete_remote_datastore_name)
.completion_cb("group_filter", complete_remote_datastore_group_filter) .completion_cb("group_filter", complete_remote_datastore_group_filter),
) )
.insert( .insert(
"verify", "verify",
CliCommand::new(&API_METHOD_VERIFY) CliCommand::new(&API_METHOD_VERIFY)
.arg_param(&["store"]) .arg_param(&["store"])
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name),
) )
.insert("report", .insert("report", CliCommand::new(&API_METHOD_REPORT))
CliCommand::new(&API_METHOD_REPORT) .insert("versions", CliCommand::new(&API_METHOD_GET_VERSIONS));
)
.insert("versions",
CliCommand::new(&API_METHOD_GET_VERSIONS)
);
let args: Vec<String> = std::env::args().take(2).collect(); let args: Vec<String> = std::env::args().take(2).collect();
let avoid_init = args.len() >= 2 && (args[1] == "bashcomplete" || args[1] == "printdoc"); let avoid_init = args.len() >= 2 && (args[1] == "bashcomplete" || args[1] == "printdoc");
if !avoid_init { if !avoid_init {
let backup_user = pbs_config::backup_user()?; let backup_user = pbs_config::backup_user()?;
let file_opts = CreateOptions::new().owner(backup_user.uid).group(backup_user.gid); let file_opts = CreateOptions::new()
proxmox_rest_server::init_worker_tasks(pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(), file_opts)?; .owner(backup_user.uid)
.group(backup_user.gid);
proxmox_rest_server::init_worker_tasks(
pbs_buildcfg::PROXMOX_BACKUP_LOG_DIR_M!().into(),
file_opts,
)?;
let mut commando_sock = proxmox_rest_server::CommandSocket::new(proxmox_rest_server::our_ctrl_sock(), backup_user.gid); let mut commando_sock = proxmox_rest_server::CommandSocket::new(
proxmox_rest_server::our_ctrl_sock(),
backup_user.gid,
);
proxmox_rest_server::register_task_control_commands(&mut commando_sock)?; proxmox_rest_server::register_task_control_commands(&mut commando_sock)?;
commando_sock.spawn()?; commando_sock.spawn()?;
} }
@ -437,7 +447,6 @@ async fn run() -> Result<(), Error> {
} }
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
proxmox_backup::tools::setup_safe_path_env(); proxmox_backup::tools::setup_safe_path_env();
proxmox_async::runtime::main(run()) proxmox_async::runtime::main(run())
@ -450,10 +459,7 @@ fn get_sync_job(id: &String) -> Result<SyncJobConfig, Error> {
} }
fn get_remote(param: &HashMap<String, String>) -> Option<String> { fn get_remote(param: &HashMap<String, String>) -> Option<String> {
param param.get("remote").map(|r| r.to_owned()).or_else(|| {
.get("remote")
.map(|r| r.to_owned())
.or_else(|| {
if let Some(id) = param.get("id") { if let Some(id) = param.get("id") {
if let Ok(job) = get_sync_job(id) { if let Ok(job) = get_sync_job(id) {
return Some(job.remote); return Some(job.remote);
@ -466,10 +472,7 @@ fn get_remote(param: &HashMap<String, String>) -> Option<String> {
fn get_remote_store(param: &HashMap<String, String>) -> Option<(String, String)> { fn get_remote_store(param: &HashMap<String, String>) -> Option<(String, String)> {
let mut job: Option<SyncJobConfig> = None; let mut job: Option<SyncJobConfig> = None;
let remote = param let remote = param.get("remote").map(|r| r.to_owned()).or_else(|| {
.get("remote")
.map(|r| r.to_owned())
.or_else(|| {
if let Some(id) = param.get("id") { if let Some(id) = param.get("id") {
job = get_sync_job(id).ok(); job = get_sync_job(id).ok();
if let Some(ref job) = job { if let Some(ref job) = job {
@ -486,7 +489,7 @@ fn get_remote_store(param: &HashMap<String, String>) -> Option<(String, String)>
.or_else(|| job.map(|job| job.remote_store)); .or_else(|| job.map(|job| job.remote_store));
if let Some(store) = store { if let Some(store) = store {
return Some((remote, store)) return Some((remote, store));
} }
} }
@ -495,14 +498,12 @@ fn get_remote_store(param: &HashMap<String, String>) -> Option<(String, String)>
// shell completion helper // shell completion helper
pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String>) -> Vec<String> { pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
let mut list = Vec::new(); let mut list = Vec::new();
if let Some(remote) = get_remote(param) { if let Some(remote) = get_remote(param) {
if let Ok(data) = proxmox_async::runtime::block_on(async move { if let Ok(data) = proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_datastores(remote).await crate::api2::config::remote::scan_remote_datastores(remote).await
}) { }) {
for item in data { for item in data {
list.push(item.store); list.push(item.store);
} }
@ -514,14 +515,13 @@ pub fn complete_remote_datastore_name(_arg: &str, param: &HashMap<String, String
// shell completion helper // shell completion helper
pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap<String, String>) -> Vec<String> { pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
let mut list = Vec::new(); let mut list = Vec::new();
if let Some((remote, remote_store)) = get_remote_store(param) { if let Some((remote, remote_store)) = get_remote_store(param) {
if let Ok(data) = proxmox_async::runtime::block_on(async move { if let Ok(data) = proxmox_async::runtime::block_on(async move {
crate::api2::config::remote::scan_remote_groups(remote.clone(), remote_store.clone()).await crate::api2::config::remote::scan_remote_groups(remote.clone(), remote_store.clone())
.await
}) { }) {
for item in data { for item in data {
list.push(format!("{}/{}", item.backup_type, item.backup_id)); list.push(format!("{}/{}", item.backup_type, item.backup_id));
} }
@ -532,8 +532,10 @@ pub fn complete_remote_datastore_group(_arg: &str, param: &HashMap<String, Strin
} }
// shell completion helper // shell completion helper
pub fn complete_remote_datastore_group_filter(_arg: &str, param: &HashMap<String, String>) -> Vec<String> { pub fn complete_remote_datastore_group_filter(
_arg: &str,
param: &HashMap<String, String>,
) -> Vec<String> {
let mut list = Vec::new(); let mut list = Vec::new();
list.push("regex:".to_string()); list.push("regex:".to_string());
@ -541,7 +543,11 @@ pub fn complete_remote_datastore_group_filter(_arg: &str, param: &HashMap<String
list.push("type:host".to_string()); list.push("type:host".to_string());
list.push("type:vm".to_string()); list.push("type:vm".to_string());
list.extend(complete_remote_datastore_group(_arg, param).iter().map(|group| format!("group:{}", group))); list.extend(
complete_remote_datastore_group(_arg, param)
.iter()
.map(|group| format!("group:{}", group)),
);
list list
} }

View File

@ -18,7 +18,6 @@ use proxmox_backup::api2;
)] )]
/// Access Control list. /// Access Control list.
fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::access::acl::API_METHOD_READ_ACL; let info = &api2::access::acl::API_METHOD_READ_ACL;
@ -28,7 +27,9 @@ fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Err
}; };
fn render_ugid(value: &Value, record: &Value) -> Result<String, Error> { fn render_ugid(value: &Value, record: &Value) -> Result<String, Error> {
if value.is_null() { return Ok(String::new()); } if value.is_null() {
return Ok(String::new());
}
let ugid = value.as_str().unwrap(); let ugid = value.as_str().unwrap();
let ugid_type = record["ugid_type"].as_str().unwrap(); let ugid_type = record["ugid_type"].as_str().unwrap();
@ -53,7 +54,6 @@ fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Err
} }
pub fn acl_commands() -> CommandLineInterface { pub fn acl_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_ACLS)) .insert("list", CliCommand::new(&API_METHOD_LIST_ACLS))
.insert( .insert(
@ -61,8 +61,7 @@ pub fn acl_commands() -> CommandLineInterface {
CliCommand::new(&api2::access::acl::API_METHOD_UPDATE_ACL) CliCommand::new(&api2::access::acl::API_METHOD_UPDATE_ACL)
.arg_param(&["path", "role"]) .arg_param(&["path", "role"])
.completion_cb("auth-id", pbs_config::user::complete_authid) .completion_cb("auth-id", pbs_config::user::complete_authid)
.completion_cb("path", pbs_config::datastore::complete_acl_path) .completion_cb("path", pbs_config::datastore::complete_acl_path),
); );
cmd_def.into() cmd_def.into()

View File

@ -3,9 +3,9 @@ use std::io::Write;
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use serde_json::Value; use serde_json::Value;
use proxmox_sys::fs::file_get_contents;
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api; use proxmox_schema::api;
use proxmox_sys::fs::file_get_contents;
use proxmox_backup::acme::AcmeClient; use proxmox_backup::acme::AcmeClient;
use proxmox_backup::api2; use proxmox_backup::api2;

View File

@ -3,13 +3,12 @@ use anyhow::{bail, Error};
use proxmox_router::cli::*; use proxmox_router::cli::*;
use proxmox_schema::api; use proxmox_schema::api;
use proxmox_backup::config;
use proxmox_backup::auth_helpers::*; use proxmox_backup::auth_helpers::*;
use proxmox_backup::config;
#[api] #[api]
/// Display node certificate information. /// Display node certificate information.
fn cert_info() -> Result<(), Error> { fn cert_info() -> Result<(), Error> {
let cert = proxmox_backup::cert_info()?; let cert = proxmox_backup::cert_info()?;
println!("Subject: {}", cert.subject_name()?); println!("Subject: {}", cert.subject_name()?);
@ -36,7 +35,10 @@ fn cert_info() -> Result<(), Error> {
println!("Fingerprint (sha256): {}", cert.fingerprint()?); println!("Fingerprint (sha256): {}", cert.fingerprint()?);
let pubkey = cert.public_key()?; let pubkey = cert.public_key()?;
println!("Public key type: {}", openssl::nid::Nid::from_raw(pubkey.id().as_raw()).long_name()?); println!(
"Public key type: {}",
openssl::nid::Nid::from_raw(pubkey.id().as_raw()).long_name()?
);
println!("Public key bits: {}", pubkey.bits()); println!("Public key bits: {}", pubkey.bits());
Ok(()) Ok(())
@ -55,7 +57,6 @@ fn cert_info() -> Result<(), Error> {
)] )]
/// Update node certificates and generate all needed files/directories. /// Update node certificates and generate all needed files/directories.
fn update_certs(force: Option<bool>) -> Result<(), Error> { fn update_certs(force: Option<bool>) -> Result<(), Error> {
config::create_configdir()?; config::create_configdir()?;
if let Err(err) = generate_auth_key() { if let Err(err) = generate_auth_key() {
@ -72,7 +73,6 @@ fn update_certs(force: Option<bool>) -> Result<(), Error> {
} }
pub fn cert_mgmt_cli() -> CommandLineInterface { pub fn cert_mgmt_cli() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("info", CliCommand::new(&API_METHOD_CERT_INFO)) .insert("info", CliCommand::new(&API_METHOD_CERT_INFO))
.insert("update", CliCommand::new(&API_METHOD_UPDATE_CERTS)); .insert("update", CliCommand::new(&API_METHOD_UPDATE_CERTS));

View File

@ -4,8 +4,8 @@ use serde_json::Value;
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api; use proxmox_schema::api;
use pbs_client::view_task_result;
use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA}; use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA};
use pbs_client::view_task_result;
use proxmox_backup::api2; use proxmox_backup::api2;
use proxmox_backup::client_helpers::connect_to_localhost; use proxmox_backup::client_helpers::connect_to_localhost;
@ -22,7 +22,6 @@ use proxmox_backup::client_helpers::connect_to_localhost;
)] )]
/// Datastore list. /// Datastore list.
fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES; let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES;
@ -56,7 +55,6 @@ fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
)] )]
/// Show datastore configuration /// Show datastore configuration
fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::datastore::API_METHOD_READ_DATASTORE; let info = &api2::config::datastore::API_METHOD_READ_DATASTORE;
@ -88,12 +86,13 @@ fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
)] )]
/// Create new datastore config. /// Create new datastore config.
async fn create_datastore(mut param: Value) -> Result<Value, Error> { async fn create_datastore(mut param: Value) -> Result<Value, Error> {
let output_format = extract_output_format(&mut param); let output_format = extract_output_format(&mut param);
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
let result = client.post("api2/json/config/datastore", Some(param)).await?; let result = client
.post("api2/json/config/datastore", Some(param))
.await?;
view_task_result(&client, result, &output_format).await?; view_task_result(&client, result, &output_format).await?;
@ -101,29 +100,37 @@ async fn create_datastore(mut param: Value) -> Result<Value, Error> {
} }
pub fn datastore_commands() -> CommandLineInterface { pub fn datastore_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES)) .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES))
.insert("show", .insert(
"show",
CliCommand::new(&API_METHOD_SHOW_DATASTORE) CliCommand::new(&API_METHOD_SHOW_DATASTORE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::datastore::complete_datastore_name) .completion_cb("name", pbs_config::datastore::complete_datastore_name),
) )
.insert("create", .insert(
CliCommand::new(&API_METHOD_CREATE_DATASTORE) "create",
.arg_param(&["name", "path"]) CliCommand::new(&API_METHOD_CREATE_DATASTORE).arg_param(&["name", "path"]),
) )
.insert("update", .insert(
"update",
CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE) CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::datastore::complete_datastore_name) .completion_cb("name", pbs_config::datastore::complete_datastore_name)
.completion_cb("gc-schedule", pbs_config::datastore::complete_calendar_event) .completion_cb(
.completion_cb("prune-schedule", pbs_config::datastore::complete_calendar_event) "gc-schedule",
pbs_config::datastore::complete_calendar_event,
) )
.insert("remove", .completion_cb(
"prune-schedule",
pbs_config::datastore::complete_calendar_event,
),
)
.insert(
"remove",
CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE) CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::datastore::complete_datastore_name) .completion_cb("name", pbs_config::datastore::complete_datastore_name),
); );
cmd_def.into() cmd_def.into()

View File

@ -5,14 +5,10 @@ use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api; use proxmox_schema::api;
use pbs_api_types::{ use pbs_api_types::{
DISK_LIST_SCHEMA, ZFS_ASHIFT_SCHEMA, ZfsRaidLevel, ZfsCompressionType, ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_NAME_SCHEMA, DATASTORE_SCHEMA, DISK_LIST_SCHEMA,
BLOCKDEVICE_NAME_SCHEMA, DATASTORE_SCHEMA, ZFS_ASHIFT_SCHEMA,
};
use proxmox_backup::tools::disks::{
FileSystemType,
SmartAttribute,
complete_disk_name,
}; };
use proxmox_backup::tools::disks::{complete_disk_name, FileSystemType, SmartAttribute};
use proxmox_backup::api2; use proxmox_backup::api2;
@ -28,7 +24,6 @@ use proxmox_backup::api2;
)] )]
/// Local disk list. /// Local disk list.
fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -41,7 +36,10 @@ fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
let render_wearout = |value: &Value, _record: &Value| -> Result<String, Error> { let render_wearout = |value: &Value, _record: &Value| -> Result<String, Error> {
match value.as_f64() { match value.as_f64() {
Some(value) => Ok(format!("{:.2} %", if value <= 100.0 { 100.0 - value } else { 0.0 })), Some(value) => Ok(format!(
"{:.2} %",
if value <= 100.0 { 100.0 - value } else { 0.0 }
)),
None => Ok(String::from("-")), None => Ok(String::from("-")),
} }
}; };
@ -54,8 +52,7 @@ fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
.column(ColumnConfig::new("size")) .column(ColumnConfig::new("size"))
.column(ColumnConfig::new("model")) .column(ColumnConfig::new("model"))
.column(ColumnConfig::new("wearout").renderer(render_wearout)) .column(ColumnConfig::new("wearout").renderer(render_wearout))
.column(ColumnConfig::new("status")) .column(ColumnConfig::new("status"));
;
format_and_print_result_full(&mut data, &info.returns, &output_format, &options); format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
@ -84,7 +81,6 @@ fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
)] )]
/// Show SMART attributes. /// Show SMART attributes.
fn smart_attributes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn smart_attributes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -98,7 +94,12 @@ fn smart_attributes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result
let mut data = data["attributes"].take(); let mut data = data["attributes"].take();
let options = default_table_format_options(); let options = default_table_format_options();
format_and_print_result_full(&mut data, &API_METHOD_SMART_ATTRIBUTES.returns, &output_format, &options); format_and_print_result_full(
&mut data,
&API_METHOD_SMART_ATTRIBUTES.returns,
&output_format,
&options,
);
Ok(Value::Null) Ok(Value::Null)
} }
@ -123,7 +124,6 @@ async fn initialize_disk(
mut param: Value, mut param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
param["node"] = "localhost".into(); param["node"] = "localhost".into();
let info = &api2::node::disks::API_METHOD_INITIALIZE_DISK; let info = &api2::node::disks::API_METHOD_INITIALIZE_DISK;
@ -166,11 +166,7 @@ async fn initialize_disk(
}, },
)] )]
/// create a zfs pool /// create a zfs pool
async fn create_zpool( async fn create_zpool(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
param["node"] = "localhost".into(); param["node"] = "localhost".into();
let info = &api2::node::disks::zfs::API_METHOD_CREATE_ZPOOL; let info = &api2::node::disks::zfs::API_METHOD_CREATE_ZPOOL;
@ -196,7 +192,6 @@ async fn create_zpool(
)] )]
/// Local zfs pools. /// Local zfs pools.
fn list_zpools(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_zpools(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -222,7 +217,11 @@ fn list_zpools(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("name")) .column(ColumnConfig::new("name"))
.column(ColumnConfig::new("size")) .column(ColumnConfig::new("size"))
.column(ColumnConfig::new("alloc").right_align(true).renderer(render_usage)) .column(
ColumnConfig::new("alloc")
.right_align(true)
.renderer(render_usage),
)
.column(ColumnConfig::new("health")); .column(ColumnConfig::new("health"));
format_and_print_result_full(&mut data, &info.returns, &output_format, &options); format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
@ -231,13 +230,13 @@ fn list_zpools(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
} }
pub fn zpool_commands() -> CommandLineInterface { pub fn zpool_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_ZPOOLS)) .insert("list", CliCommand::new(&API_METHOD_LIST_ZPOOLS))
.insert("create", .insert(
"create",
CliCommand::new(&API_METHOD_CREATE_ZPOOL) CliCommand::new(&API_METHOD_CREATE_ZPOOL)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("devices", complete_disk_name) // fixme: complete the list .completion_cb("devices", complete_disk_name), // fixme: complete the list
); );
cmd_def.into() cmd_def.into()
@ -254,8 +253,10 @@ pub fn zpool_commands() -> CommandLineInterface {
} }
)] )]
/// List systemd datastore mount units. /// List systemd datastore mount units.
fn list_datastore_mounts(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_datastore_mounts(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -303,7 +304,6 @@ async fn create_datastore_disk(
mut param: Value, mut param: Value,
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
param["node"] = "localhost".into(); param["node"] = "localhost".into();
let info = &api2::node::disks::directory::API_METHOD_CREATE_DATASTORE_DISK; let info = &api2::node::disks::directory::API_METHOD_CREATE_DATASTORE_DISK;
@ -318,33 +318,34 @@ async fn create_datastore_disk(
} }
pub fn filesystem_commands() -> CommandLineInterface { pub fn filesystem_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORE_MOUNTS)) .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORE_MOUNTS))
.insert("create", .insert(
"create",
CliCommand::new(&API_METHOD_CREATE_DATASTORE_DISK) CliCommand::new(&API_METHOD_CREATE_DATASTORE_DISK)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("disk", complete_disk_name) .completion_cb("disk", complete_disk_name),
); );
cmd_def.into() cmd_def.into()
} }
pub fn disk_commands() -> CommandLineInterface { pub fn disk_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_DISKS)) .insert("list", CliCommand::new(&API_METHOD_LIST_DISKS))
.insert("smart-attributes", .insert(
"smart-attributes",
CliCommand::new(&API_METHOD_SMART_ATTRIBUTES) CliCommand::new(&API_METHOD_SMART_ATTRIBUTES)
.arg_param(&["disk"]) .arg_param(&["disk"])
.completion_cb("disk", complete_disk_name) .completion_cb("disk", complete_disk_name),
) )
.insert("fs", filesystem_commands()) .insert("fs", filesystem_commands())
.insert("zpool", zpool_commands()) .insert("zpool", zpool_commands())
.insert("initialize", .insert(
"initialize",
CliCommand::new(&API_METHOD_INITIALIZE_DISK) CliCommand::new(&API_METHOD_INITIALIZE_DISK)
.arg_param(&["disk"]) .arg_param(&["disk"])
.completion_cb("disk", complete_disk_name) .completion_cb("disk", complete_disk_name),
); );
cmd_def.into() cmd_def.into()

View File

@ -18,7 +18,6 @@ use proxmox_backup::api2;
)] )]
/// Read DNS settings /// Read DNS settings
fn get_dns(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn get_dns(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -29,7 +28,6 @@ fn get_dns(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
_ => unreachable!(), _ => unreachable!(),
}; };
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("search")) .column(ColumnConfig::new("search"))
.column(ColumnConfig::new("dns1")) .column(ColumnConfig::new("dns1"))
@ -42,16 +40,12 @@ fn get_dns(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
} }
pub fn dns_commands() -> CommandLineInterface { pub fn dns_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert( .insert("get", CliCommand::new(&API_METHOD_GET_DNS))
"get",
CliCommand::new(&API_METHOD_GET_DNS)
)
.insert( .insert(
"set", "set",
CliCommand::new(&api2::node::dns::API_METHOD_UPDATE_DNS) CliCommand::new(&api2::node::dns::API_METHOD_UPDATE_DNS)
.fixed_param("node", String::from("localhost")) .fixed_param("node", String::from("localhost")),
); );
cmd_def.into() cmd_def.into()

View File

@ -18,7 +18,6 @@ use proxmox_backup::api2;
)] )]
/// Network device list. /// Network device list.
fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
param["node"] = "localhost".into(); param["node"] = "localhost".into();
@ -42,7 +41,9 @@ fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Re
text.push_str(cidr); text.push_str(cidr);
} }
if let Some(cidr) = record["cidr6"].as_str() { if let Some(cidr) = record["cidr6"].as_str() {
if !text.is_empty() { text.push('\n'); } if !text.is_empty() {
text.push('\n');
}
text.push_str(cidr); text.push_str(cidr);
} }
@ -71,7 +72,9 @@ fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Re
text.push_str(gateway); text.push_str(gateway);
} }
if let Some(gateway) = record["gateway6"].as_str() { if let Some(gateway) = record["gateway6"].as_str() {
if !text.is_empty() { text.push('\n'); } if !text.is_empty() {
text.push('\n');
}
text.push_str(gateway); text.push_str(gateway);
} }
@ -84,9 +87,21 @@ fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Re
.column(ColumnConfig::new("autostart")) .column(ColumnConfig::new("autostart"))
.column(ColumnConfig::new("method")) .column(ColumnConfig::new("method"))
.column(ColumnConfig::new("method6")) .column(ColumnConfig::new("method6"))
.column(ColumnConfig::new("cidr").header("address").renderer(render_address)) .column(
.column(ColumnConfig::new("gateway").header("gateway").renderer(render_gateway)) ColumnConfig::new("cidr")
.column(ColumnConfig::new("bridge_ports").header("ports/slaves").renderer(render_ports)); .header("address")
.renderer(render_address),
)
.column(
ColumnConfig::new("gateway")
.header("gateway")
.renderer(render_gateway),
)
.column(
ColumnConfig::new("bridge_ports")
.header("ports/slaves")
.renderer(render_ports),
);
format_and_print_result_full(&mut data, &info.returns, &output_format, &options); format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
@ -95,7 +110,10 @@ fn list_network_devices(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Re
#[api()] #[api()]
/// Show pending configuration changes (diff) /// Show pending configuration changes (diff)
fn pending_network_changes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn pending_network_changes(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<Value, Error> {
param["node"] = "localhost".into(); param["node"] = "localhost".into();
let info = &api2::node::network::API_METHOD_LIST_NETWORK_DEVICES; let info = &api2::node::network::API_METHOD_LIST_NETWORK_DEVICES;
@ -112,15 +130,11 @@ fn pending_network_changes(mut param: Value, rpcenv: &mut dyn RpcEnvironment) ->
} }
pub fn network_commands() -> CommandLineInterface { pub fn network_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert( .insert("list", CliCommand::new(&API_METHOD_LIST_NETWORK_DEVICES))
"list",
CliCommand::new(&API_METHOD_LIST_NETWORK_DEVICES)
)
.insert( .insert(
"changes", "changes",
CliCommand::new(&API_METHOD_PENDING_NETWORK_CHANGES) CliCommand::new(&API_METHOD_PENDING_NETWORK_CHANGES),
) )
.insert( .insert(
"create", "create",
@ -129,7 +143,7 @@ pub fn network_commands() -> CommandLineInterface {
.arg_param(&["iface"]) .arg_param(&["iface"])
.completion_cb("iface", pbs_config::network::complete_interface_name) .completion_cb("iface", pbs_config::network::complete_interface_name)
.completion_cb("bridge_ports", pbs_config::network::complete_port_list) .completion_cb("bridge_ports", pbs_config::network::complete_port_list)
.completion_cb("slaves", pbs_config::network::complete_port_list) .completion_cb("slaves", pbs_config::network::complete_port_list),
) )
.insert( .insert(
"update", "update",
@ -138,24 +152,24 @@ pub fn network_commands() -> CommandLineInterface {
.arg_param(&["iface"]) .arg_param(&["iface"])
.completion_cb("iface", pbs_config::network::complete_interface_name) .completion_cb("iface", pbs_config::network::complete_interface_name)
.completion_cb("bridge_ports", pbs_config::network::complete_port_list) .completion_cb("bridge_ports", pbs_config::network::complete_port_list)
.completion_cb("slaves", pbs_config::network::complete_port_list) .completion_cb("slaves", pbs_config::network::complete_port_list),
) )
.insert( .insert(
"remove", "remove",
CliCommand::new(&api2::node::network::API_METHOD_DELETE_INTERFACE) CliCommand::new(&api2::node::network::API_METHOD_DELETE_INTERFACE)
.fixed_param("node", String::from("localhost")) .fixed_param("node", String::from("localhost"))
.arg_param(&["iface"]) .arg_param(&["iface"])
.completion_cb("iface", pbs_config::network::complete_interface_name) .completion_cb("iface", pbs_config::network::complete_interface_name),
) )
.insert( .insert(
"revert", "revert",
CliCommand::new(&api2::node::network::API_METHOD_REVERT_NETWORK_CONFIG) CliCommand::new(&api2::node::network::API_METHOD_REVERT_NETWORK_CONFIG)
.fixed_param("node", String::from("localhost")) .fixed_param("node", String::from("localhost")),
) )
.insert( .insert(
"reload", "reload",
CliCommand::new(&api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG) CliCommand::new(&api2::node::network::API_METHOD_RELOAD_NETWORK_CONFIG)
.fixed_param("node", String::from("localhost")) .fixed_param("node", String::from("localhost")),
); );
cmd_def.into() cmd_def.into()

View File

@ -18,7 +18,6 @@ use proxmox_backup::api2;
)] )]
/// Show node configuration /// Show node configuration
fn get_node_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn get_node_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::node::config::API_METHOD_GET_NODE_CONFIG; let info = &api2::node::config::API_METHOD_GET_NODE_CONFIG;
@ -35,14 +34,11 @@ fn get_node_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
pub fn node_commands() -> CommandLineInterface { pub fn node_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert( .insert("show", CliCommand::new(&API_METHOD_GET_NODE_CONFIG))
"show",
CliCommand::new(&API_METHOD_GET_NODE_CONFIG),
)
.insert( .insert(
"update", "update",
CliCommand::new(&api2::node::config::API_METHOD_UPDATE_NODE_CONFIG) CliCommand::new(&api2::node::config::API_METHOD_UPDATE_NODE_CONFIG)
.fixed_param("node", String::from("localhost")) .fixed_param("node", String::from("localhost")),
); );
cmd_def.into() cmd_def.into()

View File

@ -8,7 +8,6 @@ use pbs_api_types::REALM_ID_SCHEMA;
use proxmox_backup::api2; use proxmox_backup::api2;
#[api( #[api(
input: { input: {
properties: { properties: {
@ -21,7 +20,6 @@ use proxmox_backup::api2;
)] )]
/// List configured OpenId realms /// List configured OpenId realms
fn list_openid_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_openid_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::access::openid::API_METHOD_LIST_OPENID_REALMS; let info = &api2::config::access::openid::API_METHOD_LIST_OPENID_REALMS;
@ -55,7 +53,6 @@ fn list_openid_realms(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<V
/// Show OpenID realm configuration /// Show OpenID realm configuration
fn show_openid_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_openid_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::access::openid::API_METHOD_READ_OPENID_REALM; let info = &api2::config::access::openid::API_METHOD_READ_OPENID_REALM;
@ -71,32 +68,35 @@ fn show_openid_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Va
} }
pub fn openid_commands() -> CommandLineInterface { pub fn openid_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_OPENID_REALMS)) .insert("list", CliCommand::new(&API_METHOD_LIST_OPENID_REALMS))
.insert("show", CliCommand::new(&API_METHOD_SHOW_OPENID_REALM) .insert(
"show",
CliCommand::new(&API_METHOD_SHOW_OPENID_REALM)
.arg_param(&["realm"]) .arg_param(&["realm"])
.completion_cb("realm", pbs_config::domains::complete_openid_realm_name) .completion_cb("realm", pbs_config::domains::complete_openid_realm_name),
) )
.insert("create", .insert(
"create",
CliCommand::new(&api2::config::access::openid::API_METHOD_CREATE_OPENID_REALM) CliCommand::new(&api2::config::access::openid::API_METHOD_CREATE_OPENID_REALM)
.arg_param(&["realm"]) .arg_param(&["realm"])
.arg_param(&["realm"]) .arg_param(&["realm"])
.completion_cb("realm", pbs_config::domains::complete_openid_realm_name) .completion_cb("realm", pbs_config::domains::complete_openid_realm_name),
) )
.insert("update", .insert(
"update",
CliCommand::new(&api2::config::access::openid::API_METHOD_UPDATE_OPENID_REALM) CliCommand::new(&api2::config::access::openid::API_METHOD_UPDATE_OPENID_REALM)
.arg_param(&["realm"]) .arg_param(&["realm"])
.arg_param(&["realm"]) .arg_param(&["realm"])
.completion_cb("realm", pbs_config::domains::complete_openid_realm_name) .completion_cb("realm", pbs_config::domains::complete_openid_realm_name),
) )
.insert("delete", .insert(
"delete",
CliCommand::new(&api2::config::access::openid::API_METHOD_DELETE_OPENID_REALM) CliCommand::new(&api2::config::access::openid::API_METHOD_DELETE_OPENID_REALM)
.arg_param(&["realm"]) .arg_param(&["realm"])
.arg_param(&["realm"]) .arg_param(&["realm"])
.completion_cb("realm", pbs_config::domains::complete_openid_realm_name) .completion_cb("realm", pbs_config::domains::complete_openid_realm_name),
) );
;
cmd_def.into() cmd_def.into()
} }

View File

@ -8,7 +8,6 @@ use pbs_api_types::REMOTE_ID_SCHEMA;
use proxmox_backup::api2; use proxmox_backup::api2;
#[api( #[api(
input: { input: {
properties: { properties: {
@ -21,7 +20,6 @@ use proxmox_backup::api2;
)] )]
/// List configured remotes. /// List configured remotes.
fn list_remotes(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_remotes(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::remote::API_METHOD_LIST_REMOTES; let info = &api2::config::remote::API_METHOD_LIST_REMOTES;
@ -57,7 +55,6 @@ fn list_remotes(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value,
)] )]
/// Show remote configuration /// Show remote configuration
fn show_remote(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_remote(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::remote::API_METHOD_READ_REMOTE; let info = &api2::config::remote::API_METHOD_READ_REMOTE;
@ -73,32 +70,30 @@ fn show_remote(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
} }
pub fn remote_commands() -> CommandLineInterface { pub fn remote_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_REMOTES)) .insert("list", CliCommand::new(&API_METHOD_LIST_REMOTES))
.insert( .insert(
"show", "show",
CliCommand::new(&API_METHOD_SHOW_REMOTE) CliCommand::new(&API_METHOD_SHOW_REMOTE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::remote::complete_remote_name) .completion_cb("name", pbs_config::remote::complete_remote_name),
) )
.insert( .insert(
"create", "create",
// fixme: howto handle password parameter? // fixme: howto handle password parameter?
CliCommand::new(&api2::config::remote::API_METHOD_CREATE_REMOTE) CliCommand::new(&api2::config::remote::API_METHOD_CREATE_REMOTE).arg_param(&["name"]),
.arg_param(&["name"])
) )
.insert( .insert(
"update", "update",
CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE) CliCommand::new(&api2::config::remote::API_METHOD_UPDATE_REMOTE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::remote::complete_remote_name) .completion_cb("name", pbs_config::remote::complete_remote_name),
) )
.insert( .insert(
"remove", "remove",
CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE) CliCommand::new(&api2::config::remote::API_METHOD_DELETE_REMOTE)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::remote::complete_remote_name) .completion_cb("name", pbs_config::remote::complete_remote_name),
); );
cmd_def.into() cmd_def.into()

View File

@ -18,7 +18,6 @@ use proxmox_backup::api2;
)] )]
/// Read subscription info. /// Read subscription info.
fn get(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn get(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::node::subscription::API_METHOD_GET_SUBSCRIPTION; let info = &api2::node::subscription::API_METHOD_GET_SUBSCRIPTION;
@ -34,23 +33,24 @@ fn get(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
} }
pub fn subscription_commands() -> CommandLineInterface { pub fn subscription_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("get", CliCommand::new(&API_METHOD_GET)) .insert("get", CliCommand::new(&API_METHOD_GET))
.insert("set", .insert(
"set",
CliCommand::new(&api2::node::subscription::API_METHOD_SET_SUBSCRIPTION) CliCommand::new(&api2::node::subscription::API_METHOD_SET_SUBSCRIPTION)
.fixed_param("node", "localhost".into()) .fixed_param("node", "localhost".into())
.arg_param(&["key"]) .arg_param(&["key"]),
) )
.insert("update", .insert(
"update",
CliCommand::new(&api2::node::subscription::API_METHOD_CHECK_SUBSCRIPTION) CliCommand::new(&api2::node::subscription::API_METHOD_CHECK_SUBSCRIPTION)
.fixed_param("node", "localhost".into()) .fixed_param("node", "localhost".into()),
) )
.insert("remove", .insert(
"remove",
CliCommand::new(&api2::node::subscription::API_METHOD_DELETE_SUBSCRIPTION) CliCommand::new(&api2::node::subscription::API_METHOD_DELETE_SUBSCRIPTION)
.fixed_param("node", "localhost".into()) .fixed_param("node", "localhost".into()),
) );
;
cmd_def.into() cmd_def.into()
} }

View File

@ -10,10 +10,7 @@ use proxmox_backup::api2;
fn render_group_filter(value: &Value, _record: &Value) -> Result<String, Error> { fn render_group_filter(value: &Value, _record: &Value) -> Result<String, Error> {
if let Some(group_filters) = value.as_array() { if let Some(group_filters) = value.as_array() {
let group_filters:Vec<&str> = group_filters let group_filters: Vec<&str> = group_filters.iter().filter_map(Value::as_str).collect();
.iter()
.filter_map(Value::as_str)
.collect();
Ok(group_filters.join(" OR ")) Ok(group_filters.join(" OR "))
} else { } else {
Ok(String::from("all")) Ok(String::from("all"))
@ -32,7 +29,6 @@ fn render_group_filter(value: &Value, _record: &Value) -> Result<String, Error>
)] )]
/// Sync job list. /// Sync job list.
fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::sync::API_METHOD_LIST_SYNC_JOBS; let info = &api2::config::sync::API_METHOD_LIST_SYNC_JOBS;
@ -71,7 +67,6 @@ fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
)] )]
/// Show sync job configuration /// Show sync job configuration
fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::sync::API_METHOD_READ_SYNC_JOB; let info = &api2::config::sync::API_METHOD_READ_SYNC_JOB;
@ -93,15 +88,16 @@ fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value,
} }
pub fn sync_job_commands() -> CommandLineInterface { pub fn sync_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS)) .insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS))
.insert("show", .insert(
"show",
CliCommand::new(&API_METHOD_SHOW_SYNC_JOB) CliCommand::new(&API_METHOD_SHOW_SYNC_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("id", pbs_config::sync::complete_sync_job_id),
) )
.insert("create", .insert(
"create",
CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB) CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("id", pbs_config::sync::complete_sync_job_id)
@ -109,21 +105,23 @@ pub fn sync_job_commands() -> CommandLineInterface {
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name)
.completion_cb("remote", pbs_config::remote::complete_remote_name) .completion_cb("remote", pbs_config::remote::complete_remote_name)
.completion_cb("remote-store", crate::complete_remote_datastore_name) .completion_cb("remote-store", crate::complete_remote_datastore_name)
.completion_cb("groups", crate::complete_remote_datastore_group_filter) .completion_cb("groups", crate::complete_remote_datastore_group_filter),
) )
.insert("update", .insert(
"update",
CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB) CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("id", pbs_config::sync::complete_sync_job_id)
.completion_cb("schedule", pbs_config::datastore::complete_calendar_event) .completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name)
.completion_cb("remote-store", crate::complete_remote_datastore_name) .completion_cb("remote-store", crate::complete_remote_datastore_name)
.completion_cb("groups", crate::complete_remote_datastore_group_filter) .completion_cb("groups", crate::complete_remote_datastore_group_filter),
) )
.insert("remove", .insert(
"remove",
CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB) CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::sync::complete_sync_job_id) .completion_cb("id", pbs_config::sync::complete_sync_job_id),
); );
cmd_def.into() cmd_def.into()

View File

@ -10,7 +10,6 @@ use pbs_tools::format::render_bytes_human_readable;
use proxmox_backup::api2; use proxmox_backup::api2;
use proxmox_backup::client_helpers::connect_to_localhost; use proxmox_backup::client_helpers::connect_to_localhost;
#[api( #[api(
input: { input: {
properties: { properties: {
@ -23,7 +22,6 @@ use proxmox_backup::client_helpers::connect_to_localhost;
)] )]
/// List configured traffic control rules. /// List configured traffic control rules.
fn list_traffic_controls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_traffic_controls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::traffic_control::API_METHOD_LIST_TRAFFIC_CONTROLS; let info = &api2::config::traffic_control::API_METHOD_LIST_TRAFFIC_CONTROLS;
@ -62,7 +60,6 @@ fn list_traffic_controls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Resul
)] )]
/// Show traffic control configuration /// Show traffic control configuration
fn show_traffic_control(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_traffic_control(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::traffic_control::API_METHOD_READ_TRAFFIC_CONTROL; let info = &api2::config::traffic_control::API_METHOD_READ_TRAFFIC_CONTROL;
@ -89,7 +86,6 @@ fn show_traffic_control(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result
)] )]
/// Show current traffic for all rules. /// Show current traffic for all rules.
async fn show_current_traffic(param: Value) -> Result<Value, Error> { async fn show_current_traffic(param: Value) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let client = connect_to_localhost()?; let client = connect_to_localhost()?;
@ -111,7 +107,6 @@ async fn show_current_traffic(param: Value) -> Result<Value, Error> {
} }
pub fn traffic_control_commands() -> CommandLineInterface { pub fn traffic_control_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_TRAFFIC_CONTROLS)) .insert("list", CliCommand::new(&API_METHOD_LIST_TRAFFIC_CONTROLS))
.insert("traffic", CliCommand::new(&API_METHOD_SHOW_CURRENT_TRAFFIC)) .insert("traffic", CliCommand::new(&API_METHOD_SHOW_CURRENT_TRAFFIC))
@ -119,24 +114,33 @@ pub fn traffic_control_commands() -> CommandLineInterface {
"show", "show",
CliCommand::new(&API_METHOD_SHOW_TRAFFIC_CONTROL) CliCommand::new(&API_METHOD_SHOW_TRAFFIC_CONTROL)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name) .completion_cb(
"name",
pbs_config::traffic_control::complete_traffic_control_name,
),
) )
.insert( .insert(
"create", "create",
CliCommand::new(&api2::config::traffic_control::API_METHOD_CREATE_TRAFFIC_CONTROL) CliCommand::new(&api2::config::traffic_control::API_METHOD_CREATE_TRAFFIC_CONTROL)
.arg_param(&["name"]) .arg_param(&["name"]),
) )
.insert( .insert(
"update", "update",
CliCommand::new(&api2::config::traffic_control::API_METHOD_UPDATE_TRAFFIC_CONTROL) CliCommand::new(&api2::config::traffic_control::API_METHOD_UPDATE_TRAFFIC_CONTROL)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name) .completion_cb(
"name",
pbs_config::traffic_control::complete_traffic_control_name,
),
) )
.insert( .insert(
"remove", "remove",
CliCommand::new(&api2::config::traffic_control::API_METHOD_DELETE_TRAFFIC_CONTROL) CliCommand::new(&api2::config::traffic_control::API_METHOD_DELETE_TRAFFIC_CONTROL)
.arg_param(&["name"]) .arg_param(&["name"])
.completion_cb("name", pbs_config::traffic_control::complete_traffic_control_name) .completion_cb(
"name",
pbs_config::traffic_control::complete_traffic_control_name,
),
); );
cmd_def.into() cmd_def.into()

View File

@ -6,13 +6,15 @@ use std::collections::HashMap;
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api; use proxmox_schema::api;
use pbs_api_types::{ACL_PATH_SCHEMA, Authid, Userid}; use pbs_api_types::{Authid, Userid, ACL_PATH_SCHEMA};
use proxmox_backup::api2; use proxmox_backup::api2;
fn render_expire(value: &Value, _record: &Value) -> Result<String, Error> { fn render_expire(value: &Value, _record: &Value) -> Result<String, Error> {
let never = String::from("never"); let never = String::from("never");
if value.is_null() { return Ok(never); } if value.is_null() {
return Ok(never);
}
let text = match value.as_i64() { let text = match value.as_i64() {
Some(epoch) if epoch == 0 => never, Some(epoch) if epoch == 0 => never,
Some(epoch) => { Some(epoch) => {
@ -21,7 +23,7 @@ fn render_expire(value: &Value, _record: &Value) -> Result<String, Error> {
} else { } else {
epoch.to_string() epoch.to_string()
} }
}, }
None => value.to_string(), None => value.to_string(),
}; };
Ok(text) Ok(text)
@ -39,7 +41,6 @@ fn render_expire(value: &Value, _record: &Value) -> Result<String, Error> {
)] )]
/// List configured users. /// List configured users.
fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::access::user::API_METHOD_LIST_USERS; let info = &api2::access::user::API_METHOD_LIST_USERS;
@ -51,13 +52,9 @@ fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Er
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("userid")) .column(ColumnConfig::new("userid"))
.column( .column(
ColumnConfig::new("enable") ColumnConfig::new("enable").renderer(pbs_tools::format::render_bool_with_default_true),
.renderer(pbs_tools::format::render_bool_with_default_true)
)
.column(
ColumnConfig::new("expire")
.renderer(render_expire)
) )
.column(ColumnConfig::new("expire").renderer(render_expire))
.column(ColumnConfig::new("firstname")) .column(ColumnConfig::new("firstname"))
.column(ColumnConfig::new("lastname")) .column(ColumnConfig::new("lastname"))
.column(ColumnConfig::new("email")) .column(ColumnConfig::new("email"))
@ -83,7 +80,6 @@ fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Er
)] )]
/// List tokens associated with user. /// List tokens associated with user.
fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::access::user::API_METHOD_LIST_TOKENS; let info = &api2::access::user::API_METHOD_LIST_TOKENS;
@ -95,13 +91,9 @@ fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
let options = default_table_format_options() let options = default_table_format_options()
.column(ColumnConfig::new("tokenid")) .column(ColumnConfig::new("tokenid"))
.column( .column(
ColumnConfig::new("enable") ColumnConfig::new("enable").renderer(pbs_tools::format::render_bool_with_default_true),
.renderer(pbs_tools::format::render_bool_with_default_true)
)
.column(
ColumnConfig::new("expire")
.renderer(render_expire)
) )
.column(ColumnConfig::new("expire").renderer(render_expire))
.column(ColumnConfig::new("comment")); .column(ColumnConfig::new("comment"));
format_and_print_result_full(&mut data, &info.returns, &output_format, &options); format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
@ -109,7 +101,6 @@ fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
Ok(Value::Null) Ok(Value::Null)
} }
#[api( #[api(
input: { input: {
properties: { properties: {
@ -129,7 +120,6 @@ fn list_tokens(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, E
)] )]
/// List permissions of user/token. /// List permissions of user/token.
fn list_permissions(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_permissions(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::access::API_METHOD_LIST_PERMISSIONS; let info = &api2::access::API_METHOD_LIST_PERMISSIONS;
@ -167,54 +157,51 @@ fn list_permissions(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Val
Ok(Value::Null) Ok(Value::Null)
} }
pub fn user_commands() -> CommandLineInterface { pub fn user_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_USERS)) .insert("list", CliCommand::new(&API_METHOD_LIST_USERS))
.insert( .insert(
"create", "create",
// fixme: howto handle password parameter? // fixme: howto handle password parameter?
CliCommand::new(&api2::access::user::API_METHOD_CREATE_USER) CliCommand::new(&api2::access::user::API_METHOD_CREATE_USER).arg_param(&["userid"]),
.arg_param(&["userid"])
) )
.insert( .insert(
"update", "update",
CliCommand::new(&api2::access::user::API_METHOD_UPDATE_USER) CliCommand::new(&api2::access::user::API_METHOD_UPDATE_USER)
.arg_param(&["userid"]) .arg_param(&["userid"])
.completion_cb("userid", pbs_config::user::complete_userid) .completion_cb("userid", pbs_config::user::complete_userid),
) )
.insert( .insert(
"remove", "remove",
CliCommand::new(&api2::access::user::API_METHOD_DELETE_USER) CliCommand::new(&api2::access::user::API_METHOD_DELETE_USER)
.arg_param(&["userid"]) .arg_param(&["userid"])
.completion_cb("userid", pbs_config::user::complete_userid) .completion_cb("userid", pbs_config::user::complete_userid),
) )
.insert( .insert(
"list-tokens", "list-tokens",
CliCommand::new(&API_METHOD_LIST_TOKENS) CliCommand::new(&API_METHOD_LIST_TOKENS)
.arg_param(&["userid"]) .arg_param(&["userid"])
.completion_cb("userid", pbs_config::user::complete_userid) .completion_cb("userid", pbs_config::user::complete_userid),
) )
.insert( .insert(
"generate-token", "generate-token",
CliCommand::new(&api2::access::user::API_METHOD_GENERATE_TOKEN) CliCommand::new(&api2::access::user::API_METHOD_GENERATE_TOKEN)
.arg_param(&["userid", "token-name"]) .arg_param(&["userid", "token-name"])
.completion_cb("userid", pbs_config::user::complete_userid) .completion_cb("userid", pbs_config::user::complete_userid),
) )
.insert( .insert(
"delete-token", "delete-token",
CliCommand::new(&api2::access::user::API_METHOD_DELETE_TOKEN) CliCommand::new(&api2::access::user::API_METHOD_DELETE_TOKEN)
.arg_param(&["userid", "token-name"]) .arg_param(&["userid", "token-name"])
.completion_cb("userid", pbs_config::user::complete_userid) .completion_cb("userid", pbs_config::user::complete_userid)
.completion_cb("token-name", pbs_config::user::complete_token_name) .completion_cb("token-name", pbs_config::user::complete_token_name),
) )
.insert( .insert(
"permissions", "permissions",
CliCommand::new(&API_METHOD_LIST_PERMISSIONS) CliCommand::new(&API_METHOD_LIST_PERMISSIONS)
.arg_param(&["auth-id"]) .arg_param(&["auth-id"])
.completion_cb("auth-id", pbs_config::user::complete_authid) .completion_cb("auth-id", pbs_config::user::complete_authid)
.completion_cb("path", pbs_config::datastore::complete_acl_path) .completion_cb("path", pbs_config::datastore::complete_acl_path),
); );
cmd_def.into() cmd_def.into()

View File

@ -20,7 +20,6 @@ use proxmox_backup::api2;
)] )]
/// List all verification jobs /// List all verification jobs
fn list_verification_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn list_verification_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::verify::API_METHOD_LIST_VERIFICATION_JOBS; let info = &api2::config::verify::API_METHOD_LIST_VERIFICATION_JOBS;
@ -57,7 +56,6 @@ fn list_verification_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Resu
)] )]
/// Show verification job configuration /// Show verification job configuration
fn show_verification_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> { fn show_verification_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
let output_format = get_output_format(&param); let output_format = get_output_format(&param);
let info = &api2::config::verify::API_METHOD_READ_VERIFICATION_JOB; let info = &api2::config::verify::API_METHOD_READ_VERIFICATION_JOB;
@ -73,33 +71,36 @@ fn show_verification_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Resul
} }
pub fn verify_job_commands() -> CommandLineInterface { pub fn verify_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
.insert("list", CliCommand::new(&API_METHOD_LIST_VERIFICATION_JOBS)) .insert("list", CliCommand::new(&API_METHOD_LIST_VERIFICATION_JOBS))
.insert("show", .insert(
"show",
CliCommand::new(&API_METHOD_SHOW_VERIFICATION_JOB) CliCommand::new(&API_METHOD_SHOW_VERIFICATION_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::verify::complete_verification_job_id) .completion_cb("id", pbs_config::verify::complete_verification_job_id),
) )
.insert("create", .insert(
"create",
CliCommand::new(&api2::config::verify::API_METHOD_CREATE_VERIFICATION_JOB) CliCommand::new(&api2::config::verify::API_METHOD_CREATE_VERIFICATION_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::verify::complete_verification_job_id) .completion_cb("id", pbs_config::verify::complete_verification_job_id)
.completion_cb("schedule", pbs_config::datastore::complete_calendar_event) .completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name),
) )
.insert("update", .insert(
"update",
CliCommand::new(&api2::config::verify::API_METHOD_UPDATE_VERIFICATION_JOB) CliCommand::new(&api2::config::verify::API_METHOD_UPDATE_VERIFICATION_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::verify::complete_verification_job_id) .completion_cb("id", pbs_config::verify::complete_verification_job_id)
.completion_cb("schedule", pbs_config::datastore::complete_calendar_event) .completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
.completion_cb("store", pbs_config::datastore::complete_datastore_name) .completion_cb("store", pbs_config::datastore::complete_datastore_name)
.completion_cb("remote-store", crate::complete_remote_datastore_name) .completion_cb("remote-store", crate::complete_remote_datastore_name),
) )
.insert("remove", .insert(
"remove",
CliCommand::new(&api2::config::verify::API_METHOD_DELETE_VERIFICATION_JOB) CliCommand::new(&api2::config::verify::API_METHOD_DELETE_VERIFICATION_JOB)
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", pbs_config::verify::complete_verification_job_id) .completion_cb("id", pbs_config::verify::complete_verification_job_id),
); );
cmd_def.into() cmd_def.into()