From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 proxmox-backup 1/5] types: extract DataStoreListItem
Date: Thu, 5 Nov 2020 12:12:22 +0100 [thread overview]
Message-ID: <20201105111226.4105475-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20201105111226.4105475-1-f.gruenbichler@proxmox.com>
for reuse in remote scan API call
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
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<Value, Error> {
+) -> Result<Vec<DataStoreListItem>, 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<String>,
+}
+
#[api(
properties: {
"backup-type": {
--
2.20.1
next prev parent reply other threads:[~2020-11-05 11:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-05 11:12 [pbs-devel] [PATCH v2 proxmox-backup 0/5] remote scanning Fabian Grünbichler
2020-11-05 11:12 ` Fabian Grünbichler [this message]
2020-11-05 12:20 ` [pbs-devel] applied: [PATCH v2 proxmox-backup 1/5] types: extract DataStoreListItem Thomas Lamprecht
2020-11-05 11:12 ` [pbs-devel] [PATCH v2 proxmox-backup 2/5] api: refactor remote client and add remote scan Fabian Grünbichler
2020-11-05 12:20 ` [pbs-devel] applied: " Thomas Lamprecht
2020-11-05 11:12 ` [pbs-devel] [PATCH v2 proxmox-backup 3/5] www: add remote store selector Fabian Grünbichler
2020-11-05 12:21 ` [pbs-devel] applied: " Thomas Lamprecht
2020-11-05 11:12 ` [pbs-devel] [PATCH v2 proxmox-backup 4/5] remote.cfg: rename userid to 'auth-id' Fabian Grünbichler
2020-11-10 12:30 ` [pbs-devel] applied: " Thomas Lamprecht
2020-11-05 11:12 ` [pbs-devel] [RFC v2 proxmox-backup 5/5] remote.cfg: rename password to secret Fabian Grünbichler
2020-11-10 12:31 ` Thomas Lamprecht
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=20201105111226.4105475-2-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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