2020-05-21 08:56:46 +00:00
|
|
|
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<Value, Error> {
|
|
|
|
|
|
|
|
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<String, Error> {
|
|
|
|
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"));
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-05-21 08:56:46 +00:00
|
|
|
|
|
|
|
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"])
|
2020-10-30 14:18:41 +00:00
|
|
|
.completion_cb("auth-id", config::user::complete_authid)
|
2020-05-21 08:56:46 +00:00
|
|
|
.completion_cb("path", config::datastore::complete_acl_path)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
cmd_def.into()
|
|
|
|
}
|