[pbs-devel] [PATCH proxmox-backup 1/5] api: add ZPOOL_NAME_SCHEMA and regex

Dominik Csapak d.csapak at proxmox.com
Wed Jul 8 14:59:15 CEST 2020


poolnames can containe spaces and some other special characters

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/api2/node/disks/zfs.rs | 5 ++++-
 src/api2/types.rs          | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/api2/node/disks/zfs.rs b/src/api2/node/disks/zfs.rs
index 3184a76..be2a163 100644
--- a/src/api2/node/disks/zfs.rs
+++ b/src/api2/node/disks/zfs.rs
@@ -41,6 +41,9 @@ pub const ZFS_ASHIFT_SCHEMA: Schema = IntegerSchema::new(
     .default(12)
     .schema();
 
+pub const ZPOOL_NAME_SCHEMA: Schema =StringSchema::new("ZFS Pool Name")
+    .format(&ApiStringFormat::Pattern(&ZPOOL_NAME_REGEX))
+    .schema();
 
 #[api(
     default: "On",
@@ -157,7 +160,7 @@ pub fn list_zpools() -> Result<Vec<ZpoolListItem>, Error> {
                 schema: NODE_SCHEMA,
             },
             name: {
-                schema: DATASTORE_SCHEMA,
+                schema: ZPOOL_NAME_SCHEMA,
             },
         },
     },
diff --git a/src/api2/types.rs b/src/api2/types.rs
index 7b90270..0d0fab3 100644
--- a/src/api2/types.rs
+++ b/src/api2/types.rs
@@ -78,6 +78,8 @@ const_regex!{
     pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$");
 
     pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
+
+    pub ZPOOL_NAME_REGEX = r"^[a-zA-Z][a-z0-9A-Z\-_.:]+$";
 }
 
 pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat =
-- 
2.20.1






More information about the pbs-devel mailing list