From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5AC1F6C7EE for ; Thu, 23 Sep 2021 13:38:16 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 418AD24D5E for ; Thu, 23 Sep 2021 13:37:46 +0200 (CEST) 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 id 5398024C41 for ; Thu, 23 Sep 2021 13:37:41 +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 29C5E44A7B for ; Thu, 23 Sep 2021 13:37:41 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 23 Sep 2021 13:37:35 +0200 Message-Id: <20210923113739.4151043-10-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210923113739.4151043-1-d.csapak@proxmox.com> References: <20210923113739.4151043-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.359 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 v2 09/13] proxmox-backup-client: add 'protected' commands X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2021 11:38:16 -0000 includes 'update' and 'show' similar to the notes commands Signed-off-by: Dominik Csapak --- proxmox-backup-client/src/snapshot.rs | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/proxmox-backup-client/src/snapshot.rs b/proxmox-backup-client/src/snapshot.rs index 4465f69a..37db5579 100644 --- a/proxmox-backup-client/src/snapshot.rs +++ b/proxmox-backup-client/src/snapshot.rs @@ -359,6 +359,118 @@ async fn update_notes(param: Value) -> Result { Ok(Value::Null) } +#[api( + input: { + properties: { + repository: { + schema: REPO_URL_SCHEMA, + optional: true, + }, + snapshot: { + type: String, + description: "Snapshot path.", + }, + "output-format": { + schema: OUTPUT_FORMAT, + optional: true, + }, + } + } +)] +/// Show protection status of the specified snapshot +async fn show_protection(param: Value) -> Result { + let repo = extract_repository_from_value(¶m)?; + let path = required_string_param(¶m, "snapshot")?; + + let snapshot: BackupDir = path.parse()?; + let client = connect(&repo)?; + + let path = format!("api2/json/admin/datastore/{}/protected", repo.store()); + + let args = json!({ + "backup-type": snapshot.group().backup_type(), + "backup-id": snapshot.group().backup_id(), + "backup-time": snapshot.backup_time(), + }); + + let output_format = get_output_format(¶m); + + let mut result = client.get(&path, Some(args)).await?; + + let protected = result["data"].take(); + + if output_format == "text" { + if let Some(protected) = protected.as_bool() { + println!("{}", protected); + } + } else { + format_and_print_result( + &json!({ + "protected": protected, + }), + &output_format, + ); + } + + Ok(Value::Null) +} + +#[api( + input: { + properties: { + repository: { + schema: REPO_URL_SCHEMA, + optional: true, + }, + snapshot: { + type: String, + description: "Snapshot path.", + }, + protected: { + type: bool, + description: "The protection status.", + }, + } + } +)] +/// Update Protection Status of a snapshot +async fn update_protection(protected: bool, param: Value) -> Result { + let repo = extract_repository_from_value(¶m)?; + let path = required_string_param(¶m, "snapshot")?; + + let snapshot: BackupDir = path.parse()?; + let mut client = connect(&repo)?; + + let path = format!("api2/json/admin/datastore/{}/protected", repo.store()); + + let args = json!({ + "backup-type": snapshot.group().backup_type(), + "backup-id": snapshot.group().backup_id(), + "backup-time": snapshot.backup_time(), + "protected": protected, + }); + + client.put(&path, Some(args)).await?; + + Ok(Value::Null) +} + +fn protected_cli() -> CliCommandMap { + CliCommandMap::new() + .insert( + "show", + CliCommand::new(&API_METHOD_SHOW_PROTECTION) + .arg_param(&["snapshot"]) + .completion_cb("snapshot", complete_backup_snapshot), + ) + .insert( + "update", + CliCommand::new(&API_METHOD_UPDATE_PROTECTION) + .arg_param(&["snapshot", "protected"]) + .completion_cb("snapshot", complete_backup_snapshot), + ) +} + fn notes_cli() -> CliCommandMap { CliCommandMap::new() .insert( @@ -378,6 +490,7 @@ fn notes_cli() -> CliCommandMap { pub fn snapshot_mgtm_cli() -> CliCommandMap { CliCommandMap::new() .insert("notes", notes_cli()) + .insert("protected", protected_cli()) .insert( "list", CliCommand::new(&API_METHOD_LIST_SNAPSHOTS) -- 2.30.2