]> git.proxmox.com Git - proxmox-backup.git/blob - src/api2/access/domain.rs
router change made one level of rpcenv mut superfluous
[proxmox-backup.git] / src / api2 / access / domain.rs
1 //! List Authentication domains/realms
2
3 use anyhow::Error;
4 use serde_json::{json, Value};
5
6 use proxmox_router::{Permission, Router, RpcEnvironment};
7 use proxmox_schema::api;
8
9 use pbs_api_types::BasicRealmInfo;
10
11 #[api(
12 returns: {
13 description: "List of realms with basic info.",
14 type: Array,
15 items: {
16 type: BasicRealmInfo,
17 }
18 },
19 access: {
20 description: "Anyone can access this, because we need that list for the login box (before the user is authenticated).",
21 permission: &Permission::World,
22 }
23 )]
24 /// Authentication domain/realm index.
25 fn list_domains(rpcenv: &mut dyn RpcEnvironment) -> Result<Vec<BasicRealmInfo>, Error> {
26 let mut list = Vec::new();
27
28 list.push(serde_json::from_value(json!({
29 "realm": "pam",
30 "type": "pam",
31 "comment": "Linux PAM standard authentication",
32 "default": Some(true),
33 }))?);
34 list.push(serde_json::from_value(json!({
35 "realm": "pbs",
36 "type": "pbs",
37 "comment": "Proxmox Backup authentication server",
38 }))?);
39
40 let (config, digest) = pbs_config::domains::config()?;
41
42 for (_, (section_type, v)) in config.sections.iter() {
43 let mut entry = v.clone();
44 entry["type"] = Value::from(section_type.clone());
45 list.push(serde_json::from_value(entry)?);
46 }
47
48 rpcenv["digest"] = hex::encode(&digest).into();
49
50 Ok(list)
51 }
52
53 pub const ROUTER: Router = Router::new().get(&API_METHOD_LIST_DOMAINS);