]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api2/access/acl: add path and exact parameter to list_acl
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 20 May 2020 10:15:35 +0000 (12:15 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 20 May 2020 11:44:36 +0000 (13:44 +0200)
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>
src/api2/access/acl.rs
src/config/acl.rs

index d436c4378733ae85ce06b5dec23ca8401c6c7df6..4fed4652eee2afcde91bd5d6bbd25cae840b7a91 100644 (file)
@@ -75,6 +75,20 @@ fn extract_acl_node_data(
 }
 
 #[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: {
         description: "ACL entry list.",
         type: Array,
@@ -88,16 +102,25 @@ fn extract_acl_node_data(
 )]
 /// Read Access Control List (ACLs).
 pub fn read_acl(
-    _rpcenv: &mut dyn RpcEnvironment,
+    path: Option<String>,
+    exact: bool,
+    mut rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<AclListItem>, Error> {
 
     //let auth_user = rpcenv.get_user().unwrap();
 
-    // fixme: return digest?
-    let (tree, _digest) = acl::config()?;
+    let (mut tree, digest) = acl::config()?;
 
     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)
 }
index 70bcf73a7224091f758a37d909f1427e5ed039dd..f702ec4d8580692a953451454c1bbf8bd183831a 100644 (file)
@@ -340,6 +340,11 @@ impl AclTree {
         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> {
         let mut node = &mut self.root;
         for comp in path {