From 66c49c21c33b6865e42936cdfe1d1f6880a93627 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 11 Dec 2019 13:45:23 +0100 Subject: [PATCH] src/api2/types.rs: factor out DATASTORE_SCHEMA --- src/api2/admin/datastore.rs | 22 ++++++++++------------ src/api2/backup.rs | 2 +- src/api2/config/datastore.rs | 5 +++-- src/api2/node/tasks.rs | 2 +- src/api2/reader.rs | 2 +- src/api2/types.rs | 4 ++++ 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 24c69f00..17943094 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -200,7 +200,7 @@ const API_METHOD_STATUS: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Get datastore status.", &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ]), ) ); @@ -299,7 +299,7 @@ const API_METHOD_PRUNE: ApiMethod = ApiMethod::new( .schema() ), ],[ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ]) ) ); @@ -388,7 +388,7 @@ pub const API_METHOD_START_GARBAGE_COLLECTION: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Start garbage collection.", &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ]) ) ); @@ -423,7 +423,7 @@ pub const API_METHOD_GARBAGE_COLLECTION_STATUS: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Garbage collection status.", &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ]) ) ); @@ -463,7 +463,7 @@ pub const API_METHOD_DOWNLOAD_FILE: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Download single raw file from backup snapshot.", &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA), @@ -526,7 +526,7 @@ pub const API_METHOD_UPLOAD_BACKUP_LOG: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Download single raw file from backup snapshot.", &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA), @@ -585,8 +585,6 @@ fn upload_backup_log( }.boxed() } -const STORE_SCHEMA: Schema = StringSchema::new("Datastore name.").schema(); - #[sortable] const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ ( @@ -603,7 +601,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ &ObjectSchema::new( "List snapshot files.", &sorted!([ - ("store", false, &STORE_SCHEMA), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA), @@ -626,7 +624,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ &ApiHandler::Sync(&list_groups), &ObjectSchema::new( "List backup groups.", - &sorted!([ ("store", false, &STORE_SCHEMA) ]), + &sorted!([ ("store", false, &DATASTORE_SCHEMA) ]), ) ) ) @@ -645,7 +643,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ &ObjectSchema::new( "List backup groups.", &sorted!([ - ("store", false, &STORE_SCHEMA), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", true, &BACKUP_TYPE_SCHEMA), ("backup-id", true, &BACKUP_ID_SCHEMA), ]), @@ -658,7 +656,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ &ObjectSchema::new( "Delete backup snapshot.", &sorted!([ - ("store", false, &STORE_SCHEMA), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA), diff --git a/src/api2/backup.rs b/src/api2/backup.rs index 74bd5fb8..9329e067 100644 --- a/src/api2/backup.rs +++ b/src/api2/backup.rs @@ -32,7 +32,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new( &ObjectSchema::new( concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_PROTOCOL_ID_V1!(), "')."), &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &BACKUP_TYPE_SCHEMA), ("backup-id", false, &BACKUP_ID_SCHEMA), ("backup-time", false, &BACKUP_TIME_SCHEMA), diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index e58212e7..92d1b17e 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -6,6 +6,7 @@ use serde_json::{json, Value}; use proxmox::api::{ApiHandler, ApiMethod, Router, RpcEnvironment}; use proxmox::api::schema::*; +use crate::api2::types::*; use crate::backup::*; use crate::config::datastore; @@ -30,7 +31,7 @@ pub const POST: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Create new datastore.", &[ - ("name", false, &StringSchema::new("Datastore name.").schema()), + ("name", false, &DATASTORE_SCHEMA), ("path", false, &StringSchema::new("Directory path (must exist).").schema()), ], ) @@ -71,7 +72,7 @@ pub const DELETE: ApiMethod = ApiMethod::new( &ObjectSchema::new( "Remove a datastore configuration.", &[ - ("name", false, &StringSchema::new("Datastore name.").schema()), + ("name", false, &DATASTORE_SCHEMA), ], ) ); diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs index c26c7af2..a764abf1 100644 --- a/src/api2/node/tasks.rs +++ b/src/api2/node/tasks.rs @@ -280,7 +280,7 @@ pub const ROUTER: Router = Router::new() .default(50) .schema() ), - ("store", true, &StringSchema::new("Only lists tasks for datastore name.").schema()), + ("store", true, &DATASTORE_SCHEMA), ("running", true, &BooleanSchema::new("Only list running tasks.").schema()), ("errors", true, &BooleanSchema::new("Only list erroneous tasks.").schema()), ("userfilter", true, &StringSchema::new("Only list tasks from this user.").schema()), diff --git a/src/api2/reader.rs b/src/api2/reader.rs index e146f2c6..9f425b5c 100644 --- a/src/api2/reader.rs +++ b/src/api2/reader.rs @@ -28,7 +28,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new( &ObjectSchema::new( concat!("Upgraded to backup protocol ('", PROXMOX_BACKUP_READER_PROTOCOL_ID_V1!(), "')."), &sorted!([ - ("store", false, &StringSchema::new("Datastore name.").schema()), + ("store", false, &DATASTORE_SCHEMA), ("backup-type", false, &StringSchema::new("Backup type.") .format(&ApiStringFormat::Enum(&["vm", "ct", "host"])) .schema() diff --git a/src/api2/types.rs b/src/api2/types.rs index ac4c6979..d1d52740 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -101,3 +101,7 @@ pub const BACKUP_TIME_SCHEMA: Schema = pub const UPID_SCHEMA: Schema = StringSchema::new("Unique Process/Task ID.") .max_length(256) .schema(); + +pub const DATASTORE_SCHEMA: Schema = StringSchema::new("Datastore name.") + .max_length(32) + .schema();