public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Matthias Heiserer <m.heiserer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] fix #3939: set default value in domains endpoint
Date: Wed, 23 Mar 2022 14:01:10 +0100	[thread overview]
Message-ID: <20220323130111.2552347-2-m.heiserer@proxmox.com> (raw)
In-Reply-To: <20220323130111.2552347-1-m.heiserer@proxmox.com>

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@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





  reply	other threads:[~2022-03-23 13:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 13:01 [pbs-devel] [PATCH proxmox-backup 1/3] fix #3939: add default-realm field to node config Matthias Heiserer
2022-03-23 13:01 ` Matthias Heiserer [this message]
2022-04-11  8:12   ` [pbs-devel] [PATCH proxmox-backup 2/3] fix #3939: set default value in domains endpoint Thomas Lamprecht
2022-04-11 10:20     ` Matthias Heiserer
2022-04-11 11:34       ` Thomas Lamprecht
2022-03-23 13:01 ` [pbs-devel] [PATCH proxmox-backup 3/3] fix #3939: ui: default realm setting in NodeOptionView Matthias Heiserer
2022-04-11  8:13   ` Thomas Lamprecht
2022-04-11 10:03     ` Matthias Heiserer
2022-04-11 11:41       ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220323130111.2552347-2-m.heiserer@proxmox.com \
    --to=m.heiserer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal