From 3855386c65a82e2d95863cee7e446e23d2fa0bc0 Mon Sep 17 00:00:00 2001
From: Lyanis Souidi <lyanis.souidi@u-pec.fr>
Date: Wed, 8 Jan 2025 17:25:08 +0100
Subject: [PATCH] Add import acl script

---
 vm/extract_acl.py |  0
 vm/import_acl.py  | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 mode change 100644 => 100755 vm/extract_acl.py
 create mode 100755 vm/import_acl.py

diff --git a/vm/extract_acl.py b/vm/extract_acl.py
old mode 100644
new mode 100755
diff --git a/vm/import_acl.py b/vm/import_acl.py
new file mode 100755
index 0000000..98f4f76
--- /dev/null
+++ b/vm/import_acl.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import sys
+import subprocess
+
+def import_acls(input_file):
+    print(f"Importing ACLs from {input_file}...")
+
+    with open(input_file, "r") as f:
+        lines = f.readlines()
+
+    for line in lines:
+        line = line.strip()
+        if not line:
+            continue
+
+        path, user, role = line.split()
+        print(f"Adding ACL: Path={path}, User={user}, Role={role}")
+
+        result = subprocess.run(["pveum", "acl", "modify", path, "--users", user, "--roles", role])
+
+        if result.returncode != 0:
+            print(f"Error adding ACL: {result.stderr}")
+        else:
+            print(f"Successfully added ACL for {path}")
+
+    print("ACL import completed.")
+
+def main():
+    if len(sys.argv) != 2:
+        print(f"Usage: {sys.argv[0]} <input_file>")
+        sys.exit(1)
+
+    input_file = sys.argv[1]
+    import_acls(input_file)
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file