From 53e14507c1eab42206f7e9c8a3cd62090cdb9807 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 21 May 2020 10:56:46 +0200 Subject: [PATCH] proxmox-backup-manager: split out acl.rs --- src/bin/proxmox-backup-manager.rs | 62 ------------------------ src/bin/proxmox_backup_manager/acl.rs | 69 +++++++++++++++++++++++++++ src/bin/proxmox_backup_manager/mod.rs | 2 + 3 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 src/bin/proxmox_backup_manager/acl.rs diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index bfc52ca4..c1fa8b6e 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -54,68 +54,6 @@ fn connect() -> Result { Ok(client) } -#[api( - input: { - properties: { - "output-format": { - schema: OUTPUT_FORMAT, - optional: true, - }, - } - } -)] -/// Access Control list. -fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { - - let output_format = get_output_format(¶m); - - let info = &api2::access::acl::API_METHOD_READ_ACL; - let mut data = match info.handler { - ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, - _ => unreachable!(), - }; - - fn render_ugid(value: &Value, record: &Value) -> Result { - if value.is_null() { return Ok(String::new()); } - let ugid = value.as_str().unwrap(); - let ugid_type = record["ugid_type"].as_str().unwrap(); - - if ugid_type == "user" { - Ok(ugid.to_string()) - } else if ugid_type == "group" { - Ok(format!("@{}", ugid)) - } else { - bail!("render_ugid: got unknown ugid_type"); - } - } - - let options = default_table_format_options() - .column(ColumnConfig::new("ugid").renderer(render_ugid)) - .column(ColumnConfig::new("path")) - .column(ColumnConfig::new("propagate")) - .column(ColumnConfig::new("roleid")); - - format_and_print_result_full(&mut data, info.returns, &output_format, &options); - - Ok(Value::Null) -} - -fn acl_commands() -> CommandLineInterface { - - let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(&&API_METHOD_LIST_ACLS)) - .insert( - "update", - CliCommand::new(&api2::access::acl::API_METHOD_UPDATE_ACL) - .arg_param(&["path", "role"]) - .completion_cb("userid", config::user::complete_user_name) - .completion_cb("path", config::datastore::complete_acl_path) - - ); - - cmd_def.into() -} - #[api( input: { properties: { diff --git a/src/bin/proxmox_backup_manager/acl.rs b/src/bin/proxmox_backup_manager/acl.rs new file mode 100644 index 00000000..bc2e8f7a --- /dev/null +++ b/src/bin/proxmox_backup_manager/acl.rs @@ -0,0 +1,69 @@ +use anyhow::{bail, Error}; +use serde_json::Value; + +use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler}; + +use proxmox_backup::config; +use proxmox_backup::api2; + +#[api( + input: { + properties: { + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Access Control list. +fn list_acls(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { + + let output_format = get_output_format(¶m); + + let info = &api2::access::acl::API_METHOD_READ_ACL; + let mut data = match info.handler { + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, + _ => unreachable!(), + }; + + fn render_ugid(value: &Value, record: &Value) -> Result { + if value.is_null() { return Ok(String::new()); } + let ugid = value.as_str().unwrap(); + let ugid_type = record["ugid_type"].as_str().unwrap(); + + if ugid_type == "user" { + Ok(ugid.to_string()) + } else if ugid_type == "group" { + Ok(format!("@{}", ugid)) + } else { + bail!("render_ugid: got unknown ugid_type"); + } + } + + let options = default_table_format_options() + .column(ColumnConfig::new("ugid").renderer(render_ugid)) + .column(ColumnConfig::new("path")) + .column(ColumnConfig::new("propagate")) + .column(ColumnConfig::new("roleid")); + + format_and_print_result_full(&mut data, info.returns, &output_format, &options); + + Ok(Value::Null) +} + +pub fn acl_commands() -> CommandLineInterface { + + let cmd_def = CliCommandMap::new() + .insert("list", CliCommand::new(&&API_METHOD_LIST_ACLS)) + .insert( + "update", + CliCommand::new(&api2::access::acl::API_METHOD_UPDATE_ACL) + .arg_param(&["path", "role"]) + .completion_cb("userid", config::user::complete_user_name) + .completion_cb("path", config::datastore::complete_acl_path) + + ); + + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 83df55a6..487cab22 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -1,3 +1,5 @@ +mod acl; +pub use acl::*; mod remote; pub use remote::*; mod user;