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 32471C9E4 for ; Tue, 12 Apr 2022 12:39:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 30287D787 for ; Tue, 12 Apr 2022 12:39:53 +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 561CAD77E for ; Tue, 12 Apr 2022 12:39:52 +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 2C1FC415EA for ; Tue, 12 Apr 2022 12:39:52 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Tue, 12 Apr 2022 12:39:50 +0200 Message-Id: <20220412103950.70875-1-w.bumiller@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.341 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.rs, media.rs, main.rs, acme.rs, manifest.rs, network.rs] Subject: [pbs-devel] [PATCH backup] tree-wide: replace serde_json::from_value(a_value.clone()) 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: Tue, 12 Apr 2022 10:39:53 -0000 `&Value` itself implements `Deserializer` and can therefore be passed directly to `T::deserialize` without requiring an intermediate `clone()`. (This also enables optionally borrowing strings if the result has a short enough lifetime) Signed-off-by: Wolfgang Bumiller --- pbs-client/Cargo.toml | 1 + pbs-client/src/tools/key_source.rs | 2 +- pbs-datastore/src/manifest.rs | 4 ++-- proxmox-file-restore/src/main.rs | 4 ++-- src/acme/plugin.rs | 2 +- src/api2/config/acme.rs | 2 +- src/api2/node/network.rs | 4 ++-- src/bin/proxmox_tape/media.rs | 3 ++- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pbs-client/Cargo.toml b/pbs-client/Cargo.toml index d713a3ca..767285d4 100644 --- a/pbs-client/Cargo.toml +++ b/pbs-client/Cargo.toml @@ -22,6 +22,7 @@ percent-encoding = "2.1" pin-project-lite = "0.2" regex = "1.5" rustyline = "7" +serde = "1.0" serde_json = "1.0" tokio = { version = "1.6", features = [ "fs", "signal" ] } tokio-stream = "0.1.0" diff --git a/pbs-client/src/tools/key_source.rs b/pbs-client/src/tools/key_source.rs index f68b1e41..53a9ab96 100644 --- a/pbs-client/src/tools/key_source.rs +++ b/pbs-client/src/tools/key_source.rs @@ -131,7 +131,7 @@ fn do_crypto_parameters(param: &Value, keep_keyfd_open: bool) -> Result = match param.get("crypt-mode") { - Some(mode) => Some(serde_json::from_value(mode.clone())?), + Some(mode) => Some(serde::Deserialize::deserialize(mode)?), None => None, }; diff --git a/pbs-datastore/src/manifest.rs b/pbs-datastore/src/manifest.rs index 42b4bf29..d55ce792 100644 --- a/pbs-datastore/src/manifest.rs +++ b/pbs-datastore/src/manifest.rs @@ -178,7 +178,7 @@ impl BackupManifest { pub fn fingerprint(&self) -> Result, Error> { match &self.unprotected["key-fingerprint"] { Value::Null => Ok(None), - value => Ok(Some(serde_json::from_value(value.clone())?)) + value => Ok(Some(Deserialize::deserialize(value)?)) } } @@ -220,7 +220,7 @@ impl BackupManifest { let fingerprint = &json["unprotected"]["key-fingerprint"]; if fingerprint != &Value::Null { - let fingerprint = serde_json::from_value(fingerprint.clone())?; + let fingerprint = Fingerprint::deserialize(fingerprint)?; let config_fp = Fingerprint::new(crypt_config.fingerprint()); if config_fp != fingerprint { bail!( diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 8876ecd0..b6b0a13e 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -230,7 +230,7 @@ async fn list(snapshot: String, path: String, base64: bool, param: Value) -> Res keyfile, }; let driver: Option = match param.get("driver") { - Some(drv) => Some(serde_json::from_value(drv.clone())?), + Some(drv) => Some(serde::Deserialize::deserialize(drv)?), None => None, }; data_list(driver, details, file, path).await @@ -382,7 +382,7 @@ async fn extract( keyfile, }; let driver: Option = match param.get("driver") { - Some(drv) => Some(serde_json::from_value(drv.clone())?), + Some(drv) => Some(serde::Deserialize::deserialize(drv)?), None => None, }; diff --git a/src/acme/plugin.rs b/src/acme/plugin.rs index a993c8d7..335e6709 100644 --- a/src/acme/plugin.rs +++ b/src/acme/plugin.rs @@ -30,7 +30,7 @@ pub(crate) fn get_acme_plugin( Ok(Some(match ty.as_str() { "dns" => { - let plugin: DnsPlugin = serde_json::from_value(data.clone())?; + let plugin: DnsPlugin = serde::Deserialize::deserialize(data)?; Box::new(plugin) } "standalone" => { diff --git a/src/api2/config/acme.rs b/src/api2/config/acme.rs index 5e3b4b3f..9b586e00 100644 --- a/src/api2/config/acme.rs +++ b/src/api2/config/acme.rs @@ -706,7 +706,7 @@ pub fn update_plugin( bail!("cannot update plugin of type {:?}", ty); } - let mut plugin: DnsPlugin = serde_json::from_value(entry.clone())?; + let mut plugin = DnsPlugin::deserialize(&*entry)?; if let Some(delete) = delete { for delete_prop in delete { diff --git a/src/api2/node/network.rs b/src/api2/node/network.rs index 77821fde..4cb0d7b9 100644 --- a/src/api2/node/network.rs +++ b/src/api2/node/network.rs @@ -1,6 +1,6 @@ use anyhow::{Error, bail}; +use serde::{Deserialize, Serialize}; use serde_json::{Value, to_value}; -use ::serde::{Deserialize, Serialize}; use hex::FromHex; use proxmox_router::{ApiMethod, Router, RpcEnvironment, Permission}; @@ -539,7 +539,7 @@ pub fn update_interface( let interface = config.lookup_mut(&iface)?; if let Some(interface_type) = param.get("type") { - let interface_type: NetworkInterfaceType = serde_json::from_value(interface_type.clone())?; + let interface_type = NetworkInterfaceType::deserialize(interface_type)?; if interface_type != interface.interface_type { bail!("got unexpected interface type ({:?} != {:?})", interface_type, interface.interface_type); } diff --git a/src/bin/proxmox_tape/media.rs b/src/bin/proxmox_tape/media.rs index b73c4b0b..7c0db26d 100644 --- a/src/bin/proxmox_tape/media.rs +++ b/src/bin/proxmox_tape/media.rs @@ -1,4 +1,5 @@ use anyhow::Error; +use serde::Deserialize; use serde_json::Value; use proxmox_router::{cli::*, ApiHandler, RpcEnvironment}; @@ -77,7 +78,7 @@ async fn list_media(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), }; fn render_status(_value: &Value, record: &Value) -> Result { - let record: MediaListEntry = serde_json::from_value(record.clone())?; + let record = MediaListEntry::deserialize(record)?; Ok(match record.status { MediaStatus::Damaged | MediaStatus::Retired => serde_json::to_value(&record.status)? .as_str() -- 2.30.2