From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from ronja.mits.lan
	by ronja.mits.lan with LMTP
	id ECGfOfivcmalSAAAxxbTJA
	(envelope-from <pbs-devel-bounces@lists.proxmox.com>); Wed, 19 Jun 2024 12:16:24 +0200
Received: from proxmox-new.maurer-it.com (unknown [192.168.2.33])
	by ronja.mits.lan (Postfix) with ESMTPS id D013BF64595;
	Wed, 19 Jun 2024 12:16:24 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
	by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B46B747C7B;
	Wed, 19 Jun 2024 12:16:24 +0200 (CEST)
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 (4096 bits))
	(No client certificate requested)
	by proxmox-new.maurer-it.com (Proxmox) with ESMTPS;
	Wed, 19 Jun 2024 12:16:23 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 7CD8B1E73;
	Wed, 19 Jun 2024 12:16:22 +0200 (CEST)
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Wed, 19 Jun 2024 12:15:44 +0200
Message-ID: <20240619101546.109271-1-g.goller@proxmox.com>
X-Mailer: git-send-email 2.43.0
MIME-Version: 1.0
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] backup_manager: use
 confirmation helper in wipe-disk command
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>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
	DMARC_MISSING             0.1 Missing DMARC policy
	KAM_DMARC_STATUS         0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
	KAM_LAZY_DOMAIN_SECURITY      1 Sending domain does not have any anti-forgery methods
	MAILING_LIST_MULTI         -2 Multiple indicators imply a widely-seen list manager
	RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/, medium trust
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_NONE                0.001 SPF: sender does not publish an SPF Record
	T_SCC_BODY_TEXT_LINE    -0.01 -

Use `Confirmation` helper in the wipe-disk command prompt.

Improves: 887d83cb (cli: add interactive confirmation for block device wipe, 2023-11-29)
Cc: Markus Frank <m.frank@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 src/bin/proxmox_backup_manager/disk.rs | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs
index 9c55a989..d0fdfc6f 100644
--- a/src/bin/proxmox_backup_manager/disk.rs
+++ b/src/bin/proxmox_backup_manager/disk.rs
@@ -3,7 +3,7 @@ use serde_json::Value;
 
 use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
 use proxmox_schema::api;
-use std::io::{IsTerminal, Write};
+use std::io::IsTerminal;
 
 use pbs_api_types::{
     ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA,
@@ -155,17 +155,16 @@ async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<
 
     // If we're on a TTY, query the user
     if std::io::stdin().is_terminal() {
-        println!("You are about to wipe block device {}.", param["disk"]);
-        print!("Are you sure you want to continue? (y/N): ");
-        let _ = std::io::stdout().flush();
-        use std::io::{BufRead, BufReader};
-        let mut line = String::new();
-        match BufReader::new(std::io::stdin()).read_line(&mut line) {
-            Ok(_) => match line.trim() {
-                "y" | "Y" => (), // continue
-                _ => bail!("Aborting."),
-            },
-            Err(err) => bail!("Failed to read line - {err}."),
+        let confirmation = Confirmation::query_with_default(
+            format!(
+                "You are about to wipe block device {}. Are you sure you want to continue?",
+                param["disk"]
+            )
+            .as_str(),
+            Confirmation::No,
+        )?;
+        if confirmation.is_no() {
+            bail!("Aborting.");
         }
     }
 
-- 
2.43.0



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel