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 4FA0865EA4 for ; Thu, 5 Nov 2020 12:13:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 40F7217353 for ; Thu, 5 Nov 2020 12:12:34 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 B337017348 for ; Thu, 5 Nov 2020 12:12:33 +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 7D8D645EB2 for ; Thu, 5 Nov 2020 12:12:33 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Thu, 5 Nov 2020 12:12:22 +0100 Message-Id: <20201105111226.4105475-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105111226.4105475-1-f.gruenbichler@proxmox.com> References: <20201105111226.4105475-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [datastore.rs, mod.rs] Subject: [pbs-devel] [PATCH v2 proxmox-backup 1/5] types: extract DataStoreListItem 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, 05 Nov 2020 11:13:04 -0000 for reuse in remote scan API call Signed-off-by: Fabian Grünbichler --- src/api2/admin/datastore.rs | 23 ++++++++--------------- src/api2/types/mod.rs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index a5d3e979..b051e8dd 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -902,15 +902,7 @@ pub fn garbage_collection_status( type: Array, items: { description: "Datastore name and description.", - properties: { - store: { - schema: DATASTORE_SCHEMA, - }, - comment: { - optional: true, - schema: SINGLE_LINE_COMMENT_SCHEMA, - }, - }, + type: DataStoreListItem, }, }, access: { @@ -922,7 +914,7 @@ fn get_datastore_list( _param: Value, _info: &ApiMethod, rpcenv: &mut dyn RpcEnvironment, -) -> Result { +) -> Result, Error> { let (config, _digest) = datastore::config()?; @@ -935,11 +927,12 @@ fn get_datastore_list( let user_privs = user_info.lookup_privs(&auth_id, &["datastore", &store]); let allowed = (user_privs & (PRIV_DATASTORE_AUDIT| PRIV_DATASTORE_BACKUP)) != 0; if allowed { - let mut entry = json!({ "store": store }); - if let Some(comment) = data["comment"].as_str() { - entry["comment"] = comment.into(); - } - list.push(entry); + list.push( + DataStoreListItem { + store: store.clone(), + comment: data["comment"].as_str().map(String::from), + } + ); } } diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 7ee89f57..31fd89d2 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -370,6 +370,25 @@ pub const BLOCKDEVICE_NAME_SCHEMA: Schema = StringSchema::new("Block device name // Complex type definitions +#[api( + properties: { + store: { + schema: DATASTORE_SCHEMA, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + }, +)] +#[derive(Serialize, Deserialize)] +#[serde(rename_all="kebab-case")] +/// Basic information about a datastore. +pub struct DataStoreListItem { + pub store: String, + pub comment: Option, +} + #[api( properties: { "backup-type": { -- 2.20.1