From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <l.wagner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 8A5E492777
 for <pbs-devel@lists.proxmox.com>; Mon, 13 Feb 2023 15:29:33 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 73D6E24D08
 for <pbs-devel@lists.proxmox.com>; Mon, 13 Feb 2023 15:29:33 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pbs-devel@lists.proxmox.com>; Mon, 13 Feb 2023 15:29:32 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 972C146F57
 for <pbs-devel@lists.proxmox.com>; Mon, 13 Feb 2023 15:29:32 +0100 (CET)
From: Lukas Wagner <l.wagner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Mon, 13 Feb 2023 15:29:31 +0100
Message-Id: <20230213142931.904152-1-l.wagner@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.186 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pbs-devel] [PATCH proxmox-backup] manager: use view_task_result
 function for realm sync
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 13 Feb 2023 14:29:33 -0000

Previously, the same approach as in `proxmox-backup-debug` was used.
With the changes from this commit, realm syncing uses the same method for
waiting for task output as other parts of `proxmox-backup-manager`.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
Thx @ Fabian for the suggestion!

 src/bin/proxmox_backup_manager/ldap.rs | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/bin/proxmox_backup_manager/ldap.rs b/src/bin/proxmox_backup_manager/ldap.rs
index 538c313b..7ff4ad1d 100644
--- a/src/bin/proxmox_backup_manager/ldap.rs
+++ b/src/bin/proxmox_backup_manager/ldap.rs
@@ -1,14 +1,14 @@
 use anyhow::Error;
+use pbs_client::view_task_result;
+use pbs_tools::json::required_string_param;
 use serde_json::Value;
 
 use proxmox_router::{cli::*, ApiHandler, Permission, RpcEnvironment};
 use proxmox_schema::api;
 
-use pbs_api_types::{
-    Realm, PRIV_PERMISSIONS_MODIFY, PROXMOX_UPID_REGEX, REALM_ID_SCHEMA, REMOVE_VANISHED_SCHEMA,
-};
+use pbs_api_types::{Realm, PRIV_PERMISSIONS_MODIFY, REALM_ID_SCHEMA, REMOVE_VANISHED_SCHEMA};
 
-use proxmox_backup::api2;
+use proxmox_backup::{api2, client_helpers::connect_to_localhost};
 
 #[api(
     input: {
@@ -98,18 +98,13 @@ fn show_ldap_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Valu
     },
 )]
 /// Sync a given LDAP realm
-async fn sync_ldap_realm(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
-    let info = &api2::access::domain::API_METHOD_SYNC_REALM;
-    let data = match info.handler {
-        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
-        _ => unreachable!(),
-    };
+async fn sync_ldap_realm(param: Value) -> Result<Value, Error> {
+    let realm = required_string_param(&param, "realm")?;
+    let client = connect_to_localhost()?;
 
-    if let Some(upid) = data.as_str() {
-        if PROXMOX_UPID_REGEX.is_match(upid) {
-            proxmox_rest_server::handle_worker(upid).await?;
-        }
-    }
+    let path = format!("api2/json/access/domains/{}/sync", realm);
+    let result = client.post(&path, Some(param)).await?;
+    view_task_result(&client, result, "text").await?;
 
     Ok(Value::Null)
 }
-- 
2.30.2