api2/access/acl: add path and exact parameter to list_acl
so that we can get only a subset of the acls, filtered by the backed also return the digest here Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
c0ac207453
commit
2882c881e9
|
@ -75,6 +75,20 @@ fn extract_acl_node_data(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
path: {
|
||||||
|
schema: ACL_PATH_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
exact: {
|
||||||
|
description: "If set, returns only ACL for the exact path.",
|
||||||
|
type: bool,
|
||||||
|
optional: true,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
returns: {
|
returns: {
|
||||||
description: "ACL entry list.",
|
description: "ACL entry list.",
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -88,16 +102,25 @@ fn extract_acl_node_data(
|
||||||
)]
|
)]
|
||||||
/// Read Access Control List (ACLs).
|
/// Read Access Control List (ACLs).
|
||||||
pub fn read_acl(
|
pub fn read_acl(
|
||||||
_rpcenv: &mut dyn RpcEnvironment,
|
path: Option<String>,
|
||||||
|
exact: bool,
|
||||||
|
mut rpcenv: &mut dyn RpcEnvironment,
|
||||||
) -> Result<Vec<AclListItem>, Error> {
|
) -> Result<Vec<AclListItem>, Error> {
|
||||||
|
|
||||||
//let auth_user = rpcenv.get_user().unwrap();
|
//let auth_user = rpcenv.get_user().unwrap();
|
||||||
|
|
||||||
// fixme: return digest?
|
let (mut tree, digest) = acl::config()?;
|
||||||
let (tree, _digest) = acl::config()?;
|
|
||||||
|
|
||||||
let mut list: Vec<AclListItem> = Vec::new();
|
let mut list: Vec<AclListItem> = Vec::new();
|
||||||
extract_acl_node_data(&tree.root, "", &mut list, false);
|
if let Some(path) = &path {
|
||||||
|
if let Some(node) = &tree.find_node(path) {
|
||||||
|
extract_acl_node_data(&node, path, &mut list, exact);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
extract_acl_node_data(&tree.root, "", &mut list, exact);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
|
||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,6 +340,11 @@ impl AclTree {
|
||||||
Self { root: AclTreeNode::new() }
|
Self { root: AclTreeNode::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_node(&mut self, path: &str) -> Option<&mut AclTreeNode> {
|
||||||
|
let path = split_acl_path(path);
|
||||||
|
return self.get_node(&path);
|
||||||
|
}
|
||||||
|
|
||||||
fn get_node(&mut self, path: &[&str]) -> Option<&mut AclTreeNode> {
|
fn get_node(&mut self, path: &[&str]) -> Option<&mut AclTreeNode> {
|
||||||
let mut node = &mut self.root;
|
let mut node = &mut self.root;
|
||||||
for comp in path {
|
for comp in path {
|
||||||
|
|
Loading…
Reference in New Issue