From: Markus Frank <m.frank@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] cli: add interactive confirmation for block device wipe
Date: Wed, 29 Nov 2023 13:14:23 +0100 [thread overview]
Message-ID: <20231129121423.70408-1-m.frank@proxmox.com> (raw)
If stdin is a TTY, an interactive prompt is added to confirm the deletion
of a block device, ensuring user verification before proceeding.
Signed-off-by: Markus Frank <m.frank@proxmox.com>
---
src/bin/proxmox_backup_manager/disk.rs | 27 ++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/bin/proxmox_backup_manager/disk.rs b/src/bin/proxmox_backup_manager/disk.rs
index 7a292098..4baa2a25 100644
--- a/src/bin/proxmox_backup_manager/disk.rs
+++ b/src/bin/proxmox_backup_manager/disk.rs
@@ -3,6 +3,8 @@ use serde_json::Value;
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
use proxmox_schema::api;
+use proxmox_sys::linux::tty::stdin_isatty;
+use std::io::Write;
use pbs_api_types::{
ZfsCompressionType, ZfsRaidLevel, BLOCKDEVICE_DISK_AND_PARTITION_NAME_SCHEMA,
@@ -152,6 +154,31 @@ async fn initialize_disk(
async fn wipe_disk(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
param["node"] = "localhost".into();
+ // If we're on a TTY, query the user
+ if stdin_isatty() {
+ loop {
+ eprintln!("You are about to wipe block device {}.", param["disk"]);
+ eprintln!("Please make sure you have selected the correct device!");
+ eprint!("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(_) => {
+ let trimmed = line.trim();
+ if trimmed == "y" || trimmed == "Y" {
+ break;
+ } else if trimmed == "n" || trimmed == "N" {
+ bail!("Aborting.");
+ } else {
+ continue;
+ }
+ }
+ Err(err) => bail!("Failed to read line - {}.", err),
+ }
+ }
+ }
+
let info = &api2::node::disks::API_METHOD_WIPE_DISK;
let result = match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
--
2.39.2
next reply other threads:[~2023-11-29 12:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 12:14 Markus Frank [this message]
2023-11-29 12:52 ` Thomas Lamprecht
2023-11-29 13:00 ` Gabriel Goller
2023-11-29 13:04 ` Thomas Lamprecht
2023-11-29 13:08 ` Gabriel Goller
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=20231129121423.70408-1-m.frank@proxmox.com \
--to=m.frank@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