start ACL api

This commit is contained in:
Dietmar Maurer
2020-04-13 11:09:44 +02:00
parent a83eab3c4d
commit ed3e60ae69
5 changed files with 188 additions and 5 deletions

View File

@ -171,6 +171,60 @@ fn user_commands() -> CommandLineInterface {
cmd_def.into()
}
#[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(&param);
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"));
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));
cmd_def.into()
}
fn datastore_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new()
@ -539,6 +593,7 @@ async fn pull_datastore(
fn main() {
let cmd_def = CliCommandMap::new()
.insert("acl", acl_commands())
.insert("datastore", datastore_commands())
.insert("user", user_commands())
.insert("remote", remote_commands())