[pbs-devel] [PATCH proxmox-backup 2/3] fix #3939: set default value in domains endpoint

Matthias Heiserer m.heiserer at proxmox.com
Wed Mar 23 14:01:10 CET 2022


Because the default realm is stored in node.cfg, here we have to add
it to the returned information.

Signed-off-by: Matthias Heiserer <m.heiserer at proxmox.com>
---
 src/api2/access/domain.rs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/api2/access/domain.rs b/src/api2/access/domain.rs
index 3518e5ca..1dbc8a0e 100644
--- a/src/api2/access/domain.rs
+++ b/src/api2/access/domain.rs
@@ -5,7 +5,7 @@ use serde_json::{json, Value};
 
 use proxmox_router::{Router, RpcEnvironment, Permission};
 use proxmox_schema::api;
-
+use crate::config::node;
 use pbs_api_types::BasicRealmInfo;
 
 #[api(
@@ -24,17 +24,19 @@ use pbs_api_types::BasicRealmInfo;
 /// Authentication domain/realm index.
 fn list_domains(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Vec<BasicRealmInfo>, Error> {
     let mut list = Vec::new();
+    let default_realm = node::config()?.0.default_realm;
 
     list.push(serde_json::from_value(json!({
         "realm": "pam",
         "type": "pam",
         "comment": "Linux PAM standard authentication",
-        "default": Some(true),
+        "default": default_realm.as_ref().map(|value|value == "pam"),
     }))?);
     list.push(serde_json::from_value(json!({
         "realm": "pbs",
         "type": "pbs",
         "comment": "Proxmox Backup authentication server",
+        "default": default_realm.as_ref().map(|value|value == "pbs"),
     }))?);
 
     let (config, digest) = pbs_config::domains::config()?;
@@ -42,6 +44,11 @@ fn list_domains(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Vec<BasicRealmInf
     for (_, (section_type, v)) in config.sections.iter() {
         let mut entry = v.clone();
         entry["type"] = Value::from(section_type.clone());
+        entry["default"] = Value::from(
+            default_realm
+                .as_ref()
+                .map_or(false, |value| value == &entry["realm"]),
+        );
         list.push(serde_json::from_value(entry)?);
     }
 
-- 
2.30.2





More information about the pbs-devel mailing list