2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::Error;
|
2020-04-17 12:03:24 +00:00
|
|
|
|
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
|
|
|
use proxmox::api::{api, Permission};
|
|
|
|
use proxmox::api::router::Router;
|
|
|
|
|
|
|
|
use crate::api2::types::*;
|
2020-05-20 10:15:31 +00:00
|
|
|
use crate::config::acl::{Role, ROLE_NAMES, PRIVILEGES};
|
2020-04-17 12:03:24 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
returns: {
|
|
|
|
description: "List of roles.",
|
|
|
|
type: Array,
|
|
|
|
items: {
|
|
|
|
type: Object,
|
2020-09-18 12:55:00 +00:00
|
|
|
description: "Role with description and privileges.",
|
2020-04-17 12:03:24 +00:00
|
|
|
properties: {
|
2020-05-20 10:15:32 +00:00
|
|
|
roleid: {
|
2020-04-29 11:01:24 +00:00
|
|
|
type: Role,
|
2020-04-17 12:03:24 +00:00
|
|
|
},
|
2020-05-20 10:15:31 +00:00
|
|
|
privs: {
|
|
|
|
type: Array,
|
|
|
|
description: "List of Privileges",
|
|
|
|
items: {
|
|
|
|
type: String,
|
|
|
|
description: "A Privilege",
|
|
|
|
},
|
|
|
|
},
|
2020-04-17 12:03:24 +00:00
|
|
|
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();
|
|
|
|
|
2020-05-20 10:15:31 +00:00
|
|
|
for (role, (privs, comment)) in ROLE_NAMES.iter() {
|
|
|
|
let mut priv_list = Vec::new();
|
|
|
|
for (name, privilege) in PRIVILEGES.iter() {
|
|
|
|
if privs & privilege > 0 {
|
2021-01-15 13:38:27 +00:00
|
|
|
priv_list.push(name);
|
2020-05-20 10:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 10:15:32 +00:00
|
|
|
list.push(json!({ "roleid": role, "privs": priv_list, "comment": comment }));
|
2020-04-17 12:03:24 +00:00
|
|
|
}
|
|
|
|
Ok(list.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const ROUTER: Router = Router::new()
|
|
|
|
.get(&API_METHOD_LIST_ROLES);
|