]> git.proxmox.com Git - proxmox-backup.git/commitdiff
datastore config: cleanup code (use flatten attribute)
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 23 Jul 2021 09:15:31 +0000 (11:15 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 23 Jul 2021 10:43:33 +0000 (12:43 +0200)
src/api2/config/datastore.rs
src/bin/proxmox_backup_manager/datastore.rs
src/config/datastore.rs

index a55e3bdc475d8c65556c830dcb54fb039f21618c..7edc43d8483e870859168c784821e7d2ec0877e3 100644 (file)
@@ -7,7 +7,6 @@ use ::serde::{Deserialize, Serialize};
 use proxmox::api::{api, Router, RpcEnvironment, Permission};
 use proxmox::api::section_config::SectionConfigData;
 use proxmox::api::schema::parse_property_string;
-
 use pbs_datastore::task::TaskState;
 
 use crate::api2::config::sync::delete_sync_job;
@@ -20,7 +19,7 @@ use crate::api2::admin::{
 use crate::api2::types::*;
 use crate::backup::*;
 use crate::config::cached_user_info::CachedUserInfo;
-use crate::config::datastore::{self, DataStoreConfig, DIR_NAME_SCHEMA};
+use crate::config::datastore::{self, DataStoreConfig};
 use crate::config::acl::{PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY};
 use crate::server::{jobstate, WorkerTask};
 
@@ -31,7 +30,7 @@ use crate::server::{jobstate, WorkerTask};
     returns: {
         description: "List the configured datastores (with config digest).",
         type: Array,
-        items: { type: datastore::DataStoreConfig },
+        items: { type: DataStoreConfig },
     },
     access: {
         permission: &Permission::Anybody,
@@ -80,63 +79,13 @@ pub(crate) fn do_create_datastore(
     Ok(())
 }
 
-// fixme: impl. const fn get_object_schema(datastore::DataStoreConfig::API_SCHEMA),
-// but this need support for match inside const fn
-// see: https://github.com/rust-lang/rust/issues/49146
-
 #[api(
     protected: true,
     input: {
         properties: {
-            name: {
-                schema: DATASTORE_SCHEMA,
-            },
-            path: {
-                schema: DIR_NAME_SCHEMA,
-            },
-            comment: {
-                optional: true,
-                schema: SINGLE_LINE_COMMENT_SCHEMA,
-            },
-            "notify-user": {
-                optional: true,
-                type: Userid,
-            },
-            "notify": {
-                optional: true,
-                schema: DATASTORE_NOTIFY_STRING_SCHEMA,
-            },
-            "gc-schedule": {
-                optional: true,
-                schema: GC_SCHEDULE_SCHEMA,
-            },
-            "prune-schedule": {
-                optional: true,
-                schema: PRUNE_SCHEDULE_SCHEMA,
-            },
-            "keep-last": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_LAST,
-            },
-            "keep-hourly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_HOURLY,
-            },
-            "keep-daily": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_DAILY,
-            },
-            "keep-weekly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_WEEKLY,
-            },
-            "keep-monthly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_MONTHLY,
-            },
-            "keep-yearly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_YEARLY,
+            config: {
+                type: DataStoreConfig,
+                flatten: true,
             },
         },
     },
@@ -146,28 +95,26 @@ pub(crate) fn do_create_datastore(
 )]
 /// Create new datastore config.
 pub fn create_datastore(
-    param: Value,
+    config: DataStoreConfig,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<String, Error> {
 
     let lock = datastore::lock_config()?;
 
-    let datastore: datastore::DataStoreConfig = serde_json::from_value(param)?;
-
-    let (config, _digest) = datastore::config()?;
+    let (section_config, _digest) = datastore::config()?;
 
-    if config.sections.get(&datastore.name).is_some() {
-        bail!("datastore '{}' already exists.", datastore.name);
+    if section_config.sections.get(&config.name).is_some() {
+        bail!("datastore '{}' already exists.", config.name);
     }
 
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
 
     WorkerTask::new_thread(
         "create-datastore",
-        Some(datastore.name.to_string()),
+        Some(config.name.to_string()),
         auth_id,
         false,
-        move |worker| do_create_datastore(lock, config, datastore, Some(&worker)),
+        move |worker| do_create_datastore(lock, section_config, config, Some(&worker)),
     )
 }
 
@@ -179,7 +126,7 @@ pub fn create_datastore(
             },
         },
     },
-    returns: { type: datastore::DataStoreConfig },
+    returns: { type: DataStoreConfig },
     access: {
         permission: &Permission::Privilege(&["datastore", "{name}"], PRIV_DATASTORE_AUDIT, false),
     },
@@ -334,7 +281,7 @@ pub fn update_datastore(
         crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?;
     }
 
-    let mut data: datastore::DataStoreConfig = config.lookup("datastore", &name)?;
+    let mut data: DataStoreConfig = config.lookup("datastore", &name)?;
 
      if let Some(delete) = delete {
         for delete_prop in delete {
index a2436786909cbf032beb5595fbe765f26ec25c1c..07d6111fc05f1c407cfc2299e5de9aeea662a661 100644 (file)
@@ -7,7 +7,7 @@ use pbs_client::{connect_to_localhost, view_task_result};
 
 use proxmox_backup::config;
 use proxmox_backup::api2::{self, types::* };
-use proxmox_backup::config::datastore::DIR_NAME_SCHEMA;
+use proxmox_backup::config::datastore::DataStoreConfig;
 
 #[api(
     input: {
@@ -74,55 +74,9 @@ fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
     protected: true,
     input: {
         properties: {
-            name: {
-                schema: DATASTORE_SCHEMA,
-            },
-            path: {
-                schema: DIR_NAME_SCHEMA,
-            },
-            comment: {
-                optional: true,
-                schema: SINGLE_LINE_COMMENT_SCHEMA,
-            },
-            "notify-user": {
-                optional: true,
-                type: Userid,
-            },
-            "notify": {
-                optional: true,
-                schema: DATASTORE_NOTIFY_STRING_SCHEMA,
-            },
-            "gc-schedule": {
-                optional: true,
-                schema: GC_SCHEDULE_SCHEMA,
-            },
-            "prune-schedule": {
-                optional: true,
-                schema: PRUNE_SCHEDULE_SCHEMA,
-            },
-            "keep-last": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_LAST,
-            },
-            "keep-hourly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_HOURLY,
-            },
-            "keep-daily": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_DAILY,
-            },
-            "keep-weekly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_WEEKLY,
-            },
-            "keep-monthly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_MONTHLY,
-            },
-            "keep-yearly": {
-                optional: true,
-                schema: PRUNE_SCHEMA_KEEP_YEARLY,
+            config: {
+                type: DataStoreConfig,
+                flatten: true,
             },
             "output-format": {
                 schema: OUTPUT_FORMAT,
index 46d28febfa88d66f9e8ac82a4f0a525bf47d797a..70f0384773e41a77cf86bb25f4488a619408b3c9 100644 (file)
@@ -5,7 +5,7 @@ use serde::{Serialize, Deserialize};
 
 use proxmox::api::{
     api,
-    schema::*,
+    schema::{Schema, StringSchema},
     section_config::{
         SectionConfig,
         SectionConfigData,
@@ -76,6 +76,7 @@ pub const DIR_NAME_SCHEMA: Schema = StringSchema::new("Directory name").schema()
             schema: PRUNE_SCHEMA_KEEP_YEARLY,
         },
         "verify-new": {
+            description: "If enabled, all new backups will be verified right after completion.",
             optional: true,
             type: bool,
         },