From 0a00f6e01c65f19bfcf1069c5afc075a3d9ba29e Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 29 Apr 2020 09:09:59 +0200 Subject: [PATCH] src/api2/config/datastore.rs_ add delete property to update method --- src/api2/config/datastore.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 94bd77ef..0bd86c2d 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use anyhow::{bail, Error}; use serde_json::Value; +use ::serde::{Deserialize, Serialize}; use proxmox::api::{api, ApiMethod, Router, RpcEnvironment, Permission}; @@ -119,6 +120,15 @@ pub fn read_datastore(name: String) -> Result { Ok(data) } +#[api()] +#[derive(Serialize, Deserialize)] +#[allow(non_camel_case_types)] +/// Deletable property name +pub enum DeletableProperty { + /// Delete the comment property. + comment, +} + #[api( protected: true, input: { @@ -130,6 +140,14 @@ pub fn read_datastore(name: String) -> Result { optional: true, schema: SINGLE_LINE_COMMENT_SCHEMA, }, + delete: { + description: "List of properties to delete.", + type: Array, + optional: true, + items: { + type: DeletableProperty, + } + }, digest: { optional: true, schema: PROXMOX_CONFIG_DIGEST_SCHEMA, @@ -144,6 +162,7 @@ pub fn read_datastore(name: String) -> Result { pub fn update_datastore( name: String, comment: Option, + delete: Option>, digest: Option, ) -> Result<(), Error> { @@ -159,6 +178,14 @@ pub fn update_datastore( let mut data: datastore::DataStoreConfig = config.lookup("datastore", &name)?; + if let Some(delete) = delete { + for delete_prop in delete { + match delete_prop { + DeletableProperty::comment => { data.comment = None; }, + } + } + } + if let Some(comment) = comment { let comment = comment.trim().to_string(); if comment.is_empty() {