From 6fa39e53e0d5c0528a32eda175f9c5e9466e106b Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 21 May 2020 10:53:06 +0200 Subject: [PATCH] proxmox-backup-manager: split out users.rs --- src/bin/proxmox-backup-manager.rs | 67 ----------------------- src/bin/proxmox_backup_manager/mod.rs | 2 + src/bin/proxmox_backup_manager/user.rs | 75 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 67 deletions(-) create mode 100644 src/bin/proxmox_backup_manager/user.rs diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 9d3b26cf..bfc52ca4 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -54,73 +54,6 @@ fn connect() -> Result { Ok(client) } -#[api( - input: { - properties: { - "output-format": { - schema: OUTPUT_FORMAT, - optional: true, - }, - } - } -)] -/// List configured users. -fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { - - let output_format = get_output_format(¶m); - - let info = &api2::access::user::API_METHOD_LIST_USERS; - let mut data = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; - - let options = default_table_format_options() - .column(ColumnConfig::new("userid")) - .column( - ColumnConfig::new("enable") - .renderer(tools::format::render_bool_with_default_true) - ) - .column( - ColumnConfig::new("expire") - .renderer(tools::format::render_epoch) - ) - .column(ColumnConfig::new("firstname")) - .column(ColumnConfig::new("lastname")) - .column(ColumnConfig::new("email")) - .column(ColumnConfig::new("comment")); - - format_and_print_result_full(&mut data, info.returns, &output_format, &options); - - Ok(Value::Null) -} - -fn user_commands() -> CommandLineInterface { - - let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(&&API_METHOD_LIST_USERS)) - .insert( - "create", - // fixme: howto handle password parameter? - CliCommand::new(&api2::access::user::API_METHOD_CREATE_USER) - .arg_param(&["userid"]) - ) - .insert( - "update", - CliCommand::new(&api2::access::user::API_METHOD_UPDATE_USER) - .arg_param(&["userid"]) - .completion_cb("userid", config::user::complete_user_name) - ) - .insert( - "remove", - CliCommand::new(&api2::access::user::API_METHOD_DELETE_USER) - .arg_param(&["userid"]) - .completion_cb("userid", config::user::complete_user_name) - ); - - cmd_def.into() -} - #[api( input: { properties: { diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 192fbeaa..83df55a6 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -1,2 +1,4 @@ mod remote; pub use remote::*; +mod user; +pub use user::*; diff --git a/src/bin/proxmox_backup_manager/user.rs b/src/bin/proxmox_backup_manager/user.rs new file mode 100644 index 00000000..80dbcb1b --- /dev/null +++ b/src/bin/proxmox_backup_manager/user.rs @@ -0,0 +1,75 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; + +use proxmox_backup::config; +use proxmox_backup::tools; +use proxmox_backup::api2; + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// List configured users. +fn list_users(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::access::user::API_METHOD_LIST_USERS; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + let options = default_table_format_options() + .column(ColumnConfig::new("userid")) + .column( + ColumnConfig::new("enable") + .renderer(tools::format::render_bool_with_default_true) + ) + .column( + ColumnConfig::new("expire") + .renderer(tools::format::render_epoch) + ) + .column(ColumnConfig::new("firstname")) + .column(ColumnConfig::new("lastname")) + .column(ColumnConfig::new("email")) + .column(ColumnConfig::new("comment")); + + format_and_print_result_full(&mut data, info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn user_commands() -> CommandLineInterface { + + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&&API_METHOD_LIST_USERS)) + .insert( + "create", + // fixme: howto handle password parameter? + CliCommand::new(&api2::access::user::API_METHOD_CREATE_USER) + .arg_param(&["userid"]) + ) + .insert( + "update", + CliCommand::new(&api2::access::user::API_METHOD_UPDATE_USER) + .arg_param(&["userid"]) + .completion_cb("userid", config::user::complete_user_name) + ) + .insert( + "remove", + CliCommand::new(&api2::access::user::API_METHOD_DELETE_USER) + .arg_param(&["userid"]) + .completion_cb("userid", config::user::complete_user_name) + ); + + cmd_def.into() +}