]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/access/role.rs: new api to list roles
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 17 Apr 2020 12:03:24 +0000 (14:03 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 17 Apr 2020 12:03:24 +0000 (14:03 +0200)
src/api2/access.rs
src/api2/access/role.rs [new file with mode: 0644]
src/config/acl.rs
src/config/cached_user_info.rs

index 4b148494749e38ec5b059beaf44cb5d16c0c799c..8a483b5db924fa79fd40450df7ff603ea12671a6 100644 (file)
@@ -18,6 +18,7 @@ use crate::config::acl::PRIV_PERMISSIONS_MODIFY;
 pub mod user;
 pub mod domain;
 pub mod acl;
+pub mod role;
 
 fn authenticate_user(username: &str, password: &str) -> Result<(), Error> {
 
@@ -166,6 +167,7 @@ const SUBDIRS: SubdirMap = &sorted!([
             .post(&API_METHOD_CREATE_TICKET)
     ),
     ("domains", &domain::ROUTER),
+    ("roles", &role::ROUTER),
     ("users", &user::ROUTER),
 ]);
 
diff --git a/src/api2/access/role.rs b/src/api2/access/role.rs
new file mode 100644 (file)
index 0000000..cd30e0c
--- /dev/null
@@ -0,0 +1,45 @@
+use failure::*;
+
+use serde_json::{json, Value};
+
+use proxmox::api::{api, Permission};
+use proxmox::api::router::Router;
+
+use crate::api2::types::*;
+use crate::config::acl::ROLE_NAMES;
+
+#[api(
+    returns: {
+        description: "List of roles.",
+        type: Array,
+        items: {
+            type: Object,
+            description: "User name with description.",
+            properties: {
+                role: {
+                    description: "Role name.",
+                    type: String,
+                },
+                comment: {
+                    schema: SINGLE_LINE_COMMENT_SCHEMA,
+                    optional: true,
+                },
+            },
+        }
+    },
+    access: {
+        permission: &Permission::Anybody,
+    }
+)]
+/// Role list
+fn list_roles() -> Result<Value, Error> {
+    let mut list = Vec::new();
+
+    for (role, comment) in ROLE_NAMES.iter() {
+        list.push(json!({ "role": role, "comment": comment }));
+    }
+    Ok(list.into())
+}
+
+pub const ROUTER: Router = Router::new()
+    .get(&API_METHOD_LIST_ROLES);
index 4028362b8f7c7279e2e1a24db73d9d7a47c10488..adf1b9a60827f411da7fb9029196bd6a00fd6763 100644 (file)
@@ -41,16 +41,34 @@ pub const ROLE_DATASTORE_AUDIT: u64 = PRIV_DATASTORE_AUDIT;
 pub const ROLE_NAME_NO_ACCESS: &str ="NoAccess";
 
 lazy_static! {
-    pub static ref ROLE_NAMES: HashMap<&'static str, u64> = {
+    pub static ref ROLE_NAMES: HashMap<&'static str, (u64, &'static str)> = {
         let mut map = HashMap::new();
 
-        map.insert("Admin", ROLE_ADMIN);
-        map.insert("Audit", ROLE_AUDIT);
-        map.insert(ROLE_NAME_NO_ACCESS, ROLE_NO_ACCESS);
-
-        map.insert("Datastore.Admin", ROLE_DATASTORE_ADMIN);
-        map.insert("Datastore.User", ROLE_DATASTORE_USER);
-        map.insert("Datastore.Audit", ROLE_DATASTORE_AUDIT);
+        map.insert("Admin", (
+            ROLE_ADMIN,
+            "Administrator",
+        ));
+        map.insert("Audit", (
+            ROLE_AUDIT,
+            "Auditor",
+        ));
+        map.insert(ROLE_NAME_NO_ACCESS, (
+            ROLE_NO_ACCESS,
+            "Disable access",
+        ));
+
+        map.insert("Datastore.Admin", (
+            ROLE_DATASTORE_ADMIN,
+            "Datastore Administrator",
+        ));
+        map.insert("Datastore.User", (
+            ROLE_DATASTORE_USER,
+            "Datastore User",
+        ));
+        map.insert("Datastore.Audit", (
+            ROLE_DATASTORE_AUDIT,
+            "Datastore Auditor",
+        ));
 
         map
     };
index 65378b444db5ed984d1e632493e9a6436e3daf84..15520f7838830e05b7ceb466cef577c60624880d 100644 (file)
@@ -60,7 +60,7 @@ impl UserInformation for CachedUserInfo {
         let roles = self.acl_tree.roles(userid, path);
         let mut privs: u64 = 0;
         for role in roles {
-            if let Some(role_privs) = ROLE_NAMES.get(role.as_str()) {
+            if let Some((role_privs, _)) = ROLE_NAMES.get(role.as_str()) {
                 privs |= role_privs;
             }
         }